xref: /llvm-project/lldb/test/API/functionalities/executable_first/TestExecutableFirst.py (revision 096c530ab3ea5c96526451181117f30db17b4b1d)
1a4cd99eaSjimingham# This test checks that we make the executable the first
2a4cd99eaSjimingham# element in the image list.
3a4cd99eaSjimingham
4a4cd99eaSjiminghamimport lldb
5a4cd99eaSjiminghamfrom lldbsuite.test.decorators import *
6a4cd99eaSjiminghamfrom lldbsuite.test.lldbtest import *
7a4cd99eaSjiminghamfrom lldbsuite.test import lldbutil
8a4cd99eaSjimingham
9a4cd99eaSjimingham
10a4cd99eaSjiminghamclass TestExecutableIsFirst(TestBase):
11a4cd99eaSjimingham    NO_DEBUG_INFO_TESTCASE = True
12a4cd99eaSjimingham
1315311d58SPavel Labath    # ELF does not have a hard distinction between shared libraries and
1415311d58SPavel Labath    # (position-independent) executables
1515311d58SPavel Labath    @skipIf(oslist=no_match(lldbplatformutil.getDarwinOSTriples() + ["windows"]))
16a4cd99eaSjimingham    def test_executable_is_first_before_run(self):
17a4cd99eaSjimingham        self.build()
18a4cd99eaSjimingham
19a4cd99eaSjimingham        ctx = self.platformContext
20a4cd99eaSjimingham        lib_name = ctx.shlib_prefix + "bar." + ctx.shlib_extension
21a4cd99eaSjimingham
22a4cd99eaSjimingham        exe = self.getBuildArtifact("a.out")
23a4cd99eaSjimingham        lib = self.getBuildArtifact(lib_name)
24a4cd99eaSjimingham
25a4cd99eaSjimingham        target = self.dbg.CreateTarget(None)
26a4cd99eaSjimingham        module = target.AddModule(lib, None, None)
27a4cd99eaSjimingham        self.assertTrue(module.IsValid(), "Added the module for the library")
28a4cd99eaSjimingham
29a4cd99eaSjimingham        module = target.AddModule(exe, None, None)
30a4cd99eaSjimingham        self.assertTrue(module.IsValid(), "Added the executable module")
31a4cd99eaSjimingham
32a4cd99eaSjimingham        # This is the executable module so it should be the first in the list:
33a4cd99eaSjimingham        first_module = target.GetModuleAtIndex(0)
34a4cd99eaSjimingham        print("This is the first test, this one succeeds")
35a4cd99eaSjimingham        self.assertEqual(module, first_module, "This executable is the first module")
36a4cd99eaSjimingham
37a4cd99eaSjimingham        # The executable property is an SBFileSpec to the executable.  Make sure
38a4cd99eaSjimingham        # that is also right:
39a4cd99eaSjimingham        executable_module = target.executable
40a4cd99eaSjimingham        self.assertEqual(
41a4cd99eaSjimingham            first_module.file, executable_module, "Python property is also our module"
42a4cd99eaSjimingham        )
43a4cd99eaSjimingham
44a4cd99eaSjimingham    def test_executable_is_first_during_run(self):
45a4cd99eaSjimingham        self.build()
46a4cd99eaSjimingham        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
47*096c530aSJonas Devlieghere            self,
48*096c530aSJonas Devlieghere            "break after function call",
49*096c530aSJonas Devlieghere            lldb.SBFileSpec("main.cpp"),
50*096c530aSJonas Devlieghere            extra_images=["bar"],
51a4cd99eaSjimingham        )
52a4cd99eaSjimingham
53a4cd99eaSjimingham        first_module = target.GetModuleAtIndex(0)
54a4cd99eaSjimingham        self.assertTrue(first_module.IsValid(), "We have at least one module")
55a4cd99eaSjimingham        executable_module = target.executable
56a4cd99eaSjimingham        self.assertEqual(first_module.file, executable_module, "They are the same")
57