60 lines · python
1"""2Test SBTarget APIs.3"""4 5 6import lldb7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10 11 12class TestNameLookup(TestBase):13 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")14 def test_target(self):15 """Exercise SBTarget.FindFunctions() with various name masks.16 17 A previous regression caused mangled names to not be able to be looked up.18 This test verifies that using a mangled name with eFunctionNameTypeFull works19 and that using a function basename with eFunctionNameTypeFull works for all20 C++ functions that are at the global namespace level."""21 self.build()22 exe = self.getBuildArtifact("a.out")23 24 # Create a target by the debugger.25 target = self.dbg.CreateTarget(exe)26 self.assertTrue(target, VALID_TARGET)27 28 exe_module = target.FindModule(target.GetExecutable())29 30 c_name_to_symbol = {}31 cpp_name_to_symbol = {}32 mangled_to_symbol = {}33 num_symbols = exe_module.GetNumSymbols()34 for i in range(num_symbols):35 symbol = exe_module.GetSymbolAtIndex(i)36 name = symbol.GetName()37 if (38 name39 and "unique_function_name" in name40 and "__PRETTY_FUNCTION__" not in name41 ):42 mangled = symbol.GetMangledName()43 if mangled:44 mangled_to_symbol[mangled] = symbol45 if name:46 cpp_name_to_symbol[name] = symbol47 elif name:48 c_name_to_symbol[name] = symbol49 50 # Make sure each mangled name turns up exactly one match when looking up51 # functions by full name and using the mangled name as the name in the52 # lookup53 self.assertGreaterEqual(len(mangled_to_symbol), 6)54 for mangled in mangled_to_symbol.keys():55 symbol_contexts = target.FindFunctions(mangled, lldb.eFunctionNameTypeFull)56 self.assertEqual(symbol_contexts.GetSize(), 1)57 for symbol_context in symbol_contexts:58 self.assertTrue(symbol_context.GetFunction().IsValid())59 self.assertTrue(symbol_context.GetSymbol().IsValid())60