66 lines · python
1"""2Test that SBProcess.LoadImageUsingPaths uses RTLD_LAZY3"""4 5 6import os7import shutil8import lldb9from lldbsuite.test.decorators import *10from lldbsuite.test.lldbtest import *11from lldbsuite.test import lldbutil12 13 14class LoadUsingLazyBind(TestBase):15 NO_DEBUG_INFO_TESTCASE = True16 17 @skipIfRemote18 @skipIfWindows # The Windows platform doesn't implement DoLoadImage.19 @skipIf(oslist=["linux"], archs=["arm$"]) # Fails on arm/linux20 # Failing for unknown reasons on Linux, see21 # https://bugs.llvm.org/show_bug.cgi?id=49656.22 def test_load_using_lazy_bind(self):23 """Test that we load using RTLD_LAZY"""24 25 self.build()26 wd = os.path.realpath(self.getBuildDir())27 28 def make_lib_name(name):29 return (30 self.platformContext.shlib_prefix31 + name32 + "."33 + self.platformContext.shlib_extension34 )35 36 def make_lib_path(name):37 libpath = os.path.join(wd, make_lib_name(name))38 self.assertTrue(os.path.exists(libpath))39 return libpath40 41 libt2_0 = make_lib_path("t2_0")42 libt2_1 = make_lib_path("t2_1")43 44 # Overwrite t2_0 with t2_1 to delete the definition of `use`.45 shutil.copy(libt2_1, libt2_0)46 47 # Launch a process and break48 (target, process, thread, _) = lldbutil.run_to_source_breakpoint(49 self, "break here", lldb.SBFileSpec("main.cpp"), extra_images=["t1"]50 )51 52 # Load libt1; should fail unless we use RTLD_LAZY53 error = lldb.SBError()54 lib_spec = lldb.SBFileSpec(make_lib_name("t1"))55 paths = lldb.SBStringList()56 paths.AppendString(wd)57 out_spec = lldb.SBFileSpec()58 token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)59 self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")60 61 # Calling `f1()` should return 5.62 frame = thread.GetFrameAtIndex(0)63 val = frame.EvaluateExpression("f1()")64 self.assertTrue(val.IsValid())65 self.assertEqual(val.GetValueAsSigned(-1), 5)66