116926115SRaphael Isemannimport lldb 216926115SRaphael Isemannfrom lldbsuite.test.decorators import * 316926115SRaphael Isemannfrom lldbsuite.test.lldbtest import * 416926115SRaphael Isemannfrom lldbsuite.test import lldbutil 516926115SRaphael Isemann 616926115SRaphael Isemannclass TestCase(TestBase): 716926115SRaphael Isemann 816926115SRaphael Isemann mydir = TestBase.compute_mydir(__file__) 916926115SRaphael Isemann 1016926115SRaphael Isemann @skipIfRemote 1116926115SRaphael Isemann @skipIfWindows 1216926115SRaphael Isemann # glibc's dlopen doesn't support opening executables. 1316926115SRaphael Isemann # https://sourceware.org/bugzilla/show_bug.cgi?id=11754 1416926115SRaphael Isemann @skipIfLinux 15*266c90feSMichał Górny # freebsd's dlopen ditto 1698257c30SMichał Górny @expectedFailureAll(oslist=["freebsd"]) 1716926115SRaphael Isemann @no_debug_info_test 1816926115SRaphael Isemann def test(self): 1916926115SRaphael Isemann self.build() 2016926115SRaphael Isemann # Launch and stop before the dlopen call. 2116926115SRaphael Isemann lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c")) 2216926115SRaphael Isemann 2316926115SRaphael Isemann # Delete the breakpoint we no longer need. 2416926115SRaphael Isemann self.target().DeleteAllBreakpoints() 2516926115SRaphael Isemann 2616926115SRaphael Isemann # Check that the executable is the test binary. 2716926115SRaphael Isemann self.assertEqual(self.target().GetExecutable().GetFilename(), "a.out") 2816926115SRaphael Isemann 2916926115SRaphael Isemann # Continue so that dlopen is called. 3016926115SRaphael Isemann breakpoint = self.target().BreakpointCreateBySourceRegex( 3116926115SRaphael Isemann "// break after dlopen", lldb.SBFileSpec("main.c")) 3216926115SRaphael Isemann self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0) 3316926115SRaphael Isemann stopped_threads = lldbutil.continue_to_breakpoint(self.process(), breakpoint) 3416926115SRaphael Isemann self.assertEqual(len(stopped_threads), 1) 3516926115SRaphael Isemann 3616926115SRaphael Isemann # Check that the executable is still the test binary and not "other". 3716926115SRaphael Isemann self.assertEqual(self.target().GetExecutable().GetFilename(), "a.out") 3816926115SRaphael Isemann 3916926115SRaphael Isemann # Kill the process and run the program again. 4016926115SRaphael Isemann err = self.process().Kill() 4116926115SRaphael Isemann self.assertTrue(err.Success(), str(err)) 4216926115SRaphael Isemann 4316926115SRaphael Isemann # Test that we hit the breakpoint after dlopen. 4416926115SRaphael Isemann lldbutil.run_to_breakpoint_do_run(self, self.target(), breakpoint) 45