[Lldb-commits] [lldb] 6afa5c4 - [lldb] Prefer executable files from sysroot over files from local filesystem

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 20 07:13:00 PDT 2020


Author: Yuri Per
Date: 2020-04-20T16:12:51+02:00
New Revision: 6afa5c407c1330efcadb75b8f85993660bf275a7

URL: https://github.com/llvm/llvm-project/commit/6afa5c407c1330efcadb75b8f85993660bf275a7
DIFF: https://github.com/llvm/llvm-project/commit/6afa5c407c1330efcadb75b8f85993660bf275a7.diff

LOG: [lldb] Prefer executable files from sysroot over files from local filesystem

Summary:
In D49685 sysroot behaviour was partially fixed. But files from local filesystem with same path still has priority over files from sysroot.

This patch fixes it by removing fallback to local filesystem from RemoteAwarePlatform::GetModuleSpec(). It is not actually required because higher level code do such fallback itself. See, for example, resolver in Platform::GetSharedModule().

Reviewers: labath, clayborg, EugeneBi

Reviewed By: labath

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D77529

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/RemoteAwarePlatform.cpp b/lldb/source/Target/RemoteAwarePlatform.cpp
index 86f6b9045f70..d45e8e644a71 100644
--- a/lldb/source/Target/RemoteAwarePlatform.cpp
+++ b/lldb/source/Target/RemoteAwarePlatform.cpp
@@ -21,7 +21,7 @@ bool RemoteAwarePlatform::GetModuleSpec(const FileSpec &module_file_spec,
     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(

diff  --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
index 5a1eab3f9018..435d3358b030 100644
--- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -209,6 +209,44 @@ def test_i386_sysroot(self):
 
         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):
@@ -369,3 +407,9 @@ def do_test(self, filename, pid, region_count, thread_name):
         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)

diff  --git a/lldb/test/API/functionalities/postmortem/elf-core/linux-x86_64.core b/lldb/test/API/functionalities/postmortem/elf-core/linux-x86_64.core
index e2fa69e4558e..2675eadd6a7f 100644
Binary files a/lldb/test/API/functionalities/postmortem/elf-core/linux-x86_64.core and b/lldb/test/API/functionalities/postmortem/elf-core/linux-x86_64.core 
diff er


        


More information about the lldb-commits mailing list