1# This test checks that we make the executable the first 2# element in the image list. 3 4import lldb 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8 9 10class 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, 48 "break after function call", 49 lldb.SBFileSpec("main.cpp"), 50 extra_images=["bar"], 51 ) 52 53 first_module = target.GetModuleAtIndex(0) 54 self.assertTrue(first_module.IsValid(), "We have at least one module") 55 executable_module = target.executable 56 self.assertEqual(first_module.file, executable_module, "They are the same") 57