xref: /llvm-project/lldb/examples/python/in_call_stack.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1#!/usr/bin/env python
2
3
4def __lldb_init_module(debugger, internal_dict):
5    debugger.HandleCommand(
6        f"command alias in_call_stack breakpoint command add --python-function {__name__}.in_call_stack -k name -v %1"
7    )
8
9
10def in_call_stack(frame, bp_loc, arg_dict, _):
11    """Only break if the given name is in the current call stack."""
12    name = arg_dict.GetValueForKey("name").GetStringValue(1000)
13    thread = frame.GetThread()
14    found = False
15    for frame in thread.frames:
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
25