1""" 2Test SBSymbolContext APIs. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class SymbolContextTwoFilesTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 @add_test_categories(['pyapi']) 18 @expectedFailureAll(oslist=["windows"]) 19 def test_lookup_by_address(self): 20 """Test lookup by address in a module with multiple compilation units""" 21 self.build() 22 exe = self.getBuildArtifact("a.out") 23 target = self.dbg.CreateTarget(exe) 24 self.assertTrue(target, VALID_TARGET) 25 26 module = target.GetModuleAtIndex(0) 27 self.assertTrue(module.IsValid()) 28 for symbol_name in ["struct1::f()", "struct2::f()"]: 29 sc_list = module.FindFunctions(symbol_name, lldb.eSymbolTypeCode) 30 self.assertTrue(1, sc_list.GetSize()) 31 symbol_address = sc_list.GetContextAtIndex( 32 0).GetSymbol().GetStartAddress() 33 self.assertTrue(symbol_address.IsValid()) 34 sc_by_address = module.ResolveSymbolContextForAddress( 35 symbol_address, lldb.eSymbolContextFunction) 36 self.assertEqual(symbol_name, 37 sc_by_address.GetFunction().GetName()) 38 39 @add_test_categories(['pyapi']) 40 def test_ranges_in_multiple_compile_unit(self): 41 """This test verifies that we correctly handle the case when multiple 42 compile unit contains DW_AT_ranges and DW_AT_ranges_base attributes.""" 43 self.build() 44 exe = self.getBuildArtifact("a.out") 45 target = self.dbg.CreateTarget(exe) 46 self.assertTrue(target, VALID_TARGET) 47 48 source1 = "file1.cpp" 49 line1 = line_number(source1, '// Break1') 50 breakpoint1 = target.BreakpointCreateByLocation(source1, line1) 51 self.assertIsNotNone(breakpoint1) 52 self.assertTrue(breakpoint1.IsValid()) 53 54 source2 = "file2.cpp" 55 line2 = line_number(source2, '// Break2') 56 breakpoint2 = target.BreakpointCreateByLocation(source2, line2) 57 self.assertIsNotNone(breakpoint2) 58 self.assertTrue(breakpoint2.IsValid()) 59 60 process = target.LaunchSimple(None, None, self.get_process_working_directory()) 61 self.assertIsNotNone(process, PROCESS_IS_VALID) 62 63 threads = lldbutil.get_threads_stopped_at_breakpoint( 64 process, breakpoint2) 65 self.assertEqual(len(threads), 1) 66 frame = threads[0].GetFrameAtIndex(0) 67 value = frame.FindVariable("x") 68 self.assertTrue(value.IsValid()) 69 70 process.Continue() 71 72 threads = lldbutil.get_threads_stopped_at_breakpoint( 73 process, breakpoint1) 74 self.assertEqual(len(threads), 1) 75 frame = threads[0].GetFrameAtIndex(0) 76 value = frame.FindVariable("x") 77 self.assertTrue(value.IsValid()) 78 79 process.Continue() 80