[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-07 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

The test seems to fail on certain linux distros (fedora and archlinux) ... 
Since it's not a breaking change, I sent a patch to skip it on linux, until I 
can reproduce it on those platform and fix the issue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-06 Thread Jan Kratochvil via Phabricator via lldb-commits
jankratochvil added a comment.

Even with the latest variant (commit 
`7ebe9cc4fc2d97ec0ed2a6038be25b2a7ed1aac2`) I am getting on Fedora 30 x86_64:

  
/home/jkratoch/redhat/llvm-monorepo/lldb/test/Shell/Recognizer/assert.test:5:10:
 error: CHECK: expected string not found in input
  # CHECK: thread #{{.*}}stop reason = hit program assert
   ^
  :1:1: note: scanning from here
  (lldb) command source -s 0 
'/home/jkratoch/redhat/llvm-monorepo-clangassert/tools/lldb/test/Shell/lit-lldb-init'
  ^
  :15:34: note: possible intended match here
  * thread #1, name = 'assert.test.tmp', stop reason = signal SIGABRT
   ^

The output is:

  (lldb) command source -s 0 
'/home/jkratoch/redhat/llvm-monorepo/lldb/test/Shell/Recognizer/assert.test'
  Executing commands in 
'/home/jkratoch/redhat/llvm-monorepo/lldb/test/Shell/Recognizer/assert.test'.
  (lldb) run
  assert.test.tmp.out: 
/home/jkratoch/redhat/llvm-monorepo/lldb/test/Shell/Recognizer/Inputs/assert.c:7:
 int main(): Assertion `a == 42' failed.
  Process 29077 stopped
  * thread #1, name = 'assert.test.tmp', stop reason = signal SIGABRT
  frame #0: 0x77ddee35 libc.so.6`raise + 325
  libc.so.6`raise:
  ->  0x77ddee35 <+325>: movq   0x108(%rsp), %rax
  0x77ddee3d <+333>: xorq   %fs:0x28, %rax
  0x77ddee46 <+342>: jne0x77ddee6c; <+380>
  0x77ddee48 <+344>: movl   %r8d, %eax
  
  Process 29077 launched: 
'/home/jkratoch/redhat/llvm-monorepo-clangassert/tools/lldb/test/Recognizer/Output/assert.test.tmp.out'
 (x86_64)
  (lldb) frame info
  frame #0: 0x77ddee35 libc.so.6`raise + 325
  (lldb) frame recognizer info 0
  frame 0 is recognized by Assert StackFrame Recognizer
  (lldb) set set thread-format "{${thread.stop-reason-raw}}\n"
  (lldb) thread info
  signal SIGABRT
  
  (lldb) q

Visible also on (silent) Fedora buildbot 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7ebe9cc4fc2d: [lldb/Target] Add Assert StackFrame Recognizer 
(authored by mib).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  lldb/include/lldb/Target/AssertFrameRecognizer.h
  lldb/include/lldb/Target/StackFrameRecognizer.h
  lldb/include/lldb/Target/Thread.h
  
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py
  lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  lldb/source/API/SBThread.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Target/AssertFrameRecognizer.cpp
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Process.cpp
  lldb/source/Target/StackFrameRecognizer.cpp
  lldb/source/Target/Thread.cpp
  lldb/test/Shell/Recognizer/Inputs/assert.c
  lldb/test/Shell/Recognizer/assert.test

Index: lldb/test/Shell/Recognizer/assert.test
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/assert.test
@@ -0,0 +1,13 @@
+# UNSUPPORTED: system-windows
+# RUN: %clang_host -g -O0 %S/Inputs/assert.c -o %t.out
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+run
+# CHECK: thread #{{.*}}stop reason = hit program assert
+frame info
+# CHECK: frame #{{.*}}`main at assert.c
+frame recognizer info 0
+# CHECK: frame 0 is recognized by Assert StackFrame Recognizer
+set set thread-format "{${thread.stop-reason-raw}}\n"
+thread info
+# CHECK: signal SIGABRT
+q
Index: lldb/test/Shell/Recognizer/Inputs/assert.c
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/Inputs/assert.c
@@ -0,0 +1,9 @@
+#include 
+
+int main() {
+  int a = 42;
+  assert(a == 42);
+  a--;
+  assert(a == 42);
+  return 0;
+}
Index: lldb/source/Target/Thread.cpp
===
--- lldb/source/Target/Thread.cpp
+++ lldb/source/Target/Thread.cpp
@@ -573,9 +573,64 @@
   m_state = state;
 }
 
