73 lines · python
1"""2Test that LLDB can launch a linux executable and then execs into the dynamic3loader into this program again.4"""5 6import lldb7import os8 9from lldbsuite.test.decorators import *10from lldbsuite.test.lldbtest import *11from lldbsuite.test import lldbutil12 13 14class TestLinux64ExecViaDynamicLoader(TestBase):15 NO_DEBUG_INFO_TESTCASE = True16 17 @skipIfXmlSupportMissing18 @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()22 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()27 28 def _test(self):29 self.build()30 31 # Extracts path of the interpreter.32 exe = self.getBuildArtifact("a.out")33 34 spec = lldb.SBModuleSpec()35 spec.SetFileSpec(lldb.SBFileSpec(exe))36 interp_section = lldb.SBModule(spec).FindSection(".interp")37 if not interp_section:38 return39 section_data = interp_section.GetSectionData()40 error = lldb.SBError()41 dyld_path = section_data.GetString(error, 0)42 if error.Fail():43 return44 45 target = self.dbg.CreateTarget(exe)46 self.assertTrue(target, VALID_TARGET)47 48 # Set a breakpoint in the main function that will get hit after the49 # program exec's via the dynamic loader. The breakpoint will only get50 # hit if we can successfully read the shared library lists in the51 # DynamicLoaderPOSIXDYLD.cpp when we exec into the dynamic loader.52 breakpoint_main = target.BreakpointCreateBySourceRegex(53 "// Break here", lldb.SBFileSpec("main.cpp")54 )55 # Setup our launch info to supply the dynamic loader path to the56 # program so it gets two args:57 # - path to a.out58 # - path to dynamic loader59 launch_info = lldb.SBLaunchInfo([dyld_path])60 error = lldb.SBError()61 process = target.Launch(launch_info, error)62 self.assertSuccess(error)63 64 threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonExec)65 self.assertEqual(len(threads), 1, "We got a thread stopped for exec.")66 67 process.Continue()68 69 # Stopped on main here.70 self.assertState(process.GetState(), lldb.eStateStopped)71 thread = process.GetSelectedThread()72 self.assertIn("main", thread.GetFrameAtIndex(0).GetDisplayFunctionName())73