xref: /llvm-project/lldb/examples/python/in_call_stack.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
11b099c1dSJonas Devlieghere#!/usr/bin/env python
21b099c1dSJonas Devlieghere
31b099c1dSJonas Devlieghere
41b099c1dSJonas Devliegheredef __lldb_init_module(debugger, internal_dict):
51b099c1dSJonas Devlieghere    debugger.HandleCommand(
6*2238dcc3SJonas Devlieghere        f"command alias in_call_stack breakpoint command add --python-function {__name__}.in_call_stack -k name -v %1"
71b099c1dSJonas Devlieghere    )
81b099c1dSJonas Devlieghere
91b099c1dSJonas Devlieghere
101b099c1dSJonas Devliegheredef in_call_stack(frame, bp_loc, arg_dict, _):
111b099c1dSJonas Devlieghere    """Only break if the given name is in the current call stack."""
12*2238dcc3SJonas Devlieghere    name = arg_dict.GetValueForKey("name").GetStringValue(1000)
131b099c1dSJonas Devlieghere    thread = frame.GetThread()
141b099c1dSJonas Devlieghere    found = False
151b099c1dSJonas Devlieghere    for frame in thread.frames:
161b099c1dSJonas Devlieghere        # Check the symbol.
171b099c1dSJonas Devlieghere        symbol = frame.GetSymbol()
181b099c1dSJonas Devlieghere        if symbol and name in frame.GetSymbol().GetName():
191b099c1dSJonas Devlieghere            return True
201b099c1dSJonas Devlieghere        # Check the function.
211b099c1dSJonas Devlieghere        function = frame.GetFunction()
221b099c1dSJonas Devlieghere        if function and name in function.GetName():
231b099c1dSJonas Devlieghere            return True
241b099c1dSJonas Devlieghere    return False
25