Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / functionalities / dyld-exec-linux / TestDyldExecLinux.py
blob714d2f7c95076e2760b538fed374ea1c62f24a14
1 """
2 Test that LLDB can launch a linux executable and then execs into the dynamic
3 loader into this program again.
4 """
6 import lldb
7 import os
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class TestLinux64ExecViaDynamicLoader(TestBase):
15 NO_DEBUG_INFO_TESTCASE = True
17 @skipIfXmlSupportMissing
18 @skipIf(oslist=no_match(["linux"]))
19 def test_with_svr4(self):
20 self.runCmd("settings set plugin.process.gdb-remote.use-libraries-svr4 true")
21 self._test()
23 @skipIf(oslist=no_match(["linux"]))
24 def test_without_svr4(self):
25 self.runCmd("settings set plugin.process.gdb-remote.use-libraries-svr4 false")
26 self._test()
28 def _test(self):
29 self.build()
31 # Extracts path of the interpreter.
32 exe = self.getBuildArtifact("a.out")
34 spec = lldb.SBModuleSpec()
35 spec.SetFileSpec(lldb.SBFileSpec(exe))
36 interp_section = lldb.SBModule(spec).FindSection(".interp")
37 if not interp_section:
38 return
39 section_data = interp_section.GetSectionData()
40 error = lldb.SBError()
41 dyld_path = section_data.GetString(error, 0)
42 if error.Fail():
43 return
45 target = self.dbg.CreateTarget(exe)
46 self.assertTrue(target, VALID_TARGET)
48 # Set a breakpoint in the main function that will get hit after the
49 # program exec's via the dynamic loader. The breakpoint will only get
50 # hit if we can successfully read the shared library lists in the
51 # DynamicLoaderPOSIXDYLD.cpp when we exec into the dynamic loader.
52 breakpoint_main = target.BreakpointCreateBySourceRegex(
53 "// Break here", lldb.SBFileSpec("main.cpp")
55 # Setup our launch info to supply the dynamic loader path to the
56 # program so it gets two args:
57 # - path to a.out
58 # - path to dynamic loader
59 launch_info = lldb.SBLaunchInfo([dyld_path])
60 error = lldb.SBError()
61 process = target.Launch(launch_info, error)
62 self.assertSuccess(error)
64 threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonExec)
65 self.assertEqual(len(threads), 1, "We got a thread stopped for exec.")
67 process.Continue()
69 # Stopped on main here.
70 self.assertState(process.GetState(), lldb.eStateStopped)
71 thread = process.GetSelectedThread()
72 self.assertIn("main", thread.GetFrameAtIndex(0).GetDisplayFunctionName())