199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest newly added SBSymbol and SBAddress APIs. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprechtimport lldb 699451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 799451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 899451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 999451b44SJordan Rupprecht 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprechtclass SymbolAPITestCase(TestBase): 1299451b44SJordan Rupprecht def setUp(self): 1399451b44SJordan Rupprecht # Call super's setUp(). 1499451b44SJordan Rupprecht TestBase.setUp(self) 1599451b44SJordan Rupprecht # Find the line number to of function 'c'. 1699451b44SJordan Rupprecht self.line1 = line_number( 172238dcc3SJonas Devlieghere "main.c", "// Find the line number for breakpoint 1 here." 182238dcc3SJonas Devlieghere ) 1999451b44SJordan Rupprecht self.line2 = line_number( 202238dcc3SJonas Devlieghere "main.c", "// Find the line number for breakpoint 2 here." 212238dcc3SJonas Devlieghere ) 2299451b44SJordan Rupprecht 23*ab855530SJonas Devlieghere @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765") 2499451b44SJordan Rupprecht def test(self): 2599451b44SJordan Rupprecht """Exercise some SBSymbol and SBAddress APIs.""" 2699451b44SJordan Rupprecht self.build() 2799451b44SJordan Rupprecht exe = self.getBuildArtifact("a.out") 2899451b44SJordan Rupprecht 2999451b44SJordan Rupprecht # Create a target by the debugger. 3099451b44SJordan Rupprecht target = self.dbg.CreateTarget(exe) 3199451b44SJordan Rupprecht self.assertTrue(target, VALID_TARGET) 3299451b44SJordan Rupprecht 3399451b44SJordan Rupprecht # Now create the two breakpoints inside function 'a'. 342238dcc3SJonas Devlieghere breakpoint1 = target.BreakpointCreateByLocation("main.c", self.line1) 352238dcc3SJonas Devlieghere breakpoint2 = target.BreakpointCreateByLocation("main.c", self.line2) 36b321b429SJonas Devlieghere self.trace("breakpoint1:", breakpoint1) 37b321b429SJonas Devlieghere self.trace("breakpoint2:", breakpoint2) 382238dcc3SJonas Devlieghere self.assertTrue( 392238dcc3SJonas Devlieghere breakpoint1 and breakpoint1.GetNumLocations() == 1, VALID_BREAKPOINT 402238dcc3SJonas Devlieghere ) 412238dcc3SJonas Devlieghere self.assertTrue( 422238dcc3SJonas Devlieghere breakpoint2 and breakpoint2.GetNumLocations() == 1, VALID_BREAKPOINT 432238dcc3SJonas Devlieghere ) 4499451b44SJordan Rupprecht 4599451b44SJordan Rupprecht # Now launch the process, and do not stop at entry point. 462238dcc3SJonas Devlieghere process = target.LaunchSimple(None, None, self.get_process_working_directory()) 4799451b44SJordan Rupprecht self.assertTrue(process, PROCESS_IS_VALID) 4899451b44SJordan Rupprecht 4999451b44SJordan Rupprecht # Frame #0 should be on self.line1. 5047c4c6a7SDave Lee self.assertState(process.GetState(), lldb.eStateStopped) 512238dcc3SJonas Devlieghere thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) 5299451b44SJordan Rupprecht self.assertTrue( 5399451b44SJordan Rupprecht thread.IsValid(), 542238dcc3SJonas Devlieghere "There should be a thread stopped due to breakpoint condition", 552238dcc3SJonas Devlieghere ) 5699451b44SJordan Rupprecht frame0 = thread.GetFrameAtIndex(0) 5799451b44SJordan Rupprecht symbol_line1 = frame0.GetSymbol() 5899451b44SJordan Rupprecht # We should have a symbol type of code. 59619e2e09SDave Lee self.assertEqual(symbol_line1.GetType(), lldb.eSymbolTypeCode) 6099451b44SJordan Rupprecht addr_line1 = symbol_line1.GetStartAddress() 6199451b44SJordan Rupprecht # And a section type of code, too. 622238dcc3SJonas Devlieghere self.assertEqual( 632238dcc3SJonas Devlieghere addr_line1.GetSection().GetSectionType(), lldb.eSectionTypeCode 642238dcc3SJonas Devlieghere ) 6599451b44SJordan Rupprecht 6699451b44SJordan Rupprecht # Continue the inferior, the breakpoint 2 should be hit. 6799451b44SJordan Rupprecht process.Continue() 6847c4c6a7SDave Lee self.assertState(process.GetState(), lldb.eStateStopped) 692238dcc3SJonas Devlieghere thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) 7099451b44SJordan Rupprecht self.assertTrue( 7199451b44SJordan Rupprecht thread.IsValid(), 722238dcc3SJonas Devlieghere "There should be a thread stopped due to breakpoint condition", 732238dcc3SJonas Devlieghere ) 7499451b44SJordan Rupprecht frame0 = thread.GetFrameAtIndex(0) 7599451b44SJordan Rupprecht symbol_line2 = frame0.GetSymbol() 7699451b44SJordan Rupprecht # We should have a symbol type of code. 77619e2e09SDave Lee self.assertEqual(symbol_line2.GetType(), lldb.eSymbolTypeCode) 7899451b44SJordan Rupprecht addr_line2 = symbol_line2.GetStartAddress() 7999451b44SJordan Rupprecht # And a section type of code, too. 802238dcc3SJonas Devlieghere self.assertEqual( 812238dcc3SJonas Devlieghere addr_line2.GetSection().GetSectionType(), lldb.eSectionTypeCode 822238dcc3SJonas Devlieghere ) 8399451b44SJordan Rupprecht 8499451b44SJordan Rupprecht # Now verify that both addresses point to the same module. 8599451b44SJordan Rupprecht if self.TraceOn(): 8699451b44SJordan Rupprecht print("UUID:", addr_line1.GetModule().GetUUIDString()) 872238dcc3SJonas Devlieghere self.assertEqual( 882238dcc3SJonas Devlieghere addr_line1.GetModule().GetUUIDString(), 892238dcc3SJonas Devlieghere addr_line2.GetModule().GetUUIDString(), 902238dcc3SJonas Devlieghere ) 91