1*99451b44SJordan Rupprechtimport lldb
2*99451b44SJordan Rupprecht
3*99451b44SJordan Rupprecht
4*99451b44SJordan Rupprechtdef stop_if_called_from_a(frame, bp_loc, dict):
5*99451b44SJordan Rupprecht
6*99451b44SJordan Rupprecht    thread = frame.GetThread()
7*99451b44SJordan Rupprecht    process = thread.GetProcess()
8*99451b44SJordan Rupprecht    target = process.GetTarget()
9*99451b44SJordan Rupprecht    dbg = target.GetDebugger()
10*99451b44SJordan Rupprecht
11*99451b44SJordan Rupprecht    # Perform synchronous interaction with the debugger.
12*99451b44SJordan Rupprecht    old_async = dbg.GetAsync()
13*99451b44SJordan Rupprecht    dbg.SetAsync(True)
14*99451b44SJordan Rupprecht
15*99451b44SJordan Rupprecht    # We check the call frames in order to stop only when the immediate caller
16*99451b44SJordan Rupprecht    # of the leaf function c() is a().  If it's not the right caller, we ask the
17*99451b44SJordan Rupprecht    # command interpreter to continue execution.
18*99451b44SJordan Rupprecht
19*99451b44SJordan Rupprecht    should_stop = True
20*99451b44SJordan Rupprecht    if thread.GetNumFrames() >= 2:
21*99451b44SJordan Rupprecht
22*99451b44SJordan Rupprecht        if (thread.frames[0].function.name ==
23*99451b44SJordan Rupprecht                'c' and thread.frames[1].function.name == 'a'):
24*99451b44SJordan Rupprecht            should_stop = True
25*99451b44SJordan Rupprecht        else:
26*99451b44SJordan Rupprecht            should_stop = False
27*99451b44SJordan Rupprecht
28*99451b44SJordan Rupprecht    dbg.SetAsync(old_async)
29*99451b44SJordan Rupprecht    return should_stop
30