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
15266c90feSMichał Górny    # freebsd's dlopen ditto
1698257c30SMichał Górny    @expectedFailureAll(oslist=["freebsd"])
1799562332SMichał Górny    @expectedFailureNetBSD
1816926115SRaphael Isemann    @no_debug_info_test
1916926115SRaphael Isemann    def test(self):
2016926115SRaphael Isemann        self.build()
2116926115SRaphael Isemann        # Launch and stop before the dlopen call.
2216926115SRaphael Isemann        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c"))
2316926115SRaphael Isemann
2416926115SRaphael Isemann        # Delete the breakpoint we no longer need.
2516926115SRaphael Isemann        self.target().DeleteAllBreakpoints()
2616926115SRaphael Isemann
2716926115SRaphael Isemann        # Check that the executable is the test binary.
2816926115SRaphael Isemann        self.assertEqual(self.target().GetExecutable().GetFilename(), "a.out")
2916926115SRaphael Isemann
3016926115SRaphael Isemann        # Continue so that dlopen is called.
3116926115SRaphael Isemann        breakpoint = self.target().BreakpointCreateBySourceRegex(
3216926115SRaphael Isemann            "// break after dlopen", lldb.SBFileSpec("main.c"))
3316926115SRaphael Isemann        self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0)
3416926115SRaphael Isemann        stopped_threads = lldbutil.continue_to_breakpoint(self.process(), breakpoint)
3516926115SRaphael Isemann        self.assertEqual(len(stopped_threads), 1)
3616926115SRaphael Isemann
3716926115SRaphael Isemann        # Check that the executable is still the test binary and not "other".
3816926115SRaphael Isemann        self.assertEqual(self.target().GetExecutable().GetFilename(), "a.out")
3916926115SRaphael Isemann
4016926115SRaphael Isemann        # Kill the process and run the program again.
4116926115SRaphael Isemann        err = self.process().Kill()
42*779bbbf2SDave Lee        self.assertSuccess(err)
4316926115SRaphael Isemann
4416926115SRaphael Isemann        # Test that we hit the breakpoint after dlopen.
4516926115SRaphael Isemann        lldbutil.run_to_breakpoint_do_run(self, self.target(), breakpoint)
46