2 Test SBSymbolContext APIs.
6 from lldbsuite
.test
.decorators
import *
7 from lldbsuite
.test
.lldbtest
import *
8 from lldbsuite
.test
import lldbutil
11 class SymbolContextAPITestCase(TestBase
):
13 # Call super's setUp().
15 # Find the line number to of function 'c'.
16 self
.line
= line_number(
17 "main.c", '// Find the line number of function "c" here.'
20 @expectedFailureAll(oslist
=["windows"], bugnumber
="llvm.org/pr24778")
22 """Exercise SBSymbolContext API extensively."""
24 exe
= self
.getBuildArtifact("a.out")
26 # Create a target by the debugger.
27 target
= self
.dbg
.CreateTarget(exe
)
28 self
.assertTrue(target
, VALID_TARGET
)
30 # Now create a breakpoint on main.c by name 'c'.
31 breakpoint
= target
.BreakpointCreateByName("c", exe
)
33 breakpoint
and breakpoint
.GetNumLocations() == 1, VALID_BREAKPOINT
36 # Now launch the process, and do not stop at entry point.
37 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
38 self
.assertTrue(process
, PROCESS_IS_VALID
)
40 # Frame #0 should be on self.line.
41 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
43 thread
.IsValid(), "There should be a thread stopped due to breakpoint"
45 frame0
= thread
.GetFrameAtIndex(0)
46 self
.assertEqual(frame0
.GetLineEntry().GetLine(), self
.line
)
48 # Now get the SBSymbolContext from this frame. We want everything. :-)
49 context
= frame0
.GetSymbolContext(lldb
.eSymbolContextEverything
)
50 self
.assertTrue(context
)
52 # Get the description of this module.
53 module
= context
.GetModule()
54 desc
= lldbutil
.get_description(module
)
55 self
.expect(desc
, "The module should match", exe
=False, substrs
=[exe
])
57 compileUnit
= context
.GetCompileUnit()
60 "The compile unit should match",
62 substrs
=[self
.getSourcePath("main.c")],
65 function
= context
.GetFunction()
66 self
.assertTrue(function
)
68 block
= context
.GetBlock()
69 self
.assertTrue(block
)
71 lineEntry
= context
.GetLineEntry()
73 lineEntry
.GetFileSpec().GetDirectory(),
74 "The line entry should have the correct directory",
79 lineEntry
.GetFileSpec().GetFilename(),
80 "The line entry should have the correct filename",
85 lineEntry
.GetLine(), self
.line
, "The line entry's line number should match "
88 symbol
= context
.GetSymbol()
90 function
.GetName() == symbol
.GetName() and symbol
.GetName() == "c",
91 "The symbol name should be 'c'",
94 sc_list
= lldb
.SBSymbolContextList()
95 sc_list
.Append(context
)
96 self
.assertEqual(len(sc_list
), 1)
98 self
.assertEqual(lineEntry
, sc
.GetLineEntry())