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