Skip to content

Commit 5f4c850

Browse files
committed
[lldb/test] Do a better job at setting (DY)LD_LIBRARY_PATH
Summary: registerSharedLibrariesWithTarget was setting the library path environment variable to the process build directory, but the function is also accepting libraries in other directories (in which case they won't be found automatically). This patch makes the function set the path variable correctly for these libraries too. This enables us to remove the code for setting the path variable in TestWeakSymbols.py, which was working only accidentally -- it was relying on the fact that launch_info.SetEnvironmentEntries(..., append=True) would not overwrite the path variable it has set, but that is going to change with D83306. Reviewers: davide, jingham Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D83552
1 parent e0a372f commit 5f4c850

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,8 +1881,7 @@ def registerSharedLibrariesWithTarget(self, target, shlibs):
18811881
shlib_prefix = self.platformContext.shlib_prefix
18821882
shlib_extension = '.' + self.platformContext.shlib_extension
18831883

1884-
working_dir = self.get_process_working_directory()
1885-
environment = ['%s=%s' % (shlib_environment_var, working_dir)]
1884+
dirs = []
18861885
# Add any shared libraries to our target if remote so they get
18871886
# uploaded into the working directory on the remote side
18881887
for name in shlibs:
@@ -1905,6 +1904,7 @@ def registerSharedLibrariesWithTarget(self, target, shlibs):
19051904
# Make sure we found the local shared library in the above code
19061905
self.assertTrue(os.path.exists(local_shlib_path))
19071906

1907+
19081908
# Add the shared library to our target
19091909
shlib_module = target.AddModule(local_shlib_path, None, None, None)
19101910
if lldb.remote_platform:
@@ -1914,8 +1914,15 @@ def registerSharedLibrariesWithTarget(self, target, shlibs):
19141914
os.path.basename(local_shlib_path))
19151915
shlib_module.SetRemoteInstallFileSpec(
19161916
lldb.SBFileSpec(remote_shlib_path, False))
1917+
dir_to_add = self.get_process_working_directory()
1918+
else:
1919+
dir_to_add = os.path.dirname(local_shlib_path)
1920+
1921+
if dir_to_add not in dirs:
1922+
dirs.append(dir_to_add)
19171923

1918-
return environment
1924+
env_value = self.platformContext.shlib_path_separator.join(dirs)
1925+
return ['%s=%s' % (shlib_environment_var, env_value)]
19191926

19201927
def registerSanitizerLibrariesWithTarget(self, target):
19211928
runtimes = []

lldb/test/API/commands/expression/weak_symbols/TestWeakSymbols.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ def do_test(self):
4848

4949
launch_info = lldb.SBLaunchInfo(None)
5050
launch_info.SetWorkingDirectory(self.getBuildDir())
51-
# We have to point to the hidden directory to pick up the
52-
# version of the dylib without the weak symbols:
53-
env_expr = self.platformContext.shlib_environment_var + "=" + hidden_dir
54-
launch_info.SetEnvironmentEntries([env_expr], True)
5551

5652
(self.target, _, thread, _) = lldbutil.run_to_source_breakpoint(
5753
self, "Set a breakpoint here",

0 commit comments

Comments
 (0)