64 lines · python
1"""Test binaries with delay-init dependencies."""2 3import subprocess4import lldb5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7from lldbsuite.test import lldbutil8 9 10class TestDelayInitDependencies(TestBase):11 NO_DEBUG_INFO_TESTCASE = True12 13 @skipUnlessDarwin14 @skipIf(macos_version=["<", "15.0"])15 def test_delay_init_dependency(self):16 TestBase.setUp(self)17 out = subprocess.run(18 ["xcrun", "ld", "-delay_library"],19 universal_newlines=True,20 stdout=subprocess.PIPE,21 stderr=subprocess.PIPE,22 )23 if "delay_library missing" not in out.stderr:24 self.skipTest(25 "Skipped because the linker doesn't know about -delay_library"26 )27 self.build()28 main_source = "main.c"29 exe = self.getBuildArtifact("a.out")30 lib = self.getBuildArtifact("libfoo.dylib")31 32 target = self.dbg.CreateTarget(exe)33 self.assertTrue(target, VALID_TARGET)34 35 # libfoo.dylib should not be in the target pre-execution36 for m in target.modules:37 self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib")38 39 # This run without arguments will not load libfoo.dylib40 li = lldb.SBLaunchInfo([])41 li.SetWorkingDirectory(self.getBuildDir())42 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(43 self, "// break here", lldb.SBFileSpec("main.c"), li44 )45 for m in target.modules:46 self.assertNotEqual(m.GetFileSpec().GetFilename(), "libfoo.dylib")47 48 process.Kill()49 self.dbg.DeleteTarget(target)50 51 # This run with one argument will load libfoo.dylib52 li = lldb.SBLaunchInfo([])53 li.SetWorkingDirectory(self.getBuildDir())54 li.SetArguments(["one-argument"], True)55 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(56 self, "// break here", lldb.SBFileSpec("main.c"), li57 )58 59 found_libfoo = False60 for m in target.modules:61 if m.GetFileSpec().GetFilename() == "libfoo.dylib":62 found_libfoo = True63 self.assertTrue(found_libfoo)64