199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest SBSymbolContext APIs. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprechtfrom __future__ import print_function 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport lldb 899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprecht 1399451b44SJordan Rupprechtclass SymbolContextAPITestCase(TestBase): 1499451b44SJordan Rupprecht 1599451b44SJordan Rupprecht mydir = TestBase.compute_mydir(__file__) 1699451b44SJordan Rupprecht 1799451b44SJordan Rupprecht def setUp(self): 1899451b44SJordan Rupprecht # Call super's setUp(). 1999451b44SJordan Rupprecht TestBase.setUp(self) 2099451b44SJordan Rupprecht # Find the line number to of function 'c'. 2199451b44SJordan Rupprecht self.line = line_number( 2299451b44SJordan Rupprecht 'main.c', '// Find the line number of function "c" here.') 2399451b44SJordan Rupprecht 2499451b44SJordan Rupprecht @add_test_categories(['pyapi']) 2599451b44SJordan Rupprecht @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") 265238b800SJonas Devlieghere @skipIfReproducer # FIXME: Unexpected packet during (passive) replay 2799451b44SJordan Rupprecht def test(self): 2899451b44SJordan Rupprecht """Exercise SBSymbolContext API extensively.""" 2999451b44SJordan Rupprecht self.build() 3099451b44SJordan Rupprecht exe = self.getBuildArtifact("a.out") 3199451b44SJordan Rupprecht 3299451b44SJordan Rupprecht # Create a target by the debugger. 3399451b44SJordan Rupprecht target = self.dbg.CreateTarget(exe) 3499451b44SJordan Rupprecht self.assertTrue(target, VALID_TARGET) 3599451b44SJordan Rupprecht 3699451b44SJordan Rupprecht # Now create a breakpoint on main.c by name 'c'. 379e391d4fSJonas Devlieghere breakpoint = target.BreakpointCreateByName('c', exe) 389e391d4fSJonas Devlieghere self.assertTrue(breakpoint and breakpoint.GetNumLocations() == 1, 3999451b44SJordan Rupprecht VALID_BREAKPOINT) 4099451b44SJordan Rupprecht 4199451b44SJordan Rupprecht # Now launch the process, and do not stop at entry point. 429e391d4fSJonas Devlieghere process = target.LaunchSimple(None, None, 439e391d4fSJonas Devlieghere self.get_process_working_directory()) 4499451b44SJordan Rupprecht self.assertTrue(process, PROCESS_IS_VALID) 4599451b44SJordan Rupprecht 4699451b44SJordan Rupprecht # Frame #0 should be on self.line. 479e391d4fSJonas Devlieghere thread = lldbutil.get_stopped_thread(process, 489e391d4fSJonas Devlieghere lldb.eStopReasonBreakpoint) 499e391d4fSJonas Devlieghere self.assertTrue(thread.IsValid(), 5099451b44SJordan Rupprecht "There should be a thread stopped due to breakpoint") 5199451b44SJordan Rupprecht frame0 = thread.GetFrameAtIndex(0) 52*619e2e09SDave Lee self.assertEqual(frame0.GetLineEntry().GetLine(), self.line) 5399451b44SJordan Rupprecht 5499451b44SJordan Rupprecht # Now get the SBSymbolContext from this frame. We want everything. :-) 5599451b44SJordan Rupprecht context = frame0.GetSymbolContext(lldb.eSymbolContextEverything) 5699451b44SJordan Rupprecht self.assertTrue(context) 5799451b44SJordan Rupprecht 5899451b44SJordan Rupprecht # Get the description of this module. 5999451b44SJordan Rupprecht module = context.GetModule() 6099451b44SJordan Rupprecht desc = lldbutil.get_description(module) 619e391d4fSJonas Devlieghere self.expect(desc, "The module should match", exe=False, substrs=[exe]) 6299451b44SJordan Rupprecht 6399451b44SJordan Rupprecht compileUnit = context.GetCompileUnit() 649e391d4fSJonas Devlieghere self.expect(str(compileUnit), 6599451b44SJordan Rupprecht "The compile unit should match", 6699451b44SJordan Rupprecht exe=False, 6799451b44SJordan Rupprecht substrs=[self.getSourcePath('main.c')]) 6899451b44SJordan Rupprecht 6999451b44SJordan Rupprecht function = context.GetFunction() 7099451b44SJordan Rupprecht self.assertTrue(function) 7199451b44SJordan Rupprecht 7299451b44SJordan Rupprecht block = context.GetBlock() 7399451b44SJordan Rupprecht self.assertTrue(block) 7499451b44SJordan Rupprecht 7599451b44SJordan Rupprecht lineEntry = context.GetLineEntry() 769e391d4fSJonas Devlieghere self.expect(lineEntry.GetFileSpec().GetDirectory(), 7799451b44SJordan Rupprecht "The line entry should have the correct directory", 7899451b44SJordan Rupprecht exe=False, 7999451b44SJordan Rupprecht substrs=[self.mydir]) 809e391d4fSJonas Devlieghere self.expect(lineEntry.GetFileSpec().GetFilename(), 8199451b44SJordan Rupprecht "The line entry should have the correct filename", 8299451b44SJordan Rupprecht exe=False, 8399451b44SJordan Rupprecht substrs=['main.c']) 84*619e2e09SDave Lee self.assertEqual(lineEntry.GetLine(), self.line, 8599451b44SJordan Rupprecht "The line entry's line number should match ") 8699451b44SJordan Rupprecht 8799451b44SJordan Rupprecht symbol = context.GetSymbol() 8899451b44SJordan Rupprecht self.assertTrue( 8999451b44SJordan Rupprecht function.GetName() == symbol.GetName() and symbol.GetName() == 'c', 9099451b44SJordan Rupprecht "The symbol name should be 'c'") 9199451b44SJordan Rupprecht 9299451b44SJordan Rupprecht sc_list = lldb.SBSymbolContextList() 9399451b44SJordan Rupprecht sc_list.Append(context) 9499451b44SJordan Rupprecht self.assertEqual(len(sc_list), 1) 9599451b44SJordan Rupprecht for sc in sc_list: 9699451b44SJordan Rupprecht self.assertEqual(lineEntry, sc.GetLineEntry()) 97