91 lines · python
1"""2Test newly added SBSymbol and SBAddress APIs.3"""4 5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9 10 11class SymbolAPITestCase(TestBase):12 def setUp(self):13 # Call super's setUp().14 TestBase.setUp(self)15 # Find the line number to of function 'c'.16 self.line1 = line_number(17 "main.c", "// Find the line number for breakpoint 1 here."18 )19 self.line2 = line_number(20 "main.c", "// Find the line number for breakpoint 2 here."21 )22 23 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")24 def test(self):25 """Exercise some SBSymbol and SBAddress APIs."""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 # Now create the two breakpoints inside function 'a'.34 breakpoint1 = target.BreakpointCreateByLocation("main.c", self.line1)35 breakpoint2 = target.BreakpointCreateByLocation("main.c", self.line2)36 self.trace("breakpoint1:", breakpoint1)37 self.trace("breakpoint2:", breakpoint2)38 self.assertTrue(39 breakpoint1 and breakpoint1.GetNumLocations() == 1, VALID_BREAKPOINT40 )41 self.assertTrue(42 breakpoint2 and breakpoint2.GetNumLocations() == 1, VALID_BREAKPOINT43 )44 45 # Now launch the process, and do not stop at entry point.46 process = target.LaunchSimple(None, None, self.get_process_working_directory())47 self.assertTrue(process, PROCESS_IS_VALID)48 49 # Frame #0 should be on self.line1.50 self.assertState(process.GetState(), lldb.eStateStopped)51 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)52 self.assertTrue(53 thread.IsValid(),54 "There should be a thread stopped due to breakpoint condition",55 )56 frame0 = thread.GetFrameAtIndex(0)57 symbol_line1 = frame0.GetSymbol()58 # We should have a symbol type of code.59 self.assertEqual(symbol_line1.GetType(), lldb.eSymbolTypeCode)60 addr_line1 = symbol_line1.GetStartAddress()61 # And a section type of code, too.62 self.assertEqual(63 addr_line1.GetSection().GetSectionType(), lldb.eSectionTypeCode64 )65 66 # Continue the inferior, the breakpoint 2 should be hit.67 process.Continue()68 self.assertState(process.GetState(), lldb.eStateStopped)69 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)70 self.assertTrue(71 thread.IsValid(),72 "There should be a thread stopped due to breakpoint condition",73 )74 frame0 = thread.GetFrameAtIndex(0)75 symbol_line2 = frame0.GetSymbol()76 # We should have a symbol type of code.77 self.assertEqual(symbol_line2.GetType(), lldb.eSymbolTypeCode)78 addr_line2 = symbol_line2.GetStartAddress()79 # And a section type of code, too.80 self.assertEqual(81 addr_line2.GetSection().GetSectionType(), lldb.eSectionTypeCode82 )83 84 # Now verify that both addresses point to the same module.85 if self.TraceOn():86 print("UUID:", addr_line1.GetModule().GetUUIDString())87 self.assertEqual(88 addr_line1.GetModule().GetUUIDString(),89 addr_line2.GetModule().GetUUIDString(),90 )91