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 def setUp(self): 1699451b44SJordan Rupprecht # Call super's setUp(). 1799451b44SJordan Rupprecht TestBase.setUp(self) 1899451b44SJordan Rupprecht # Find the line number to of function 'c'. 1999451b44SJordan Rupprecht self.line = line_number( 2099451b44SJordan Rupprecht 'main.c', '// Find the line number of function "c" here.') 2199451b44SJordan Rupprecht 2299451b44SJordan Rupprecht @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") 2399451b44SJordan Rupprecht def test(self): 2499451b44SJordan Rupprecht """Exercise SBSymbolContext API extensively.""" 2599451b44SJordan Rupprecht self.build() 2699451b44SJordan Rupprecht exe = self.getBuildArtifact("a.out") 2799451b44SJordan Rupprecht 2899451b44SJordan Rupprecht # Create a target by the debugger. 2999451b44SJordan Rupprecht target = self.dbg.CreateTarget(exe) 3099451b44SJordan Rupprecht self.assertTrue(target, VALID_TARGET) 3199451b44SJordan Rupprecht 3299451b44SJordan Rupprecht # Now create a breakpoint on main.c by name 'c'. 339e391d4fSJonas Devlieghere breakpoint = target.BreakpointCreateByName('c', exe) 349e391d4fSJonas Devlieghere self.assertTrue(breakpoint and breakpoint.GetNumLocations() == 1, 3599451b44SJordan Rupprecht VALID_BREAKPOINT) 3699451b44SJordan Rupprecht 3799451b44SJordan Rupprecht # Now launch the process, and do not stop at entry point. 389e391d4fSJonas Devlieghere process = target.LaunchSimple(None, None, 399e391d4fSJonas Devlieghere self.get_process_working_directory()) 4099451b44SJordan Rupprecht self.assertTrue(process, PROCESS_IS_VALID) 4199451b44SJordan Rupprecht 4299451b44SJordan Rupprecht # Frame #0 should be on self.line. 439e391d4fSJonas Devlieghere thread = lldbutil.get_stopped_thread(process, 449e391d4fSJonas Devlieghere lldb.eStopReasonBreakpoint) 459e391d4fSJonas Devlieghere self.assertTrue(thread.IsValid(), 4699451b44SJordan Rupprecht "There should be a thread stopped due to breakpoint") 4799451b44SJordan Rupprecht frame0 = thread.GetFrameAtIndex(0) 48*619e2e09SDave Lee self.assertEqual(frame0.GetLineEntry().GetLine(), self.line) 4999451b44SJordan Rupprecht 5099451b44SJordan Rupprecht # Now get the SBSymbolContext from this frame. We want everything. :-) 5199451b44SJordan Rupprecht context = frame0.GetSymbolContext(lldb.eSymbolContextEverything) 5299451b44SJordan Rupprecht self.assertTrue(context) 5399451b44SJordan Rupprecht 5499451b44SJordan Rupprecht # Get the description of this module. 5599451b44SJordan Rupprecht module = context.GetModule() 5699451b44SJordan Rupprecht desc = lldbutil.get_description(module) 579e391d4fSJonas Devlieghere self.expect(desc, "The module should match", exe=False, substrs=[exe]) 5899451b44SJordan Rupprecht 5999451b44SJordan Rupprecht compileUnit = context.GetCompileUnit() 609e391d4fSJonas Devlieghere self.expect(str(compileUnit), 6199451b44SJordan Rupprecht "The compile unit should match", 6299451b44SJordan Rupprecht exe=False, 6399451b44SJordan Rupprecht substrs=[self.getSourcePath('main.c')]) 6499451b44SJordan Rupprecht 6599451b44SJordan Rupprecht function = context.GetFunction() 6699451b44SJordan Rupprecht self.assertTrue(function) 6799451b44SJordan Rupprecht 6899451b44SJordan Rupprecht block = context.GetBlock() 6999451b44SJordan Rupprecht self.assertTrue(block) 7099451b44SJordan Rupprecht 7199451b44SJordan Rupprecht lineEntry = context.GetLineEntry() 729e391d4fSJonas Devlieghere self.expect(lineEntry.GetFileSpec().GetDirectory(), 7399451b44SJordan Rupprecht "The line entry should have the correct directory", 7499451b44SJordan Rupprecht exe=False, 7599451b44SJordan Rupprecht substrs=[self.mydir]) 769e391d4fSJonas Devlieghere self.expect(lineEntry.GetFileSpec().GetFilename(), 7799451b44SJordan Rupprecht "The line entry should have the correct filename", 7899451b44SJordan Rupprecht exe=False, 7999451b44SJordan Rupprecht substrs=['main.c']) 80*619e2e09SDave Lee self.assertEqual(lineEntry.GetLine(), self.line, 8199451b44SJordan Rupprecht "The line entry's line number should match ") 8299451b44SJordan Rupprecht 8399451b44SJordan Rupprecht symbol = context.GetSymbol() 8499451b44SJordan Rupprecht self.assertTrue( 8599451b44SJordan Rupprecht function.GetName() == symbol.GetName() and symbol.GetName() == 'c', 8699451b44SJordan Rupprecht "The symbol name should be 'c'") 8799451b44SJordan Rupprecht 8899451b44SJordan Rupprecht sc_list = lldb.SBSymbolContextList() 8999451b44SJordan Rupprecht sc_list.Append(context) 9099451b44SJordan Rupprecht self.assertEqual(len(sc_list), 1) 9199451b44SJordan Rupprecht for sc in sc_list: 9299451b44SJordan Rupprecht self.assertEqual(lineEntry, sc.GetLineEntry()) 93