2011-04-01 00:35:55 +00:00
|
|
|
"""
|
|
|
|
Test newly added SBSymbol and SBAddress APIs.
|
|
|
|
"""
|
|
|
|
|
2015-11-03 02:06:18 +00:00
|
|
|
import lldb
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test import lldbutil
|
2011-04-01 00:35:55 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-04-01 00:35:55 +00:00
|
|
|
class SymbolAPITestCase(TestBase):
|
|
|
|
def setUp(self):
|
|
|
|
# Call super's setUp().
|
|
|
|
TestBase.setUp(self)
|
|
|
|
# Find the line number to of function 'c'.
|
|
|
|
self.line1 = line_number(
|
|
|
|
"main.c", "// Find the line number for breakpoint 1 here."
|
|
|
|
)
|
|
|
|
self.line2 = line_number(
|
|
|
|
"main.c", "// Find the line number for breakpoint 2 here."
|
|
|
|
)
|
|
|
|
|
2023-06-16 14:48:37 -07:00
|
|
|
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
|
2015-09-30 10:12:40 +00:00
|
|
|
def test(self):
|
2011-04-01 00:35:55 +00:00
|
|
|
"""Exercise some SBSymbol and SBAddress APIs."""
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2018-01-19 23:24:35 +00:00
|
|
|
exe = self.getBuildArtifact("a.out")
|
2011-04-01 00:35:55 +00:00
|
|
|
|
|
|
|
# Create a target by the debugger.
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
2011-05-24 18:22:45 +00:00
|
|
|
self.assertTrue(target, VALID_TARGET)
|
2011-04-01 00:35:55 +00:00
|
|
|
|
|
|
|
# Now create the two breakpoints inside function 'a'.
|
|
|
|
breakpoint1 = target.BreakpointCreateByLocation("main.c", self.line1)
|
|
|
|
breakpoint2 = target.BreakpointCreateByLocation("main.c", self.line2)
|
2020-05-25 10:59:39 -07:00
|
|
|
self.trace("breakpoint1:", breakpoint1)
|
|
|
|
self.trace("breakpoint2:", breakpoint2)
|
2011-05-24 18:22:45 +00:00
|
|
|
self.assertTrue(
|
2011-04-01 00:35:55 +00:00
|
|
|
breakpoint1 and breakpoint1.GetNumLocations() == 1, VALID_BREAKPOINT
|
|
|
|
)
|
2011-05-24 18:22:45 +00:00
|
|
|
self.assertTrue(
|
2011-04-01 00:35:55 +00:00
|
|
|
breakpoint2 and breakpoint2.GetNumLocations() == 1, VALID_BREAKPOINT
|
|
|
|
)
|
|
|
|
|
|
|
|
# Now launch the process, and do not stop at entry point.
|
2013-12-13 19:18:59 +00:00
|
|
|
process = target.LaunchSimple(None, None, self.get_process_working_directory())
|
2011-06-15 22:14:12 +00:00
|
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
2011-04-01 00:35:55 +00:00
|
|
|
|
|
|
|
# Frame #0 should be on self.line1.
|
2022-06-08 22:22:27 -07:00
|
|
|
self.assertState(process.GetState(), lldb.eStateStopped)
|
2011-06-15 22:14:12 +00:00
|
|
|
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
|
2013-03-19 17:59:30 +00:00
|
|
|
self.assertTrue(
|
|
|
|
thread.IsValid(),
|
|
|
|
"There should be a thread stopped due to breakpoint condition",
|
|
|
|
)
|
2011-04-01 00:35:55 +00:00
|
|
|
frame0 = thread.GetFrameAtIndex(0)
|
|
|
|
symbol_line1 = frame0.GetSymbol()
|
|
|
|
# We should have a symbol type of code.
|
2021-02-01 12:01:32 -08:00
|
|
|
self.assertEqual(symbol_line1.GetType(), lldb.eSymbolTypeCode)
|
2011-04-01 00:35:55 +00:00
|
|
|
addr_line1 = symbol_line1.GetStartAddress()
|
|
|
|
# And a section type of code, too.
|
2022-11-11 16:19:03 -08:00
|
|
|
self.assertEqual(
|
|
|
|
addr_line1.GetSection().GetSectionType(), lldb.eSectionTypeCode
|
|
|
|
)
|
2011-04-01 00:35:55 +00:00
|
|
|
|
|
|
|
# Continue the inferior, the breakpoint 2 should be hit.
|
2011-06-15 22:14:12 +00:00
|
|
|
process.Continue()
|
2022-06-08 22:22:27 -07:00
|
|
|
self.assertState(process.GetState(), lldb.eStateStopped)
|
2011-06-15 22:14:12 +00:00
|
|
|
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
|
2013-03-19 17:59:30 +00:00
|
|
|
self.assertTrue(
|
|
|
|
thread.IsValid(),
|
|
|
|
"There should be a thread stopped due to breakpoint condition",
|
|
|
|
)
|
2011-04-01 00:35:55 +00:00
|
|
|
frame0 = thread.GetFrameAtIndex(0)
|
|
|
|
symbol_line2 = frame0.GetSymbol()
|
|
|
|
# We should have a symbol type of code.
|
2021-02-01 12:01:32 -08:00
|
|
|
self.assertEqual(symbol_line2.GetType(), lldb.eSymbolTypeCode)
|
2011-04-01 00:35:55 +00:00
|
|
|
addr_line2 = symbol_line2.GetStartAddress()
|
|
|
|
# And a section type of code, too.
|
2022-11-11 16:19:03 -08:00
|
|
|
self.assertEqual(
|
|
|
|
addr_line2.GetSection().GetSectionType(), lldb.eSectionTypeCode
|
|
|
|
)
|
2011-04-01 00:35:55 +00:00
|
|
|
|
|
|
|
# Now verify that both addresses point to the same module.
|
2011-04-19 19:44:26 +00:00
|
|
|
if self.TraceOn():
|
2015-10-23 17:04:29 +00:00
|
|
|
print("UUID:", addr_line1.GetModule().GetUUIDString())
|
2022-11-11 16:19:03 -08:00
|
|
|
self.assertEqual(
|
|
|
|
addr_line1.GetModule().GetUUIDString(),
|
|
|
|
addr_line2.GetModule().GetUUIDString(),
|
|
|
|
)
|