Skip to content

Commit 20f8425

Browse files
[lldb] Fix GetRemoteSharedModule fallback logic
When the various methods of locating the module in GetRemoteSharedModule fail, make sure we pass the original module spec to the bail-out call to the provided resolver function. Also make sure we consistently use the resolved module spec from the various success paths. Thanks to what appears to have been an accidentally inverted condition (commit 85967fa applied the new condition to a path where GetModuleSpec returns false, but should have applied it when GetModuleSpec returns true), without this fix we only pass the original module spec in the fallback if the original spec has no uuid (or has a uuid that somehow matches the resolved module's uuid despite the call to GetModuleSpec failing). This manifested as a bug when processing a minidump file with a user-provided sysroot, since in that case the resolver call was being applied to resolved_module_spec (despite resolution failing), which did not have the path of its file_spec set. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D88099
1 parent c90dee1 commit 20f8425

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

lldb/source/Target/Platform.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,21 +1580,29 @@ Status Platform::GetRemoteSharedModule(const ModuleSpec &module_spec,
15801580
if (error.Success() && module_sp)
15811581
break;
15821582
}
1583-
if (module_sp)
1583+
if (module_sp) {
1584+
resolved_module_spec = arch_module_spec;
15841585
got_module_spec = true;
1586+
}
15851587
}
15861588

15871589
if (!got_module_spec) {
15881590
// Get module information from a target.
1589-
if (!GetModuleSpec(module_spec.GetFileSpec(), module_spec.GetArchitecture(),
1590-
resolved_module_spec)) {
1591+
if (GetModuleSpec(module_spec.GetFileSpec(), module_spec.GetArchitecture(),
1592+
resolved_module_spec)) {
15911593
if (!module_spec.GetUUID().IsValid() ||
15921594
module_spec.GetUUID() == resolved_module_spec.GetUUID()) {
1593-
return module_resolver(module_spec);
1595+
got_module_spec = true;
15941596
}
15951597
}
15961598
}
15971599

1600+
if (!got_module_spec) {
1601+
// Fall back to the given module resolver, which may have its own
1602+
// search logic.
1603+
return module_resolver(module_spec);
1604+
}
1605+
15981606
// If we are looking for a specific UUID, make sure resolved_module_spec has
15991607
// the same one before we search.
16001608
if (module_spec.GetUUID().IsValid()) {

lldb/test/API/functionalities/postmortem/minidump-new/TestMiniDumpNew.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,29 @@ def check_region(index, start, end, read, write, execute, mapped, name):
455455
check_region(17, 0x40169000, 0x4016b000, True, True, False, True, d)
456456
check_region(18, 0x4016b000, 0x40176000, True, True, False, True, n)
457457
check_region(-1, 0x40176000, max_int, False, False, False, False, n)
458+
459+
@skipIfLLVMTargetMissing("X86")
460+
def test_minidump_sysroot(self):
461+
"""Test that lldb can find a module referenced in an i386 linux minidump using the sysroot."""
462+
463+
# Copy linux-x86_64 executable to tmp_sysroot/temp/test/ (since it was compiled as
464+
# /tmp/test/linux-x86_64)
465+
tmp_sysroot = os.path.join(
466+
self.getBuildDir(), "lldb_i386_mock_sysroot")
467+
executable = os.path.join(
468+
tmp_sysroot, "tmp", "test", "linux-x86_64")
469+
exe_dir = os.path.dirname(executable)
470+
lldbutil.mkdir_p(exe_dir)
471+
shutil.copyfile("linux-x86_64", executable)
472+
473+
# Set sysroot and load core
474+
self.runCmd("platform select remote-linux --sysroot '%s'" %
475+
tmp_sysroot)
476+
self.process_from_yaml("linux-x86_64.yaml")
477+
self.check_state()
478+
479+
# Check that we loaded the module from the sysroot
480+
self.assertEqual(self.target.GetNumModules(), 1)
481+
module = self.target.GetModuleAtIndex(0)
482+
spec = module.GetFileSpec()
483+
self.assertEqual(spec.GetDirectory(), exe_dir)

0 commit comments

Comments
 (0)