+std::string Thread::GetStopDescription() {
+  StackFrameSP frame_sp = GetStackFrameAtIndex(0);
+
+  if (!frame_sp)
+return GetStopDescriptionRaw();
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp)
+return GetStopDescriptionRaw();
+
+  std::string recognized_stop_description =
+  recognized_frame_sp->GetStopDescription();
+
+  if (!recognized_stop_description.empty())
+return recognized_stop_description;
+
+  return GetStopDescriptionRaw();
+}
+
+std::string Thread::GetStopDescriptionRaw() {
+  StopInfoSP stop_info_sp = GetStopInfo();
+  std::string raw_stop_description;
+  if (stop_info_sp && stop_info_sp->IsValid())
+raw_stop_description = stop_info_sp->GetDescription();
+  return raw_stop_description;
+}
+
+void Thread::SelectMostRelevantFrame() {
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  auto frames_list_sp = GetStackFrameList();
+
+  // Only the top frame should be recognized.
+  auto frame_sp = frames_list_sp->GetFrameAtIndex(0);
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp) {
+LLDB_LOG(log, "Frame #0 not recognized");
+return;
+  }
+
+  if (StackFrameSP most_relevant_frame_sp =
+  recognized_frame_sp->GetMostRelevantFrame()) {
+LLDB_LOG(log, "Found most relevant frame at index {0}",
+ most_relevant_frame_sp->GetFrameIndex());
+SetSelectedFrame(most_relevant_frame_sp.get());
+  } else {
+LLDB_LOG(log, "No relevant frame!");
+  }
+}
+
 void Thread::WillStop() {
   ThreadPlan *current_plan = GetCurrentPlan();
 
+  SelectMostRelevantFrame();
+
   // FIXME: I may decide to disallow threads with no plans.  In which
   // case this should go to an assert.
 
Index: lldb/source/Target/StackFrameRecognizer.cpp
===
--- lldb/source/Target/StackFrameRecognizer.cpp
+++ lldb/source/Target/StackFrameRecognizer.cpp
@@ -92,8 +92,8 @@
   }
 
   StackFrameRecognizerSP GetRecognizerForFrame(StackFrameSP frame) {
-const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+const SymbolContext  = frame->GetSymbolContext(
+eSymbolContextModule | eSymbolContextFunction | eSymbolContextSymbol);
 ConstString function_name = symctx.GetFunctionName();
 ModuleSP module_sp = symctx.module_sp;
 if (!module_sp) return StackFrameRecognizerSP();
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -38,6 +38,7 @@
 #include "lldb/Symbol/Function.h"
 #include 

[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-06 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 242926.
mib added a comment.
This revision is now accepted and ready to land.

Fixing the memory management bug should hopefully solve the Linux and Windows 
Issues.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  lldb/include/lldb/Target/AssertFrameRecognizer.h
  lldb/include/lldb/Target/StackFrameRecognizer.h
  lldb/include/lldb/Target/Thread.h
  
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py
  lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  lldb/source/API/SBThread.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Target/AssertFrameRecognizer.cpp
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Process.cpp
  lldb/source/Target/StackFrameRecognizer.cpp
  lldb/source/Target/Thread.cpp
  lldb/test/Shell/Recognizer/Inputs/assert.c
  lldb/test/Shell/Recognizer/assert.test

Index: lldb/test/Shell/Recognizer/assert.test
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/assert.test
@@ -0,0 +1,13 @@
+# UNSUPPORTED: system-windows
+# RUN: %clang_host -g -O0 %S/Inputs/assert.c -o %t.out
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+run
+# CHECK: thread #{{.*}}stop reason = hit program assert
+frame info
+# CHECK: frame #{{.*}}`main at assert.c
+frame recognizer info 0
+# CHECK: frame 0 is recognized by Assert StackFrame Recognizer
+set set thread-format "{${thread.stop-reason-raw}}\n"
+thread info
+# CHECK: signal SIGABRT
+q
Index: lldb/test/Shell/Recognizer/Inputs/assert.c
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/Inputs/assert.c
@@ -0,0 +1,9 @@
+#include 
+
+int main() {
+  int a = 42;
+  assert(a == 42);
+  a--;
+  assert(a == 42);
+  return 0;
+}
Index: lldb/source/Target/Thread.cpp
===
--- lldb/source/Target/Thread.cpp
+++ lldb/source/Target/Thread.cpp
@@ -573,9 +573,64 @@
   m_state = state;
 }
 
+std::string Thread::GetStopDescription() {
+  StackFrameSP frame_sp = GetStackFrameAtIndex(0);
+
+  if (!frame_sp)
+return GetStopDescriptionRaw();
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp)
+return GetStopDescriptionRaw();
+
+  std::string recognized_stop_description =
+  recognized_frame_sp->GetStopDescription();
+
+  if (!recognized_stop_description.empty())
+return recognized_stop_description;
+
+  return GetStopDescriptionRaw();
+}
+
+std::string Thread::GetStopDescriptionRaw() {
+  StopInfoSP stop_info_sp = GetStopInfo();
+  std::string raw_stop_description;
+  if (stop_info_sp && stop_info_sp->IsValid())
+raw_stop_description = stop_info_sp->GetDescription();
+  return raw_stop_description;
+}
+
+void Thread::SelectMostRelevantFrame() {
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  auto frames_list_sp = GetStackFrameList();
+
+  // Only the top frame should be recognized.
+  auto frame_sp = frames_list_sp->GetFrameAtIndex(0);
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp) {
+LLDB_LOG(log, "Frame #0 not recognized");
+return;
+  }
+
+  if (StackFrameSP most_relevant_frame_sp =
+  recognized_frame_sp->GetMostRelevantFrame()) {
+LLDB_LOG(log, "Found most relevant frame at index {0}",
+ most_relevant_frame_sp->GetFrameIndex());
+SetSelectedFrame(most_relevant_frame_sp.get());
+  } else {
+LLDB_LOG(log, "No relevant frame!");
+  }
+}
+
 void Thread::WillStop() {
   ThreadPlan *current_plan = GetCurrentPlan();
 
+  SelectMostRelevantFrame();
+
   // FIXME: I may decide to disallow threads with no plans.  In which
   // case this should go to an assert.
 
Index: lldb/source/Target/StackFrameRecognizer.cpp
===
--- lldb/source/Target/StackFrameRecognizer.cpp
+++ lldb/source/Target/StackFrameRecognizer.cpp
@@ -92,8 +92,8 @@
   }
 
   StackFrameRecognizerSP GetRecognizerForFrame(StackFrameSP frame) {
-const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+const SymbolContext  = frame->GetSymbolContext(
+eSymbolContextModule | eSymbolContextFunction | eSymbolContextSymbol);
 ConstString function_name = symctx.GetFunctionName();
 ModuleSP module_sp = symctx.module_sp;
 if (!module_sp) return StackFrameRecognizerSP();
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -38,6 +38,7 @@
 #include 

[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-05 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib reopened this revision.
mib added a comment.
This revision is now accepted and ready to land.

There are still some bugs on Windows and Linux that need to investigated ...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-05 Thread Frederic Riss via Phabricator via lldb-commits
friss added inline comments.



Comment at: lldb/source/API/SBThread.cpp:328-329
   if (stop_info_sp) {
-const char *stop_desc = stop_info_sp->GetDescription();
+const char *stop_desc =
+exe_ctx.GetThreadPtr()->GetStopDescription().data();
 if (stop_desc) {

This is wrong. `GetStopDescription()` returns a temporary `std::string`. 
`stop_desc` will be a dangling pointer on the next line. Just make `stop_desc` 
a `std::string` and call `.data()` below. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-05 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

It looks like there is still some memory corruption going on:

  lldb) target create --core 
"../llvm-project/lldb/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/fizzbuzz_no_heap.dmp"
  (lldb) bt
  * thread #1, stop reason = Exception 0xc005 encountered at address 
0x164d14
* frame #0: 0x00164d14 fizzbuzz.exe
  frame #1: 0x00167c79 fizzbuzz.exe
 ...
  (lldb) script lldb.thread.GetStopDescription(256)
  '\xf0\xfca\x02'




Comment at: lldb/source/Target/AssertFrameRecognizer.cpp:63-65
+symbol_name = "__GI_raise";
+if (!ModuleHasDebugInfo(target, module_spec, symbol_name))
+  symbol_name = "raise";

This part looks pretty kludgy. Maybe the function should just return a list of 
symbols (and shared libraries) and have this thing be handled at a higher level.

This is going to be needed in order to support other C library implementations 
(e.g. musl) on linux, and it's not inconceivable that the internal glibc symbol 
name will change in the future too...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-05 Thread Max Kudryavtsev via Phabricator via lldb-commits
max-kudr added a comment.

This broke LLDB tests on Windows Build Bot 
http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/13415

Can you please fix it or revert it? Thank you!

  Failing Tests (4):
  lldb-api :: 
commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
  lldb-api :: functionalities/postmortem/minidump-new/TestMiniDumpNew.py
  lldb-api :: python_api/thread/TestThreadAPI.py
  lldb-shell :: Driver/TestConvenienceVariables.test
  
Expected Passes: 1381
Expected Failures  : 10
Unsupported Tests  : 541
Unexpected Failures: 4


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-05 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/source/Target/StackFrameRecognizer.cpp:95
 const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+frame->GetSymbolContext(eSymbolContextEverything);
 ConstString function_name = symctx.GetFunctionName();

friss wrote:
> What's the reason of this change?
In line 101, lldb tries to get the symbol from the symbol context. If the 
symbol was not populated in the SymbolContext before calling 
`GetRecognizerForFrame` then it's null and the function returns a 
`StackFrameRecognizerSP`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-05 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 242634.
mib marked 5 inline comments as done.
mib added a comment.

Fixed the corrupted stop reason description.
Fixed linux support for public symbols.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  lldb/include/lldb/Target/AssertFrameRecognizer.h
  lldb/include/lldb/Target/StackFrameRecognizer.h
  lldb/include/lldb/Target/Thread.h
  
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py
  lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  lldb/source/API/SBThread.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Target/AssertFrameRecognizer.cpp
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Process.cpp
  lldb/source/Target/StackFrameRecognizer.cpp
  lldb/source/Target/Thread.cpp
  lldb/test/Shell/Recognizer/Inputs/assert.c
  lldb/test/Shell/Recognizer/assert.test

Index: lldb/test/Shell/Recognizer/assert.test
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/assert.test
@@ -0,0 +1,13 @@
+# UNSUPPORTED: system-windows
+# RUN: %clang_host -g -O0 %S/Inputs/assert.c -o %t.out
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+run
+# CHECK: thread #{{.*}}stop reason = hit program assert
+frame info
+# CHECK: frame #{{.*}}`main at assert.c
+frame recognizer info 0
+# CHECK: frame 0 is recognized by Assert StackFrame Recognizer
+set set thread-format "{${thread.stop-reason-raw}}\n"
+thread info
+# CHECK: signal SIGABRT
+q
Index: lldb/test/Shell/Recognizer/Inputs/assert.c
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/Inputs/assert.c
@@ -0,0 +1,9 @@
+#include 
+
+int main() {
+  int a = 42;
+  assert(a == 42);
+  a--;
+  assert(a == 42);
+  return 0;
+}
Index: lldb/source/Target/Thread.cpp
===
--- lldb/source/Target/Thread.cpp
+++ lldb/source/Target/Thread.cpp
@@ -573,9 +573,64 @@
   m_state = state;
 }
 
+std::string Thread::GetStopDescription() {
+  StackFrameSP frame_sp = GetStackFrameAtIndex(0);
+
+  if (!frame_sp)
+return GetStopDescriptionRaw();
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp)
+return GetStopDescriptionRaw();
+
+  std::string recognized_stop_description =
+  recognized_frame_sp->GetStopDescription();
+
+  if (!recognized_stop_description.empty())
+return recognized_stop_description;
+
+  return GetStopDescriptionRaw();
+}
+
+std::string Thread::GetStopDescriptionRaw() {
+  StopInfoSP stop_info_sp = GetStopInfo();
+  std::string raw_stop_description;
+  if (stop_info_sp && stop_info_sp->IsValid())
+raw_stop_description = stop_info_sp->GetDescription();
+  return raw_stop_description;
+}
+
+void Thread::SelectMostRelevantFrame() {
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  auto frames_list_sp = GetStackFrameList();
+
+  // Only the top frame should be recognized.
+  auto frame_sp = frames_list_sp->GetFrameAtIndex(0);
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp) {
+LLDB_LOG(log, "Frame #0 not recognized");
+return;
+  }
+
+  if (StackFrameSP most_relevant_frame_sp =
+  recognized_frame_sp->GetMostRelevantFrame()) {
+LLDB_LOG(log, "Found most relevant frame at index {0}",
+ most_relevant_frame_sp->GetFrameIndex());
+SetSelectedFrame(most_relevant_frame_sp.get());
+  } else {
+LLDB_LOG(log, "No relevant frame!");
+  }
+}
+
 void Thread::WillStop() {
   ThreadPlan *current_plan = GetCurrentPlan();
 
+  SelectMostRelevantFrame();
+
   // FIXME: I may decide to disallow threads with no plans.  In which
   // case this should go to an assert.
 
Index: lldb/source/Target/StackFrameRecognizer.cpp
===
--- lldb/source/Target/StackFrameRecognizer.cpp
+++ lldb/source/Target/StackFrameRecognizer.cpp
@@ -92,8 +92,8 @@
   }
 
   StackFrameRecognizerSP GetRecognizerForFrame(StackFrameSP frame) {
-const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+const SymbolContext  = frame->GetSymbolContext(
+eSymbolContextModule | eSymbolContextFunction | eSymbolContextSymbol);
 ConstString function_name = symctx.GetFunctionName();
 ModuleSP module_sp = symctx.module_sp;
 if (!module_sp) return StackFrameRecognizerSP();
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -38,6 +38,7 @@
 #include 

[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-02-05 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2b7f32892b76: [lldb/Target] Add Assert StackFrame Recognizer 
(authored by mib).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  lldb/include/lldb/Target/AssertFrameRecognizer.h
  lldb/include/lldb/Target/StackFrameRecognizer.h
  lldb/include/lldb/Target/Thread.h
  
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py
  lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  lldb/source/API/SBThread.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Target/AssertFrameRecognizer.cpp
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Process.cpp
  lldb/source/Target/StackFrameRecognizer.cpp
  lldb/source/Target/Thread.cpp
  lldb/test/Shell/Recognizer/Inputs/assert.c
  lldb/test/Shell/Recognizer/assert.test

Index: lldb/test/Shell/Recognizer/assert.test
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/assert.test
@@ -0,0 +1,13 @@
+# UNSUPPORTED: system-windows
+# RUN: %clang_host -g -O0 %S/Inputs/assert.c -o %t.out
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+run
+# CHECK: thread #{{.*}}stop reason = hit program assert
+frame info
+# CHECK: frame #{{.*}}`main at assert.c
+frame recognizer info 0
+# CHECK: frame 0 is recognized by Assert StackFrame Recognizer
+set set thread-format "{${thread.stop-reason-raw}}\n"
+thread info
+# CHECK: signal SIGABRT
+q
Index: lldb/test/Shell/Recognizer/Inputs/assert.c
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/Inputs/assert.c
@@ -0,0 +1,9 @@
+#include 
+
+int main() {
+  int a = 42;
+  assert(a == 42);
+  a--;
+  assert(a == 42);
+  return 0;
+}
Index: lldb/source/Target/Thread.cpp
===
--- lldb/source/Target/Thread.cpp
+++ lldb/source/Target/Thread.cpp
@@ -573,9 +573,64 @@
   m_state = state;
 }
 
+std::string Thread::GetStopDescription() {
+  StackFrameSP frame_sp = GetStackFrameAtIndex(0);
+
+  if (!frame_sp)
+return GetStopDescriptionRaw();
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp)
+return GetStopDescriptionRaw();
+
+  std::string recognized_stop_description =
+  recognized_frame_sp->GetStopDescription();
+
+  if (!recognized_stop_description.empty())
+return recognized_stop_description;
+
+  return GetStopDescriptionRaw();
+}
+
+std::string Thread::GetStopDescriptionRaw() {
+  StopInfoSP stop_info_sp = GetStopInfo();
+  std::string raw_stop_description;
+  if (stop_info_sp && stop_info_sp->IsValid())
+raw_stop_description = stop_info_sp->GetDescription();
+  return raw_stop_description;
+}
+
+void Thread::SelectMostRelevantFrame() {
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  auto frames_list_sp = GetStackFrameList();
+
+  // Only the top frame should be recognized.
+  auto frame_sp = frames_list_sp->GetFrameAtIndex(0);
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp) {
+LLDB_LOG(log, "Frame #0 not recognized");
+return;
+  }
+
+  if (StackFrameSP most_relevant_frame_sp =
+  recognized_frame_sp->GetMostRelevantFrame()) {
+LLDB_LOG(log, "Found most relevant frame at index {0}",
+ most_relevant_frame_sp->GetFrameIndex());
+SetSelectedFrame(most_relevant_frame_sp.get());
+  } else {
+LLDB_LOG(log, "No relevant frame!");
+  }
+}
+
 void Thread::WillStop() {
   ThreadPlan *current_plan = GetCurrentPlan();
 
+  SelectMostRelevantFrame();
+
   // FIXME: I may decide to disallow threads with no plans.  In which
   // case this should go to an assert.
 
Index: lldb/source/Target/StackFrameRecognizer.cpp
===
--- lldb/source/Target/StackFrameRecognizer.cpp
+++ lldb/source/Target/StackFrameRecognizer.cpp
@@ -92,8 +92,8 @@
   }
 
   StackFrameRecognizerSP GetRecognizerForFrame(StackFrameSP frame) {
-const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+const SymbolContext  = frame->GetSymbolContext(
+eSymbolContextModule | eSymbolContextFunction | eSymbolContextSymbol);
 ConstString function_name = symctx.GetFunctionName();
 ModuleSP module_sp = symctx.module_sp;
 if (!module_sp) return StackFrameRecognizerSP();
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -38,6 +38,7 @@
 #include "lldb/Symbol/Function.h"
 #include 

[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-01-29 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Since the failure reason was not very obvious from the bot message, I took a 
quick look, and to save you the trouble of reproducing this, here's what I 
found:

The reason the new test failed was because the symbols you are searching for 
(`__GI_raise`, `__GI___assert_fail`) are private libc symbols which are only 
available if you happen to have debug info for the system libc installed. If 
you don't, these will show up as `raise` and `__assert_fail`, respectively.

Also the TestExitDuringStep was failing because of some apparent memory 
corruption in the stop reason  (I am getting output like `* thread #2, name = 
'a.out', stop reason = P�4��`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-01-28 Thread Frederic Riss via Phabricator via lldb-commits
friss added a comment.

This generally looks good. I'm still not fond of registering this in the Target 
itself. But I don't have a immediately better idea as we don't have a C 
language runtime.

A couple more comments/questions that can be addressed as followups:




Comment at: lldb/include/lldb/Target/StackFrameRecognizer.h:38
+  virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; };
+  virtual llvm::StringRef GetStopDescription() { return ""; }
   virtual ~RecognizedStackFrame(){};

The fact that this returns a StringRef, means it must return a pointer to 
permanent string storage. In this case, you're returning a constant string, and 
it's fine, but it means that if you wanted to construct a return value (for 
example out of data you extract from the inferior), you need to store the 
string backing the StringRef somewhere.  The concrete `RecognizedStackFrame` 
instance seems like a good fit, but I have no clue about their lifetime 
guarantees compared to the lifetime of the StringRef returned here. Maybe we 
should make this a `std::string`?



Comment at: 
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py:113
+
+stop_reason = 'stop reason = ' + thread.GetStopDescription(256)
 

Here, you're now just checking self consistency, I son't think that's valuable. 
This should check for the actual text of the assert recognizer (and potentially 
something else on the systems where the recognizer is not supported).



Comment at: 
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py:191
+
+self.assertTrue(thread.GetFrameAtIndex(0) == frame, "Frame #0 
selected")
+

as we just did `self.runCmd` above anyway, I'd replace all of this by 
`self.runCmd('frame select 0')`. Or at least just write it as a single line, no 
need to check for every intermediate result. Such verbosity really distracts 
from what the test is trying to verify. 



Comment at: lldb/source/Target/AssertFrameRecognizer.cpp:110-112
+AssertRecognizedStackFrame::AssertRecognizedStackFrame(
+StackFrameSP most_relevant_frame_sp)
+: m_most_relevant_frame(most_relevant_frame_sp) {}

Can you move this with the other AssertRecognizedStackFrame methods?



Comment at: lldb/source/Target/StackFrameRecognizer.cpp:95
 const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+frame->GetSymbolContext(eSymbolContextEverything);
 ConstString function_name = symctx.GetFunctionName();

What's the reason of this change?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG03a6b858fde5: [lldb/Target] Add Assert StackFrame Recognizer 
(authored by mib).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  lldb/include/lldb/Target/AssertFrameRecognizer.h
  lldb/include/lldb/Target/StackFrameRecognizer.h
  lldb/include/lldb/Target/Thread.h
  
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py
  lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  lldb/source/API/SBThread.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Target/AssertFrameRecognizer.cpp
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Process.cpp
  lldb/source/Target/StackFrameRecognizer.cpp
  lldb/source/Target/Thread.cpp
  lldb/test/Shell/Recognizer/Inputs/assert.c
  lldb/test/Shell/Recognizer/assert.test

Index: lldb/test/Shell/Recognizer/assert.test
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/assert.test
@@ -0,0 +1,13 @@
+# UNSUPPORTED: system-windows
+# RUN: %clang_host -g -O0 %S/Inputs/assert.c -o %t.out
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+run
+# CHECK: thread #{{.*}}stop reason = hit program assert
+frame info
+# CHECK: frame #{{.*}}`main at assert.c
+frame recognizer info 0
+# CHECK: frame 0 is recognized by Assert StackFrame Recognizer
+set set thread-format "{${thread.stop-reason-raw}}\n"
+thread info
+# CHECK: signal SIGABRT
+q
Index: lldb/test/Shell/Recognizer/Inputs/assert.c
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/Inputs/assert.c
@@ -0,0 +1,9 @@
+#include 
+
+int main() {
+  int a = 42;
+  assert(a == 42);
+  a--;
+  assert(a == 42);
+  return 0;
+}
Index: lldb/source/Target/Thread.cpp
===
--- lldb/source/Target/Thread.cpp
+++ lldb/source/Target/Thread.cpp
@@ -573,9 +573,64 @@
   m_state = state;
 }
 
+llvm::StringRef Thread::GetStopDescription() {
+  StackFrameSP frame_sp = GetStackFrameAtIndex(0);
+
+  if (!frame_sp)
+return GetStopDescriptionRaw();
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp)
+return GetStopDescriptionRaw();
+
+  llvm::StringRef recognized_stop_description =
+  recognized_frame_sp->GetStopDescription();
+
+  if (!recognized_stop_description.empty())
+return recognized_stop_description;
+
+  return GetStopDescriptionRaw();
+}
+
+llvm::StringRef Thread::GetStopDescriptionRaw() {
+  StopInfoSP stop_info_sp = GetStopInfo();
+  llvm::StringRef raw_stop_description;
+  if (stop_info_sp && stop_info_sp->IsValid())
+raw_stop_description = stop_info_sp->GetDescription();
+  return raw_stop_description;
+}
+
+void Thread::SelectMostRelevantFrame() {
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  auto frames_list_sp = GetStackFrameList();
+
+  // Only the top frame should be recognized.
+  auto frame_sp = frames_list_sp->GetFrameAtIndex(0);
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp) {
+LLDB_LOG(log, "Frame #0 not recognized");
+return;
+  }
+
+  if (StackFrameSP most_relevant_frame_sp =
+  recognized_frame_sp->GetMostRelevantFrame()) {
+LLDB_LOG(log, "Found most relevant frame at index {0}",
+ most_relevant_frame_sp->GetFrameIndex());
+SetSelectedFrame(most_relevant_frame_sp.get());
+  } else {
+LLDB_LOG(log, "No relevant frame!");
+  }
+}
+
 void Thread::WillStop() {
   ThreadPlan *current_plan = GetCurrentPlan();
 
+  SelectMostRelevantFrame();
+
   // FIXME: I may decide to disallow threads with no plans.  In which
   // case this should go to an assert.
 
Index: lldb/source/Target/StackFrameRecognizer.cpp
===
--- lldb/source/Target/StackFrameRecognizer.cpp
+++ lldb/source/Target/StackFrameRecognizer.cpp
@@ -92,7 +92,7 @@
 
   StackFrameRecognizerSP GetRecognizerForFrame(StackFrameSP frame) {
 const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+frame->GetSymbolContext(eSymbolContextEverything);
 ConstString function_name = symctx.GetFunctionName();
 ModuleSP module_sp = symctx.module_sp;
 if (!module_sp) return StackFrameRecognizerSP();
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -38,6 +38,7 @@
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/Symbol.h"
 #include "lldb/Target/ABI.h"
+#include 

[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 240899.
mib added a comment.

Added early return in `AssertFrameRecognizer::RecognizeFrame`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  lldb/include/lldb/Target/AssertFrameRecognizer.h
  lldb/include/lldb/Target/StackFrameRecognizer.h
  lldb/include/lldb/Target/Thread.h
  
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py
  lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  lldb/source/API/SBThread.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Target/AssertFrameRecognizer.cpp
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Process.cpp
  lldb/source/Target/StackFrameRecognizer.cpp
  lldb/source/Target/Thread.cpp
  lldb/test/Shell/Recognizer/Inputs/assert.c
  lldb/test/Shell/Recognizer/assert.test

Index: lldb/test/Shell/Recognizer/assert.test
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/assert.test
@@ -0,0 +1,13 @@
+# UNSUPPORTED: system-windows
+# RUN: %clang_host -g -O0 %S/Inputs/assert.c -o %t.out
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+run
+# CHECK: thread #{{.*}}stop reason = hit program assert
+frame info
+# CHECK: frame #{{.*}}`main at assert.c
+frame recognizer info 0
+# CHECK: frame 0 is recognized by Assert StackFrame Recognizer
+set set thread-format "{${thread.stop-reason-raw}}\n"
+thread info
+# CHECK: signal SIGABRT
+q
Index: lldb/test/Shell/Recognizer/Inputs/assert.c
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/Inputs/assert.c
@@ -0,0 +1,9 @@
+#include 
+
+int main() {
+  int a = 42;
+  assert(a == 42);
+  a--;
+  assert(a == 42);
+  return 0;
+}
Index: lldb/source/Target/Thread.cpp
===
--- lldb/source/Target/Thread.cpp
+++ lldb/source/Target/Thread.cpp
@@ -573,9 +573,64 @@
   m_state = state;
 }
 
+llvm::StringRef Thread::GetStopDescription() {
+  StackFrameSP frame_sp = GetStackFrameAtIndex(0);
+
+  if (!frame_sp)
+return GetStopDescriptionRaw();
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp)
+return GetStopDescriptionRaw();
+
+  llvm::StringRef recognized_stop_description =
+  recognized_frame_sp->GetStopDescription();
+
+  if (!recognized_stop_description.empty())
+return recognized_stop_description;
+
+  return GetStopDescriptionRaw();
+}
+
+llvm::StringRef Thread::GetStopDescriptionRaw() {
+  StopInfoSP stop_info_sp = GetStopInfo();
+  llvm::StringRef raw_stop_description;
+  if (stop_info_sp && stop_info_sp->IsValid())
+raw_stop_description = stop_info_sp->GetDescription();
+  return raw_stop_description;
+}
+
+void Thread::SelectMostRelevantFrame() {
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  auto frames_list_sp = GetStackFrameList();
+
+  // Only the top frame should be recognized.
+  auto frame_sp = frames_list_sp->GetFrameAtIndex(0);
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp) {
+LLDB_LOG(log, "Frame #0 not recognized");
+return;
+  }
+
+  if (StackFrameSP most_relevant_frame_sp =
+  recognized_frame_sp->GetMostRelevantFrame()) {
+LLDB_LOG(log, "Found most relevant frame at index {0}",
+ most_relevant_frame_sp->GetFrameIndex());
+SetSelectedFrame(most_relevant_frame_sp.get());
+  } else {
+LLDB_LOG(log, "No relevant frame!");
+  }
+}
+
 void Thread::WillStop() {
   ThreadPlan *current_plan = GetCurrentPlan();
 
+  SelectMostRelevantFrame();
+
   // FIXME: I may decide to disallow threads with no plans.  In which
   // case this should go to an assert.
 
Index: lldb/source/Target/StackFrameRecognizer.cpp
===
--- lldb/source/Target/StackFrameRecognizer.cpp
+++ lldb/source/Target/StackFrameRecognizer.cpp
@@ -92,7 +92,7 @@
 
   StackFrameRecognizerSP GetRecognizerForFrame(StackFrameSP frame) {
 const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+frame->GetSymbolContext(eSymbolContextEverything);
 ConstString function_name = symctx.GetFunctionName();
 ModuleSP module_sp = symctx.module_sp;
 if (!module_sp) return StackFrameRecognizerSP();
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -38,6 +38,7 @@
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/Symbol.h"
 #include "lldb/Target/ABI.h"
+#include "lldb/Target/AssertFrameRecognizer.h"
 

[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked an inline comment as done.
mib added inline comments.



Comment at: lldb/source/Target/AssertFrameRecognizer.cpp:155
+
+  most_relevant_frame_sp = thread_sp->GetStackFrameAtIndex(
+  std::min(frame_index + 1, last_frame_index));

JDevlieghere wrote:
> Why not return here? 
> 
> ```
> StackFrameSP most_relevant_frame_sp = 
> thread_sp->GetStackFrameAtIndex(std::min(frame_index + 1, last_frame_index));
> return lldb::RecognizedStackFrameSP(new 
> AssertRecognizedStackFrame(most_relevant_frame_sp));
> ```
> 
> That way you don't have to check again after you finish the loop and you can 
> just `return RecognizedStackFrameSP();`.
Fair.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-01-28 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM with one inline comment, but let's give the other reviewers a chance to 
take another look before landing this.




Comment at: lldb/source/Target/AssertFrameRecognizer.cpp:155
+
+  most_relevant_frame_sp = thread_sp->GetStackFrameAtIndex(
+  std::min(frame_index + 1, last_frame_index));

Why not return here? 

```
StackFrameSP most_relevant_frame_sp = 
thread_sp->GetStackFrameAtIndex(std::min(frame_index + 1, last_frame_index));
return lldb::RecognizedStackFrameSP(new 
AssertRecognizedStackFrame(most_relevant_frame_sp));
```

That way you don't have to check again after you finish the loop and you can 
just `return RecognizedStackFrameSP();`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D73303: [lldb/Target] Add Assert StackFrame Recognizer

2020-01-27 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 240744.
mib marked 2 inline comments as done.
mib retitled this revision from "[lldb/Target] Add Abort StackFrame Recognizer" 
to "[lldb/Target] Add Assert StackFrame Recognizer".
mib edited the summary of this revision.
mib added a comment.

Renamed AbortRecognizer to AssertFrameRecognizer.

Moved the assert frame (aka most relevant frame) lookup from the 
AssertRecognizedStackFrame constructor to 
AssertFrameRecognizer::RecognizeFrame(), so if the assert frame is not found, 
only a base RecognizedStackFrame is returned.

Add doxygen comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73303/new/

https://reviews.llvm.org/D73303

Files:
  lldb/docs/use/formatting.rst
  lldb/include/lldb/Core/FormatEntity.h
  lldb/include/lldb/Target/AssertFrameRecognizer.h
  lldb/include/lldb/Target/StackFrameRecognizer.h
  lldb/include/lldb/Target/Thread.h
  
lldb/packages/Python/lldbsuite/test/functionalities/inferior-assert/TestInferiorAssert.py
  lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
  lldb/source/API/SBThread.cpp
  lldb/source/Core/FormatEntity.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Target/AssertFrameRecognizer.cpp
  lldb/source/Target/CMakeLists.txt
  lldb/source/Target/Process.cpp
  lldb/source/Target/StackFrameRecognizer.cpp
  lldb/source/Target/Thread.cpp
  lldb/test/Shell/Recognizer/Inputs/assert.c
  lldb/test/Shell/Recognizer/assert.test

Index: lldb/test/Shell/Recognizer/assert.test
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/assert.test
@@ -0,0 +1,13 @@
+# UNSUPPORTED: system-windows
+# RUN: %clang_host -g -O0 %S/Inputs/assert.c -o %t.out
+# RUN: %lldb -b -s %s %t.out | FileCheck %s
+run
+# CHECK: thread #{{.*}}stop reason = hit program assert
+frame info
+# CHECK: frame #{{.*}}`main at assert.c
+frame recognizer info 0
+# CHECK: frame 0 is recognized by Assert StackFrame Recognizer
+set set thread-format "{${thread.stop-reason-raw}}\n"
+thread info
+# CHECK: signal SIGABRT
+q
Index: lldb/test/Shell/Recognizer/Inputs/assert.c
===
--- /dev/null
+++ lldb/test/Shell/Recognizer/Inputs/assert.c
@@ -0,0 +1,9 @@
+#include 
+
+int main() {
+  int a = 42;
+  assert(a == 42);
+  a--;
+  assert(a == 42);
+  return 0;
+}
Index: lldb/source/Target/Thread.cpp
===
--- lldb/source/Target/Thread.cpp
+++ lldb/source/Target/Thread.cpp
@@ -573,9 +573,64 @@
   m_state = state;
 }
 
+llvm::StringRef Thread::GetStopDescription() {
+  StackFrameSP frame_sp = GetStackFrameAtIndex(0);
+
+  if (!frame_sp)
+return GetStopDescriptionRaw();
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp)
+return GetStopDescriptionRaw();
+
+  llvm::StringRef recognized_stop_description =
+  recognized_frame_sp->GetStopDescription();
+
+  if (!recognized_stop_description.empty())
+return recognized_stop_description;
+
+  return GetStopDescriptionRaw();
+}
+
+llvm::StringRef Thread::GetStopDescriptionRaw() {
+  StopInfoSP stop_info_sp = GetStopInfo();
+  llvm::StringRef raw_stop_description;
+  if (stop_info_sp && stop_info_sp->IsValid())
+raw_stop_description = stop_info_sp->GetDescription();
+  return raw_stop_description;
+}
+
+void Thread::SelectMostRelevantFrame() {
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
+
+  auto frames_list_sp = GetStackFrameList();
+
+  // Only the top frame should be recognized.
+  auto frame_sp = frames_list_sp->GetFrameAtIndex(0);
+
+  auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
+
+  if (!recognized_frame_sp) {
+LLDB_LOG(log, "Frame #0 not recognized");
+return;
+  }
+
+  if (StackFrameSP most_relevant_frame_sp =
+  recognized_frame_sp->GetMostRelevantFrame()) {
+LLDB_LOG(log, "Found most relevant frame at index {0}",
+ most_relevant_frame_sp->GetFrameIndex());
+SetSelectedFrame(most_relevant_frame_sp.get());
+  } else {
+LLDB_LOG(log, "No relevant frame!");
+  }
+}
+
 void Thread::WillStop() {
   ThreadPlan *current_plan = GetCurrentPlan();
 
+  SelectMostRelevantFrame();
+
   // FIXME: I may decide to disallow threads with no plans.  In which
   // case this should go to an assert.
 
Index: lldb/source/Target/StackFrameRecognizer.cpp
===
--- lldb/source/Target/StackFrameRecognizer.cpp
+++ lldb/source/Target/StackFrameRecognizer.cpp
@@ -92,7 +92,7 @@
 
   StackFrameRecognizerSP GetRecognizerForFrame(StackFrameSP frame) {
 const SymbolContext  =
-frame->GetSymbolContext(eSymbolContextModule | eSymbolContextFunction);
+frame->GetSymbolContext(eSymbolContextEverything);
 ConstString function_name =