[Lldb-commits] [lldb] 1b099c1 - [Examples] Add in_call_stack breakpoint function.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 22 15:36:55 PST 2019


Author: Jonas Devlieghere
Date: 2019-11-22T15:36:42-08:00
New Revision: 1b099c1df00e3c8a0ba20af199c89a154bdb7a45

URL: https://github.com/llvm/llvm-project/commit/1b099c1df00e3c8a0ba20af199c89a154bdb7a45
DIFF: https://github.com/llvm/llvm-project/commit/1b099c1df00e3c8a0ba20af199c89a154bdb7a45.diff

LOG: [Examples] Add in_call_stack breakpoint function.

The in_call_stack Python script makes it possible to modify the last
breakpoint to only stop if a given function is present in the call
stack. It will check both the symbol name and the function name (coming
from the debug info, in case the binary is stripped).

To use this, you have to:

1. Import the script into lldb.

(lldb) command script import in_call_stack.py

2. Set a breakpoint and use the in_call_stack alias.

(lldb) b foo
(lldb) in_call_stack bar

Note that this alias operates on the last set breakpoint. You can re-run
the in_call_stack command to modify the condition.

Added: 
    lldb/examples/python/in_call_stack.py

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/lldb/examples/python/in_call_stack.py b/lldb/examples/python/in_call_stack.py
new file mode 100755
index 000000000000..ba3ca57267fa
--- /dev/null
+++ b/lldb/examples/python/in_call_stack.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+
+def __lldb_init_module(debugger, internal_dict):
+  debugger.HandleCommand(
+      'command alias in_call_stack breakpoint command add --python-function in_call_stack.in_call_stack -k name -v %1'
+  )
+
+
+def in_call_stack(frame, bp_loc, arg_dict, _):
+  """Only break if the given name is in the current call stack."""
+  thread = frame.GetThread()
+  found = False
+  for frame in thread.frames:
+    name = arg_dict.GetValueForKey('name').GetStringValue(1000)
+    # Check the symbol.
+    symbol = frame.GetSymbol()
+    if symbol and name in frame.GetSymbol().GetName():
+      return True
+    # Check the function.
+    function = frame.GetFunction()
+    if function and name in function.GetName():
+      return True
+  return False


        


More information about the lldb-commits mailing list