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