1import lldb
2
3class Resolver:
4  got_files = 0
5  func_list = []
6
7  def __init__(self, bkpt, extra_args, dict):
8      self.bkpt = bkpt
9      self.extra_args = extra_args
10
11      Resolver.func_list = []
12      Resolver.got_files = 0
13
14  def __callback__(self, sym_ctx):
15      sym_name = "not_a_real_function_name"
16      sym_item = self.extra_args.GetValueForKey("symbol")
17      if sym_item.IsValid():
18          sym_name = sym_item.GetStringValue(1000)
19      else:
20          print("Didn't have a value for key 'symbol'")
21
22      if sym_ctx.compile_unit.IsValid():
23          Resolver.got_files = 1
24      else:
25          Resolver.got_files = 2
26
27      if sym_ctx.function.IsValid():
28        Resolver.got_files = 3
29        func_name = sym_ctx.function.GetName()
30        Resolver.func_list.append(func_name)
31        if sym_name == func_name:
32          self.bkpt.AddLocation(sym_ctx.function.GetStartAddress())
33        return
34
35      if sym_ctx.module.IsValid():
36          sym = sym_ctx.module.FindSymbol(sym_name, lldb.eSymbolTypeCode)
37          if sym.IsValid():
38              self.bkpt.AddLocation(sym.GetStartAddress())
39
40  def get_short_help(self):
41      return "I am a python breakpoint resolver"
42
43class ResolverModuleDepth(Resolver):
44    def __get_depth__ (self):
45        return lldb.eSearchDepthModule
46
47class ResolverCUDepth(Resolver):
48    def __get_depth__ (self):
49        return lldb.eSearchDepthCompUnit
50
51class ResolverFuncDepth(Resolver):
52    def __get_depth__ (self):
53        return lldb.eSearchDepthFunction
54
55class ResolverBadDepth(Resolver):
56    def __get_depth__ (self):
57        return lldb.kLastSearchDepthKind + 1
58