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