Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / macosx / indirect_symbol / TestIndirectSymbols.py
blobfbe6db9f892d55517183cff4da9dd45c297bbb53
1 """Test stepping and setting breakpoints in indirect and re-exported symbols."""
4 import lldb
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
10 class TestIndirectFunctions(TestBase):
11 def setUp(self):
12 # Call super's setUp().
13 TestBase.setUp(self)
14 # Find the line numbers that we will step to in main:
15 self.main_source = "main.c"
17 @skipUnlessDarwin
18 @add_test_categories(["pyapi"])
19 def test_with_python_api(self):
20 """Test stepping and setting breakpoints in indirect and re-exported symbols."""
21 self.build()
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)
50 if len(threads) != 1:
51 self.fail("Failed to stop at breakpoint 1.")
53 thread = threads[0]
55 # Now do a step-into, and we should end up in the hidden target of this
56 # indirect function.
57 thread.StepInto()
58 curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
59 self.assertEqual(
60 curr_function,
61 "call_through_indirect_hidden",
62 "Stepped into indirect symbols.",
65 # Now set a breakpoint using the indirect symbol name, and make sure we
66 # get to that:
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
71 # symbol:
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()
76 self.assertEqual(
77 curr_function,
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
86 # main:
87 threads = lldbutil.continue_to_breakpoint(process, break2)
89 # This is stepping Into through a re-exported symbol to an indirect
90 # symbol:
91 thread.StepInto()
92 curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
93 self.assertEqual(
94 curr_function,
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
105 # symbol:
107 threads = lldbutil.continue_to_breakpoint(process, break_reexported)
108 self.assertEqual(
109 len(threads), 1, "Stopped at breakpoint in reexported function target."
111 curr_function = thread.GetFrameAtIndex(0).GetFunctionName()
112 self.assertEqual(
113 curr_function,
114 "call_through_indirect_hidden",
115 "Stepped into indirect symbols.",