1*9c95617cSMichael Buch""" 24bd2bfb6SVedant KumarTest that SBProcess.LoadImageUsingPaths uses RTLD_LAZY 34bd2bfb6SVedant Kumar""" 44bd2bfb6SVedant Kumar 54bd2bfb6SVedant Kumar 64bd2bfb6SVedant Kumarimport os 74bd2bfb6SVedant Kumarimport shutil 84bd2bfb6SVedant Kumarimport lldb 94bd2bfb6SVedant Kumarfrom lldbsuite.test.decorators import * 104bd2bfb6SVedant Kumarfrom lldbsuite.test.lldbtest import * 114bd2bfb6SVedant Kumarfrom lldbsuite.test import lldbutil 124bd2bfb6SVedant Kumar 134bd2bfb6SVedant Kumar 144bd2bfb6SVedant Kumarclass LoadUsingLazyBind(TestBase): 154bd2bfb6SVedant Kumar NO_DEBUG_INFO_TESTCASE = True 164bd2bfb6SVedant Kumar 174bd2bfb6SVedant Kumar @skipIfRemote 184bd2bfb6SVedant Kumar @skipIfWindows # The Windows platform doesn't implement DoLoadImage. 1945597316SMuhammad Omair Javaid @skipIf(oslist=["linux"], archs=["arm"]) # Fails on arm/linux 204bd2bfb6SVedant Kumar # Failing for unknown reasons on Linux, see 214bd2bfb6SVedant Kumar # https://bugs.llvm.org/show_bug.cgi?id=49656. 224bd2bfb6SVedant Kumar def test_load_using_lazy_bind(self): 234bd2bfb6SVedant Kumar """Test that we load using RTLD_LAZY""" 244bd2bfb6SVedant Kumar 254bd2bfb6SVedant Kumar self.build() 264bd2bfb6SVedant Kumar wd = os.path.realpath(self.getBuildDir()) 274bd2bfb6SVedant Kumar 28bad5ee15SPavel Labath def make_lib_name(name): 292238dcc3SJonas Devlieghere return ( 302238dcc3SJonas Devlieghere self.platformContext.shlib_prefix 312238dcc3SJonas Devlieghere + name 322238dcc3SJonas Devlieghere + "." 332238dcc3SJonas Devlieghere + self.platformContext.shlib_extension 342238dcc3SJonas Devlieghere ) 354bd2bfb6SVedant Kumar 364bd2bfb6SVedant Kumar def make_lib_path(name): 37bad5ee15SPavel Labath libpath = os.path.join(wd, make_lib_name(name)) 384bd2bfb6SVedant Kumar self.assertTrue(os.path.exists(libpath)) 394bd2bfb6SVedant Kumar return libpath 404bd2bfb6SVedant Kumar 412238dcc3SJonas Devlieghere libt2_0 = make_lib_path("t2_0") 422238dcc3SJonas Devlieghere libt2_1 = make_lib_path("t2_1") 434bd2bfb6SVedant Kumar 444bd2bfb6SVedant Kumar # Overwrite t2_0 with t2_1 to delete the definition of `use`. 454bd2bfb6SVedant Kumar shutil.copy(libt2_1, libt2_0) 464bd2bfb6SVedant Kumar 474bd2bfb6SVedant Kumar # Launch a process and break 482238dcc3SJonas Devlieghere (target, process, thread, _) = lldbutil.run_to_source_breakpoint( 492238dcc3SJonas Devlieghere self, "break here", lldb.SBFileSpec("main.cpp"), extra_images=["t1"] 502238dcc3SJonas Devlieghere ) 514bd2bfb6SVedant Kumar 524bd2bfb6SVedant Kumar # Load libt1; should fail unless we use RTLD_LAZY 534bd2bfb6SVedant Kumar error = lldb.SBError() 542238dcc3SJonas Devlieghere lib_spec = lldb.SBFileSpec(make_lib_name("t1")) 554bd2bfb6SVedant Kumar paths = lldb.SBStringList() 564bd2bfb6SVedant Kumar paths.AppendString(wd) 574bd2bfb6SVedant Kumar out_spec = lldb.SBFileSpec() 584bd2bfb6SVedant Kumar token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error) 594bd2bfb6SVedant Kumar self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token") 604bd2bfb6SVedant Kumar 614bd2bfb6SVedant Kumar # Calling `f1()` should return 5. 624bd2bfb6SVedant Kumar frame = thread.GetFrameAtIndex(0) 634bd2bfb6SVedant Kumar val = frame.EvaluateExpression("f1()") 644bd2bfb6SVedant Kumar self.assertTrue(val.IsValid()) 6580fcecb1SJonas Devlieghere self.assertEqual(val.GetValueAsSigned(-1), 5) 66