Index: packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py =================================================================== --- packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py +++ packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/TestLinuxCore.py @@ -6,6 +6,7 @@ import shutil import struct +import os import lldb from lldbsuite.test.decorators import * @@ -203,6 +204,30 @@ 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 @@ 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 @@ 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) Index: source/Target/Platform.cpp =================================================================== --- source/Target/Platform.cpp +++ source/Target/Platform.cpp @@ -228,17 +228,36 @@ module_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr, did_create_ptr, false); + // 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, - [&](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; - }, - did_create_ptr); + resolver, did_create_ptr); } bool Platform::GetModuleSpec(const FileSpec &module_file_spec,