Skip to content

Commit

Permalink
Respect platform sysroot when loading core files
Browse files Browse the repository at this point in the history
Patch by Eugene Birukov <eugenebi@microsoft.com>
Differential Revision: https://reviews.llvm.org/D49685

llvm-svn: 340841
  • Loading branch information
labath committed Aug 28, 2018
1 parent 8f8832d commit 1f8639a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 19 deletions.
Expand Up @@ -6,6 +6,7 @@

import shutil
import struct
import os

import lldb
from lldbsuite.test.decorators import *
Expand Down Expand Up @@ -203,6 +204,30 @@ def test_FPR_SSE(self):
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)
Expand Down Expand Up @@ -299,15 +324,7 @@ def check_state(self, process):
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)
Expand All @@ -324,6 +341,21 @@ def do_test(self, filename, pid, region_count, thread_name):
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)
39 changes: 29 additions & 10 deletions lldb/source/Target/Platform.cpp
Expand Up @@ -228,16 +228,35 @@ Status Platform::GetSharedModule(const ModuleSpec &module_spec,
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);
}

Expand Down

0 comments on commit 1f8639a

Please sign in to comment.