[Lldb-commits] [lldb] r340841 - Respect platform sysroot when loading core files

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 28 09:32:46 PDT 2018


Author: labath
Date: Tue Aug 28 09:32:46 2018
New Revision: 340841

URL: http://llvm.org/viewvc/llvm-project?rev=340841&view=rev
Log:
Respect platform sysroot when loading core files

Patch by Eugene Birukov <eugenebi at microsoft.com>
Differential Revision: https://reviews.llvm.org/D49685

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py
    lldb/trunk/source/Target/Platform.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py?rev=340841&r1=340840&r2=340841&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py Tue Aug 28 09:32:46 2018
@@ -6,6 +6,7 @@ from __future__ import print_function
 
 import shutil
 import struct
+import os
 
 import lldb
 from lldbsuite.test.decorators import *
@@ -203,6 +204,30 @@ class LinuxCoreTestCase(TestBase):
         for regname, value in values.iteritems():
             self.expect("register read {}".format(regname), substrs=["{} = {}".format(regname, value)])
 
+    @expectedFailureAll(bugnumber="llvm.org/pr37371", hostoslist=["windows"])
+    @skipIf(triple='^mips')
+    @skipIfLLVMTargetMissing("X86")
+    def test_i386_sysroot(self):
+        """Test that lldb can find the exe for an i386 linux core file using the sysroot."""
+
+        # Copy linux-i386.out to tmp_sysroot/home/labath/test/a.out (since it was compiled as
+        # /home/labath/test/a.out)
+        tmp_sysroot = os.path.join(self.getBuildDir(), "lldb_i386_mock_sysroot")
+        executable = os.path.join(tmp_sysroot, "home", "labath", "test", "a.out")
+        lldbutil.mkdir_p(os.path.dirname(executable))
+        shutil.copyfile("linux-i386.out", executable)
+
+        # 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("linux-i386.core")
+
+        # Check that we found a.out from the sysroot
+        self.check_all(process, self._i386_pid, self._i386_regions, "a.out")
+
+        self.dbg.DeleteTarget(target)
+
     def check_memory_regions(self, process, region_count):
         region_list = process.GetMemoryRegions()
         self.assertEqual(region_list.GetSize(), region_count)
@@ -299,15 +324,7 @@ class LinuxCoreTestCase(TestBase):
             self.dbg.SetOutputFileHandle(None, False)
             self.dbg.SetErrorFileHandle(None, False)
 
-    def do_test(self, filename, pid, region_count, thread_name):
-        target = self.dbg.CreateTarget(filename + ".out")
-        process = target.LoadCore(filename + ".core")
-        self.assertTrue(process, PROCESS_IS_VALID)
-        self.assertEqual(process.GetNumThreads(), 1)
-        self.assertEqual(process.GetProcessID(), pid)
-
-        self.check_state(process)
-
+    def check_stack(self, process, pid, thread_name):
         thread = process.GetSelectedThread()
         self.assertTrue(thread)
         self.assertEqual(thread.GetThreadID(), pid)
@@ -324,6 +341,21 @@ class LinuxCoreTestCase(TestBase):
                 frame.FindVariable("F").GetValueAsUnsigned(), ord(
                     backtrace[i][0]))
 
+    def check_all(self, process, pid, region_count, thread_name):
+        self.assertTrue(process, PROCESS_IS_VALID)
+        self.assertEqual(process.GetNumThreads(), 1)
+        self.assertEqual(process.GetProcessID(), pid)
+
+        self.check_state(process)
+
+        self.check_stack(process, pid, thread_name)
+
         self.check_memory_regions(process, region_count)
 
+    def do_test(self, filename, pid, region_count, thread_name):
+        target = self.dbg.CreateTarget(filename + ".out")
+        process = target.LoadCore(filename + ".core")
+
+        self.check_all(process, pid, region_count, thread_name)
+
         self.dbg.DeleteTarget(target)

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=340841&r1=340840&r2=340841&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Tue Aug 28 09:32:46 2018
@@ -228,16 +228,35 @@ Status Platform::GetSharedModule(const M
         module_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr,
         did_create_ptr, false);
 
-  return GetRemoteSharedModule(module_spec, process, module_sp,
-                               [&](const ModuleSpec &spec) {
-                                 Status error = ModuleList::GetSharedModule(
-                                     spec, module_sp, module_search_paths_ptr,
-                                     old_module_sp_ptr, did_create_ptr, false);
-                                 if (error.Success() && module_sp)
-                                   module_sp->SetPlatformFileSpec(
-                                       spec.GetFileSpec());
-                                 return error;
-                               },
+  // Module resolver lambda.
+  auto resolver = [&](const ModuleSpec &spec) {
+    Status error(eErrorTypeGeneric);
+    ModuleSpec resolved_spec;
+    // Check if we have sysroot set.
+    if (m_sdk_sysroot) {
+      // Prepend sysroot to module spec.
+      resolved_spec = spec;
+      resolved_spec.GetFileSpec().PrependPathComponent(
+          m_sdk_sysroot.GetStringRef());
+      // Try to get shared module with resolved spec.
+      error = ModuleList::GetSharedModule(
+          resolved_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr,
+          did_create_ptr, false);
+    }
+    // If we don't have sysroot or it didn't work then
+    // try original module spec.
+    if (!error.Success()) {
+      resolved_spec = spec;
+      error = ModuleList::GetSharedModule(
+          resolved_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr,
+          did_create_ptr, false);
+    }
+    if (error.Success() && module_sp)
+      module_sp->SetPlatformFileSpec(resolved_spec.GetFileSpec());
+    return error;
+  };
+
+  return GetRemoteSharedModule(module_spec, process, module_sp, resolver,
                                did_create_ptr);
 }
 




More information about the lldb-commits mailing list