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