Skip to content

Commit 1b099c1

Browse files
committed
[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.
1 parent 6551ac7 commit 1b099c1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lldb/examples/python/in_call_stack.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
3+
4+
def __lldb_init_module(debugger, internal_dict):
5+
debugger.HandleCommand(
6+
'command alias in_call_stack breakpoint command add --python-function in_call_stack.in_call_stack -k name -v %1'
7+
)
8+
9+
10+
def in_call_stack(frame, bp_loc, arg_dict, _):
11+
"""Only break if the given name is in the current call stack."""
12+
thread = frame.GetThread()
13+
found = False
14+
for frame in thread.frames:
15+
name = arg_dict.GetValueForKey('name').GetStringValue(1000)
16+
# Check the symbol.
17+
symbol = frame.GetSymbol()
18+
if symbol and name in frame.GetSymbol().GetName():
19+
return True
20+
# Check the function.
21+
function = frame.GetFunction()
22+
if function and name in function.GetName():
23+
return True
24+
return False

0 commit comments

Comments
 (0)