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