1 """Test stepping and setting breakpoints in indirect and re-exported symbols."""
5 from lldbsuite
.test
.decorators
import *
6 from lldbsuite
.test
.lldbtest
import *
7 from lldbsuite
.test
import lldbutil
10 class TestIndirectFunctions(TestBase
):
12 # Call super's setUp().
14 # Find the line numbers that we will step to in main:
15 self
.main_source
= "main.c"
18 @add_test_categories(["pyapi"])
19 def test_with_python_api(self
):
20 """Test stepping and setting breakpoints in indirect and re-exported symbols."""
22 exe
= self
.getBuildArtifact("a.out")
24 target
= self
.dbg
.CreateTarget(exe
)
25 self
.assertTrue(target
, VALID_TARGET
)
27 lib1
= self
.getBuildArtifact("libindirect.dylib")
28 lib2
= self
.getBuildArtifact("libreexport.dylib")
29 self
.registerSharedLibrariesWithTarget(target
, [lib1
, lib2
])
31 self
.main_source_spec
= lldb
.SBFileSpec(self
.main_source
)
33 break1
= target
.BreakpointCreateBySourceRegex(
34 "Set breakpoint here to step in indirect.", self
.main_source_spec
36 self
.assertTrue(break1
, VALID_BREAKPOINT
)
38 break2
= target
.BreakpointCreateBySourceRegex(
39 "Set breakpoint here to step in reexported.", self
.main_source_spec
41 self
.assertTrue(break2
, VALID_BREAKPOINT
)
43 # Now launch the process, and do not stop at entry point.
44 process
= target
.LaunchSimple(None, None, self
.get_process_working_directory())
46 self
.assertTrue(process
, PROCESS_IS_VALID
)
48 # The stop reason of the thread should be breakpoint.
49 threads
= lldbutil
.get_threads_stopped_at_breakpoint(process
, break1
)
51 self
.fail("Failed to stop at breakpoint 1.")
55 # Now do a step-into, and we should end up in the hidden target of this
58 curr_function
= thread
.GetFrameAtIndex(0).GetFunctionName()
61 "call_through_indirect_hidden",
62 "Stepped into indirect symbols.",
65 # Now set a breakpoint using the indirect symbol name, and make sure we
67 break_indirect
= target
.BreakpointCreateByName("call_through_indirect")
68 self
.assertTrue(break_indirect
, VALID_BREAKPOINT
)
70 # Now continue should take us to the second call through the indirect
73 threads
= lldbutil
.continue_to_breakpoint(process
, break_indirect
)
74 self
.assertEqual(len(threads
), 1, "Stopped at breakpoint in indirect function.")
75 curr_function
= thread
.GetFrameAtIndex(0).GetFunctionName()
78 "call_through_indirect_hidden",
79 "Stepped into indirect symbols.",
82 # Delete this breakpoint so it won't get in the way:
83 target
.BreakpointDelete(break_indirect
.GetID())
85 # Now continue to the site of the first re-exported function call in
87 threads
= lldbutil
.continue_to_breakpoint(process
, break2
)
89 # This is stepping Into through a re-exported symbol to an indirect
92 curr_function
= thread
.GetFrameAtIndex(0).GetFunctionName()
95 "call_through_indirect_hidden",
96 "Stepped into indirect symbols.",
99 # And the last bit is to set a breakpoint on the re-exported symbol and
100 # make sure we are again in out target function.
101 break_reexported
= target
.BreakpointCreateByName("reexport_to_indirect")
102 self
.assertEqual(break_reexported
.GetNumLocations(), 1, VALID_BREAKPOINT
)
104 # Now continue should take us to the second call through the indirect
107 threads
= lldbutil
.continue_to_breakpoint(process
, break_reexported
)
109 len(threads
), 1, "Stopped at breakpoint in reexported function target."
111 curr_function
= thread
.GetFrameAtIndex(0).GetFunctionName()
114 "call_through_indirect_hidden",
115 "Stepped into indirect symbols.",