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 # Failing for unknown reasons on Linux, see 23 # https://bugs.llvm.org/show_bug.cgi?id=49656. 24 @skipUnlessDarwin 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 ext = '.so' 32 if self.platformIsDarwin(): 33 ext = '.dylib' 34 35 def make_lib_path(name): 36 libpath = os.path.join(wd, name + ext) 37 self.assertTrue(os.path.exists(libpath)) 38 return libpath 39 40 libt1 = make_lib_path('libt1') 41 libt2_0 = make_lib_path('libt2_0') 42 libt2_1 = make_lib_path('libt2_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 break 48 (target, process, thread, _) = lldbutil.run_to_source_breakpoint(self, 49 "break here", 50 lldb.SBFileSpec("main.cpp")) 51 52 # Load libt1; should fail unless we use RTLD_LAZY 53 error = lldb.SBError() 54 lib_spec = lldb.SBFileSpec('libt1' + ext) 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