xref: /llvm-project/lldb/test/API/functionalities/conditional_break/conditional_break.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprechtimport lldb
299451b44SJordan Rupprecht
399451b44SJordan Rupprecht
499451b44SJordan Rupprechtdef stop_if_called_from_a(frame, bp_loc, dict):
599451b44SJordan Rupprecht    thread = frame.GetThread()
699451b44SJordan Rupprecht    process = thread.GetProcess()
799451b44SJordan Rupprecht    target = process.GetTarget()
899451b44SJordan Rupprecht    dbg = target.GetDebugger()
999451b44SJordan Rupprecht
1099451b44SJordan Rupprecht    # Perform synchronous interaction with the debugger.
1199451b44SJordan Rupprecht    old_async = dbg.GetAsync()
1299451b44SJordan Rupprecht    dbg.SetAsync(True)
1399451b44SJordan Rupprecht
1499451b44SJordan Rupprecht    # We check the call frames in order to stop only when the immediate caller
1599451b44SJordan Rupprecht    # of the leaf function c() is a().  If it's not the right caller, we ask the
1699451b44SJordan Rupprecht    # command interpreter to continue execution.
1799451b44SJordan Rupprecht
1899451b44SJordan Rupprecht    should_stop = True
1999451b44SJordan Rupprecht    if thread.GetNumFrames() >= 2:
20*2238dcc3SJonas Devlieghere        if (
21*2238dcc3SJonas Devlieghere            thread.frames[0].function.name == "c"
22*2238dcc3SJonas Devlieghere            and thread.frames[1].function.name == "a"
23*2238dcc3SJonas Devlieghere        ):
2499451b44SJordan Rupprecht            should_stop = True
2599451b44SJordan Rupprecht        else:
2699451b44SJordan Rupprecht            should_stop = False
2799451b44SJordan Rupprecht
2899451b44SJordan Rupprecht    dbg.SetAsync(old_async)
2999451b44SJordan Rupprecht    return should_stop
30