1""" 2Test SBTarget APIs. 3""" 4 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 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 works 19 and that using a function basename with eFunctionNameTypeFull works for all 20 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 name 39 and "unique_function_name" in name 40 and "__PRETTY_FUNCTION__" not in name 41 ): 42 mangled = symbol.GetMangledName() 43 if mangled: 44 mangled_to_symbol[mangled] = symbol 45 if name: 46 cpp_name_to_symbol[name] = symbol 47 elif name: 48 c_name_to_symbol[name] = symbol 49 50 # Make sure each mangled name turns up exactly one match when looking up 51 # functions by full name and using the mangled name as the name in the 52 # lookup 53 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