1879a47a5SGreg Clayton""" 2879a47a5SGreg ClaytonTest that LLDB can launch a linux executable and then execs into the dynamic 3879a47a5SGreg Claytonloader into this program again. 4879a47a5SGreg Clayton""" 5879a47a5SGreg Clayton 6879a47a5SGreg Claytonimport lldb 7879a47a5SGreg Claytonimport os 8879a47a5SGreg Clayton 9879a47a5SGreg Claytonfrom lldbsuite.test.decorators import * 10879a47a5SGreg Claytonfrom lldbsuite.test.lldbtest import * 11879a47a5SGreg Claytonfrom lldbsuite.test import lldbutil 12879a47a5SGreg Clayton 13*2238dcc3SJonas Devlieghere 14879a47a5SGreg Claytonclass TestLinux64ExecViaDynamicLoader(TestBase): 15cf2c8e41SPavel Labath NO_DEBUG_INFO_TESTCASE = True 16cf2c8e41SPavel Labath 17cf2c8e41SPavel Labath @skipIfXmlSupportMissing 18*2238dcc3SJonas Devlieghere @skipIf(oslist=no_match(["linux"])) 19cf2c8e41SPavel Labath def test_with_svr4(self): 20cf2c8e41SPavel Labath self.runCmd("settings set plugin.process.gdb-remote.use-libraries-svr4 true") 21cf2c8e41SPavel Labath self._test() 22879a47a5SGreg Clayton 23*2238dcc3SJonas Devlieghere @skipIf(oslist=no_match(["linux"])) 24cf2c8e41SPavel Labath def test_without_svr4(self): 25cf2c8e41SPavel Labath self.runCmd("settings set plugin.process.gdb-remote.use-libraries-svr4 false") 26cf2c8e41SPavel Labath self._test() 27cf2c8e41SPavel Labath 28cf2c8e41SPavel Labath def _test(self): 29879a47a5SGreg Clayton self.build() 30879a47a5SGreg Clayton 31879a47a5SGreg Clayton # Extracts path of the interpreter. 32879a47a5SGreg Clayton exe = self.getBuildArtifact("a.out") 33879a47a5SGreg Clayton 34879a47a5SGreg Clayton spec = lldb.SBModuleSpec() 35879a47a5SGreg Clayton spec.SetFileSpec(lldb.SBFileSpec(exe)) 36879a47a5SGreg Clayton interp_section = lldb.SBModule(spec).FindSection(".interp") 37879a47a5SGreg Clayton if not interp_section: 38879a47a5SGreg Clayton return 39879a47a5SGreg Clayton section_data = interp_section.GetSectionData() 40879a47a5SGreg Clayton error = lldb.SBError() 41879a47a5SGreg Clayton dyld_path = section_data.GetString(error, 0) 42879a47a5SGreg Clayton if error.Fail(): 43879a47a5SGreg Clayton return 44879a47a5SGreg Clayton 45879a47a5SGreg Clayton target = self.dbg.CreateTarget(exe) 46879a47a5SGreg Clayton self.assertTrue(target, VALID_TARGET) 47879a47a5SGreg Clayton 48879a47a5SGreg Clayton # Set a breakpoint in the main function that will get hit after the 49879a47a5SGreg Clayton # program exec's via the dynamic loader. The breakpoint will only get 50879a47a5SGreg Clayton # hit if we can successfully read the shared library lists in the 51879a47a5SGreg Clayton # DynamicLoaderPOSIXDYLD.cpp when we exec into the dynamic loader. 52*2238dcc3SJonas Devlieghere breakpoint_main = target.BreakpointCreateBySourceRegex( 53*2238dcc3SJonas Devlieghere "// Break here", lldb.SBFileSpec("main.cpp") 54*2238dcc3SJonas Devlieghere ) 55879a47a5SGreg Clayton # Setup our launch info to supply the dynamic loader path to the 56879a47a5SGreg Clayton # program so it gets two args: 57879a47a5SGreg Clayton # - path to a.out 58879a47a5SGreg Clayton # - path to dynamic loader 59879a47a5SGreg Clayton launch_info = lldb.SBLaunchInfo([dyld_path]) 60879a47a5SGreg Clayton error = lldb.SBError() 61879a47a5SGreg Clayton process = target.Launch(launch_info, error) 62879a47a5SGreg Clayton self.assertSuccess(error) 63879a47a5SGreg Clayton 64879a47a5SGreg Clayton threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonExec) 65879a47a5SGreg Clayton self.assertEqual(len(threads), 1, "We got a thread stopped for exec.") 66879a47a5SGreg Clayton 67*2238dcc3SJonas Devlieghere process.Continue() 68879a47a5SGreg Clayton 69879a47a5SGreg Clayton # Stopped on main here. 7047c4c6a7SDave Lee self.assertState(process.GetState(), lldb.eStateStopped) 71879a47a5SGreg Clayton thread = process.GetSelectedThread() 72879a47a5SGreg Clayton self.assertIn("main", thread.GetFrameAtIndex(0).GetDisplayFunctionName()) 73