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