[Lldb-commits] [PATCH] D77529: Prefer executable files from sysroot over files from local filesystem
Pavel Labath via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 20 07:32:52 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6afa5c407c13: [lldb] Prefer executable files from sysroot over files from local filesystem (authored by yuri, committed by labath).
Changed prior to commit:
https://reviews.llvm.org/D77529?vs=258034&id=258735#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77529/new/
https://reviews.llvm.org/D77529
Files:
lldb/source/Target/RemoteAwarePlatform.cpp
lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
lldb/test/API/functionalities/postmortem/elf-core/linux-x86_64.core
Index: lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
===================================================================
--- lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -210,6 +210,44 @@
self.dbg.DeleteTarget(target)
@skipIf(triple='^mips')
+ @skipIfLLVMTargetMissing("X86")
+ @skipIfWindows
+ def test_x86_64_sysroot(self):
+ """Test that sysroot has more priority then local filesystem."""
+
+ # Copy wrong executable to the location outside of sysroot
+ exe_outside = os.path.join(self.getBuildDir(), "bin", "a.out")
+ lldbutil.mkdir_p(os.path.dirname(exe_outside))
+ shutil.copyfile("altmain.out", exe_outside)
+
+ # Copy correct executable to the location inside sysroot
+ tmp_sysroot = os.path.join(self.getBuildDir(), "mock_sysroot")
+ exe_inside = os.path.join(tmp_sysroot, os.path.relpath(exe_outside, "/"))
+ lldbutil.mkdir_p(os.path.dirname(exe_inside))
+ shutil.copyfile("linux-x86_64.out", exe_inside)
+
+ # Prepare patched core file
+ core_file = os.path.join(self.getBuildDir(), "patched.core")
+ with open("linux-x86_64.core", "rb") as f:
+ core = f.read()
+ core = replace_path(core, "/test" * 817 + "/a.out", exe_outside)
+ with open(core_file, "wb") as f:
+ f.write(core)
+
+ # Set sysroot and load core
+ self.runCmd("platform select remote-linux --sysroot '%s'" % tmp_sysroot)
+ target = self.dbg.CreateTarget(None)
+ self.assertTrue(target, VALID_TARGET)
+ process = target.LoadCore(core_file)
+
+ # Check that we found executable from the sysroot
+ mod_path = str(target.GetModuleAtIndex(0).GetFileSpec())
+ self.assertEqual(mod_path, exe_inside)
+ self.check_all(process, self._x86_64_pid, self._x86_64_regions, "a.out")
+
+ self.dbg.DeleteTarget(target)
+
+ @skipIf(triple='^mips')
@skipIfLLVMTargetMissing("ARM")
def test_arm_core(self):
# check 32 bit ARM core file
@@ -369,3 +407,9 @@
self.check_all(process, pid, region_count, thread_name)
self.dbg.DeleteTarget(target)
+
+def replace_path(binary, replace_from, replace_to):
+ src = replace_from.encode()
+ dst = replace_to.encode()
+ dst += b"\0" * (len(src) - len(dst))
+ return binary.replace(src, dst)
Index: lldb/source/Target/RemoteAwarePlatform.cpp
===================================================================
--- lldb/source/Target/RemoteAwarePlatform.cpp
+++ lldb/source/Target/RemoteAwarePlatform.cpp
@@ -21,7 +21,7 @@
return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,
module_spec);
- return Platform::GetModuleSpec(module_file_spec, arch, module_spec);
+ return false;
}
Status RemoteAwarePlatform::RunShellCommand(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77529.258735.patch
Type: text/x-patch
Size: 2985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200420/a15f5ca8/attachment.bin>
More information about the lldb-commits
mailing list