xref: /openbsd-src/gnu/llvm/lldb/examples/python/in_call_stack.py (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1061da546Spatrick#!/usr/bin/env python
2061da546Spatrick
3061da546Spatrick
4061da546Spatrickdef __lldb_init_module(debugger, internal_dict):
5061da546Spatrick  debugger.HandleCommand(
6*f6aab3d8Srobert      f'command alias in_call_stack breakpoint command add --python-function {__name__}.in_call_stack -k name -v %1'
7061da546Spatrick  )
8061da546Spatrick
9061da546Spatrick
10061da546Spatrickdef in_call_stack(frame, bp_loc, arg_dict, _):
11061da546Spatrick  """Only break if the given name is in the current call stack."""
12061da546Spatrick  name = arg_dict.GetValueForKey('name').GetStringValue(1000)
13061da546Spatrick  thread = frame.GetThread()
14061da546Spatrick  found = False
15061da546Spatrick  for frame in thread.frames:
16061da546Spatrick    # Check the symbol.
17061da546Spatrick    symbol = frame.GetSymbol()
18061da546Spatrick    if symbol and name in frame.GetSymbol().GetName():
19061da546Spatrick      return True
20061da546Spatrick    # Check the function.
21061da546Spatrick    function = frame.GetFunction()
22061da546Spatrick    if function and name in function.GetName():
23061da546Spatrick      return True
24061da546Spatrick  return False
25