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