1import lldb
2from lldbsuite.test.decorators import *
3from lldbsuite.test.lldbtest import *
4from lldbsuite.test import lldbutil
5
6class TestCase(TestBase):
7
8    mydir = TestBase.compute_mydir(__file__)
9
10    @skipIfRemote
11    @skipIfWindows
12    # glibc's dlopen doesn't support opening executables.
13    # https://sourceware.org/bugzilla/show_bug.cgi?id=11754
14    @skipIfLinux
15    # freebsd's dlopen ditto
16    @expectedFailureAll(oslist=["freebsd"])
17    @no_debug_info_test
18    def test(self):
19        self.build()
20        # Launch and stop before the dlopen call.
21        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c"))
22
23        # Delete the breakpoint we no longer need.
24        self.target().DeleteAllBreakpoints()
25
26        # Check that the executable is the test binary.
27        self.assertEqual(self.target().GetExecutable().GetFilename(), "a.out")
28
29        # Continue so that dlopen is called.
30        breakpoint = self.target().BreakpointCreateBySourceRegex(
31            "// break after dlopen", lldb.SBFileSpec("main.c"))
32        self.assertNotEqual(breakpoint.GetNumResolvedLocations(), 0)
33        stopped_threads = lldbutil.continue_to_breakpoint(self.process(), breakpoint)
34        self.assertEqual(len(stopped_threads), 1)
35
36        # Check that the executable is still the test binary and not "other".
37        self.assertEqual(self.target().GetExecutable().GetFilename(), "a.out")
38
39        # Kill the process and run the program again.
40        err = self.process().Kill()
41        self.assertTrue(err.Success(), str(err))
42
43        # Test that we hit the breakpoint after dlopen.
44        lldbutil.run_to_breakpoint_do_run(self, self.target(), breakpoint)
45