1""" 2Test that SBProcess.LoadImageUsingPaths uses RTLD_LAZY 3""" 4 5 6 7import os 8import shutil 9import lldb 10from lldbsuite.test.decorators import * 11from lldbsuite.test.lldbtest import * 12from lldbsuite.test import lldbutil 13 14 15class LoadUsingLazyBind(TestBase): 16 17 mydir = TestBase.compute_mydir(__file__) 18 NO_DEBUG_INFO_TESTCASE = True 19 20 @skipIfRemote 21 @skipIfWindows # The Windows platform doesn't implement DoLoadImage. 22 @skipIf(oslist=["linux"], archs=["arm"]) # Fails on arm/linux 23 # Failing for unknown reasons on Linux, see 24 # https://bugs.llvm.org/show_bug.cgi?id=49656. 25 def test_load_using_lazy_bind(self): 26 """Test that we load using RTLD_LAZY""" 27 28 self.build() 29 wd = os.path.realpath(self.getBuildDir()) 30 31 def make_lib_name(name): 32 return (self.platformContext.shlib_prefix + name + "." + 33 self.platformContext.shlib_extension) 34 35 def make_lib_path(name): 36 libpath = os.path.join(wd, make_lib_name(name)) 37 self.assertTrue(os.path.exists(libpath)) 38 return libpath 39 40 libt2_0 = make_lib_path('t2_0') 41 libt2_1 = make_lib_path('t2_1') 42 43 # Overwrite t2_0 with t2_1 to delete the definition of `use`. 44 shutil.copy(libt2_1, libt2_0) 45 46 # Launch a process and break 47 (target, process, thread, _) = lldbutil.run_to_source_breakpoint(self, 48 "break here", 49 lldb.SBFileSpec("main.cpp"), 50 extra_images=["t1"]) 51 52 # Load libt1; should fail unless we use RTLD_LAZY 53 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.assertEquals(val.GetValueAsSigned(-1), 5) 66