In general, it seems like the debugger should allow programs to load & run with libraries as far as possible, instead of defaulting to being super-picky about unavailable symbols. This is critical on macOS/Darwin, as libswiftCore.dylib may 1) export a version symbol using @available markup and then 2) expect that other exported APIs are only dynamically used once the version symbol is checked. We can't open a version of the library built with a bleeding-edge SDK on an older OS without RTLD_LAXY (or pervasive/expensive @available markup added to dyld APIs). This was previously committed as cb8c1ee269da and reverted due to unknown failures on the Linux bots. This version adds additional asserts to check that the shared objects are where we expect them & that calling f1() from libt1 produces the expected value. The Linux failure is tracked by https://bugs.llvm.org/show_bug.cgi?id=49656. See: https://lists.llvm.org/pipermail/lldb-dev/2021-March/016796.html Differential Revision: https://reviews.llvm.org/D98879
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
"""
|
|
Test that SBProcess.LoadImageUsingPaths uses RTLD_LAZY
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
import shutil
|
|
import lldb
|
|
from lldbsuite.test.decorators import *
|
|
from lldbsuite.test.lldbtest import *
|
|
from lldbsuite.test import lldbutil
|
|
|
|
|
|
class LoadUsingLazyBind(TestBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
NO_DEBUG_INFO_TESTCASE = True
|
|
|
|
@skipIfRemote
|
|
@skipIfWindows # The Windows platform doesn't implement DoLoadImage.
|
|
# Failing for unknown reasons on Linux, see
|
|
# https://bugs.llvm.org/show_bug.cgi?id=49656.
|
|
@skipUnlessDarwin
|
|
def test_load_using_lazy_bind(self):
|
|
"""Test that we load using RTLD_LAZY"""
|
|
|
|
self.build()
|
|
wd = os.path.realpath(self.getBuildDir())
|
|
|
|
ext = '.so'
|
|
if self.platformIsDarwin():
|
|
ext = '.dylib'
|
|
|
|
def make_lib_path(name):
|
|
libpath = os.path.join(wd, name + ext)
|
|
self.assertTrue(os.path.exists(libpath))
|
|
return libpath
|
|
|
|
libt1 = make_lib_path('libt1')
|
|
libt2_0 = make_lib_path('libt2_0')
|
|
libt2_1 = make_lib_path('libt2_1')
|
|
|
|
# Overwrite t2_0 with t2_1 to delete the definition of `use`.
|
|
shutil.copy(libt2_1, libt2_0)
|
|
|
|
# Launch a process and break
|
|
(target, process, thread, _) = lldbutil.run_to_source_breakpoint(self,
|
|
"break here",
|
|
lldb.SBFileSpec("main.cpp"))
|
|
|
|
# Load libt1; should fail unless we use RTLD_LAZY
|
|
error = lldb.SBError()
|
|
lib_spec = lldb.SBFileSpec('libt1' + ext)
|
|
paths = lldb.SBStringList()
|
|
paths.AppendString(wd)
|
|
out_spec = lldb.SBFileSpec()
|
|
token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
|
|
self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
|
|
|
|
# Calling `f1()` should return 5.
|
|
frame = thread.GetFrameAtIndex(0)
|
|
val = frame.EvaluateExpression("f1()")
|
|
self.assertTrue(val.IsValid())
|
|
self.assertEquals(val.GetValueAsSigned(-1), 5)
|