xref: /llvm-project/lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py (revision bad5ee15ea2e5a5aaaed9c9a5d9982e23cedba55)
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    def test_load_using_lazy_bind(self):
25        """Test that we load using RTLD_LAZY"""
26
27        self.build()
28        wd = os.path.realpath(self.getBuildDir())
29
30        def make_lib_name(name):
31            return (self.platformContext.shlib_prefix + name + "." +
32                    self.platformContext.shlib_extension)
33
34        def make_lib_path(name):
35            libpath = os.path.join(wd, make_lib_name(name))
36            self.assertTrue(os.path.exists(libpath))
37            return libpath
38
39        libt2_0 = make_lib_path('t2_0')
40        libt2_1 = make_lib_path('t2_1')
41
42        # Overwrite t2_0 with t2_1 to delete the definition of `use`.
43        shutil.copy(libt2_1, libt2_0)
44
45        # Launch a process and break
46        (target, process, thread, _) = lldbutil.run_to_source_breakpoint(self,
47                                                "break here",
48                                                lldb.SBFileSpec("main.cpp"),
49                                                extra_images=["t1"])
50
51        # Load libt1; should fail unless we use RTLD_LAZY
52        error = lldb.SBError()
53        lib_spec = lldb.SBFileSpec(make_lib_name('t1'))
54        paths = lldb.SBStringList()
55        paths.AppendString(wd)
56        out_spec = lldb.SBFileSpec()
57        token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
58        self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
59
60        # Calling `f1()` should return 5.
61        frame = thread.GetFrameAtIndex(0)
62        val = frame.EvaluateExpression("f1()")
63        self.assertTrue(val.IsValid())
64        self.assertEquals(val.GetValueAsSigned(-1), 5)
65