Fix a crasher due to an assert when two files have the same UUID but different paths.

Summary: The PlaceholderObjectFile has an assert in SetLoadAddress that fires if "m_base == value" is not true. To avoid this, we create check that the base address matches, and if it doesn't we clear the module that was found using the UUID so that we create a new PlaceholderObjectFile. Added a test to cover this issue.

Reviewers: labath, aadsm, dvlahovski

Subscribers: lldb-commits

Tags: #lldb

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

llvm-svn: 374242
This commit is contained in:
Greg Clayton 2019-10-09 22:03:15 +00:00
parent c6dec1d828
commit 0156be59b4
3 changed files with 81 additions and 24 deletions

View File

@ -121,6 +121,24 @@ class MiniDumpUUIDTestCase(TestBase):
self.verify_module(modules[0], "/not/exist/a", None) self.verify_module(modules[0], "/not/exist/a", None)
self.verify_module(modules[1], "/not/exist/b", None) self.verify_module(modules[1], "/not/exist/b", None)
def test_uuid_modules_elf_build_id_same(self):
"""
Test multiple modules having a MINIDUMP_MODULE.CvRecord that is
valid, and contains a ELF build ID whose value is the same. There
is an assert in the PlaceholderObjectFile that was firing when we
encountered this which was crashing the process that was checking
if PlaceholderObjectFile.m_base was the same as the address this
fake module was being loaded at. We need to ensure we don't crash
in such cases and that we add both modules even though they have
the same UUID.
"""
modules = self.get_minidump_modules("linux-arm-same-uuids.yaml")
self.assertEqual(2, len(modules))
self.verify_module(modules[0], "/file/does/not/exist/a",
'11223344-1122-3344-1122-334411223344-11223344')
self.verify_module(modules[1], "/file/does/not/exist/b",
'11223344-1122-3344-1122-334411223344-11223344')
@expectedFailureAll(oslist=["windows"]) @expectedFailureAll(oslist=["windows"])
def test_partial_uuid_match(self): def test_partial_uuid_match(self):
""" """

View File

@ -0,0 +1,21 @@
--- !minidump
Streams:
- Type: SystemInfo
Processor Arch: AMD64
Platform ID: Linux
CSD Version: '15E216'
CPU:
Vendor ID: GenuineIntel
Version Info: 0x00000000
Feature Info: 0x00000000
- Type: ModuleList
Modules:
- Base of Image: 0x0000000000001000
Size of Image: 0x00001000
Module Name: '/file/does/not/exist/a'
CodeView Record: '52534453112233441122334411223344112233441122334411'
- Base of Image: 0x0000000000003000
Size of Image: 0x00001000
Module Name: '/file/does/not/exist/b'
CodeView Record: '52534453112233441122334411223344112233441122334411'
...

View File

@ -49,8 +49,8 @@ namespace {
class PlaceholderObjectFile : public ObjectFile { class PlaceholderObjectFile : public ObjectFile {
public: public:
PlaceholderObjectFile(const lldb::ModuleSP &module_sp, PlaceholderObjectFile(const lldb::ModuleSP &module_sp,
const ModuleSpec &module_spec, lldb::offset_t base, const ModuleSpec &module_spec, lldb::addr_t base,
lldb::offset_t size) lldb::addr_t size)
: ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0, : ObjectFile(module_sp, &module_spec.GetFileSpec(), /*file_offset*/ 0,
/*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0), /*length*/ 0, /*data_sp*/ nullptr, /*data_offset*/ 0),
m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()), m_arch(module_spec.GetArchitecture()), m_uuid(module_spec.GetUUID()),
@ -58,7 +58,10 @@ public:
m_symtab_up = std::make_unique<Symtab>(this); m_symtab_up = std::make_unique<Symtab>(this);
} }
ConstString GetPluginName() override { return ConstString("placeholder"); } static ConstString GetStaticPluginName() {
return ConstString("placeholder");
}
ConstString GetPluginName() override { return GetStaticPluginName(); }
uint32_t GetPluginVersion() override { return 1; } uint32_t GetPluginVersion() override { return 1; }
bool ParseHeader() override { return true; } bool ParseHeader() override { return true; }
Type CalculateType() override { return eTypeUnknown; } Type CalculateType() override { return eTypeUnknown; }
@ -109,11 +112,12 @@ public:
GetFileSpec(), m_base, m_base + m_size); GetFileSpec(), m_base, m_base + m_size);
} }
lldb::addr_t GetBaseImageAddress() const { return m_base; }
private: private:
ArchSpec m_arch; ArchSpec m_arch;
UUID m_uuid; UUID m_uuid;
lldb::offset_t m_base; lldb::addr_t m_base;
lldb::offset_t m_size; lldb::addr_t m_size;
}; };
} // namespace } // namespace
@ -351,14 +355,15 @@ void ProcessMinidump::ReadModuleList() {
std::vector<const minidump::Module *> filtered_modules = std::vector<const minidump::Module *> filtered_modules =
m_minidump_parser->GetFilteredModuleList(); m_minidump_parser->GetFilteredModuleList();
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_MODULES)); Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
for (auto module : filtered_modules) { for (auto module : filtered_modules) {
std::string name = cantFail(m_minidump_parser->GetMinidumpFile().getString( std::string name = cantFail(m_minidump_parser->GetMinidumpFile().getString(
module->ModuleNameRVA)); module->ModuleNameRVA));
const uint64_t load_addr = module->BaseOfImage;
const uint64_t load_size = module->SizeOfImage;
LLDB_LOG(log, "found module: name: {0} {1:x10}-{2:x10} size: {3}", name, LLDB_LOG(log, "found module: name: {0} {1:x10}-{2:x10} size: {3}", name,
module->BaseOfImage, module->BaseOfImage + module->SizeOfImage, load_addr, load_addr + load_size, load_size);
module->SizeOfImage);
// check if the process is wow64 - a 32 bit windows process running on a // check if the process is wow64 - a 32 bit windows process running on a
// 64 bit windows // 64 bit windows
@ -401,6 +406,19 @@ void ProcessMinidump::ReadModuleList() {
} }
} }
} }
if (module_sp) {
// Watch out for place holder modules that have different paths, but the
// same UUID. If the base address is different, create a new module. If
// we don't then we will end up setting the load address of a different
// PlaceholderObjectFile and an assertion will fire.
auto *objfile = module_sp->GetObjectFile();
if (objfile && objfile->GetPluginName() ==
PlaceholderObjectFile::GetStaticPluginName()) {
if (((PlaceholderObjectFile *)objfile)->GetBaseImageAddress() !=
load_addr)
module_sp.reset();
}
}
if (!module_sp) { if (!module_sp) {
// We failed to locate a matching local object file. Fortunately, the // We failed to locate a matching local object file. Fortunately, the
// minidump format encodes enough information about each module's memory // minidump format encodes enough information about each module's memory
@ -415,12 +433,12 @@ void ProcessMinidump::ReadModuleList() {
name); name);
module_sp = Module::CreateModuleFromObjectFile<PlaceholderObjectFile>( module_sp = Module::CreateModuleFromObjectFile<PlaceholderObjectFile>(
module_spec, module->BaseOfImage, module->SizeOfImage); module_spec, load_addr, load_size);
GetTarget().GetImages().Append(module_sp, true /* notify */); GetTarget().GetImages().Append(module_sp, true /* notify */);
} }
bool load_addr_changed = false; bool load_addr_changed = false;
module_sp->SetLoadAddress(GetTarget(), module->BaseOfImage, false, module_sp->SetLoadAddress(GetTarget(), load_addr, false,
load_addr_changed); load_addr_changed);
} }
} }