"""Test stepping and setting breakpoints in indirect and re-exported symbols."""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestIndirectFunctions(TestBase):
def setUp(self):
TestBase.setUp(self)
self.main_source = "main.c"
@skipUnlessDarwin
@add_test_categories(["pyapi"])
@skipIf(bugnumber="rdar://120796553")
def test_with_python_api(self):
"""Test stepping and setting breakpoints in indirect and re-exported symbols."""
self.build()
exe = self.getBuildArtifact("a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
lib1 = self.getBuildArtifact("libindirect.dylib")
lib2 = self.getBuildArtifact("libreexport.dylib")
self.registerSharedLibrariesWithTarget(target, [lib1, lib2])
self.main_source_spec = lldb.SBFileSpec(self.main_source)
break1 = target.BreakpointCreateBySourceRegex(
"Set breakpoint here to step in indirect.", self.main_source_spec
)
self.assertTrue(break1, VALID_BREAKPOINT)
break2 = target.BreakpointCreateBySourceRegex(
"Set breakpoint here to step in reexported.", self.main_source_spec
)
self.assertTrue(break2, VALID_BREAKPOINT)
process = target.LaunchSimple(None, None, self.get_process_working_directory())
self.assertTrue(process, PROCESS_IS_VALID)
threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1)
if len(threads) != 1:
self.fail("Failed to stop at breakpoint 1.")
thread = threads[0]
thread.StepInto()
curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
self.assertEqual(
curr_function,
"call_through_indirect_hidden",
"Stepped into indirect symbols.",
)
break_indirect = target.BreakpointCreateByName("call_through_indirect")
self.assertTrue(break_indirect, VALID_BREAKPOINT)
threads = lldbutil.continue_to_breakpoint(process, break_indirect)
self.assertEqual(len(threads), 1, "Stopped at breakpoint in indirect function.")
curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
self.assertEqual(
curr_function,
"call_through_indirect_hidden",
"Stepped into indirect symbols.",
)
target.BreakpointDelete(break_indirect.GetID())
threads = lldbutil.continue_to_breakpoint(process, break2)
thread.StepInto()
curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
self.assertEqual(
curr_function,
"call_through_indirect_hidden",
"Stepped into indirect symbols.",
)
break_reexported = target.BreakpointCreateByName("reexport_to_indirect")
self.assertEqual(break_reexported.GetNumLocations(), 1, VALID_BREAKPOINT)
threads = lldbutil.continue_to_breakpoint(process, break_reexported)
self.assertEqual(
len(threads), 1, "Stopped at breakpoint in reexported function target."
)
curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
self.assertEqual(
curr_function,
"call_through_indirect_hidden",
"Stepped into indirect symbols.",
)