Skip to content

Commit 179a68a

Browse files
committed
[lldb] Fix ELF core debugging
Addressing two issues on ELF core debugging 1. ProcessElfCore::FindBuidIdInCoreMemory reads wrong address for ELF header (fixed by @clayborg) 2. DynamicLoader does not use ProcessElfCore NT_FILE entries to get UUID. Add FindBuildId to get UUID from Process.
1 parent 4087b87 commit 179a68a

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

lldb/include/lldb/Target/Process.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,8 @@ class Process : public std::enable_shared_from_this<Process>,
13801380

13811381
virtual bool GetProcessInfo(ProcessInstanceInfo &info);
13821382

1383+
virtual lldb_private::UUID FindBuildId(const llvm::StringRef path);
1384+
13831385
/// Get the exit status for a process.
13841386
///
13851387
/// \return

lldb/source/Core/DynamicLoader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP module) const {
157157
ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
158158
Target &target = m_process->GetTarget();
159159
ModuleSpec module_spec(file, target.GetArchitecture());
160+
if (UUID uuid = m_process->FindBuildId(file.GetPath())) {
161+
// Process may have the UUID for the module, e.g. ELF core.
162+
module_spec.GetUUID().SetFromStringRef(uuid.GetAsString());
163+
}
160164

161165
if (ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec))
162166
return module_sp;

lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
281281
}
282282
}
283283

284+
UUID ProcessElfCore::FindBuildId(const llvm::StringRef path) {
285+
for (NT_FILE_Entry &entry : m_nt_file_entries)
286+
if (path == entry.path)
287+
return entry.uuid;
288+
return UUID();
289+
}
290+
284291
lldb_private::DynamicLoader *ProcessElfCore::GetDynamicLoader() {
285292
if (m_dyld_up.get() == nullptr)
286293
m_dyld_up.reset(DynamicLoader::FindPlugin(
@@ -1034,7 +1041,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
10341041
std::vector<uint8_t> note_bytes;
10351042
note_bytes.resize(program_header.p_memsz);
10361043

1037-
byte_read = ReadMemory(program_header.p_vaddr, note_bytes.data(),
1044+
const lldb::addr_t program_header_vaddr = program_header.p_vaddr + address;
1045+
byte_read = ReadMemory(program_header_vaddr, note_bytes.data(),
10381046
program_header.p_memsz, error);
10391047
if (byte_read != program_header.p_memsz)
10401048
continue;

lldb/source/Plugins/Process/elf-core/ProcessElfCore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class ProcessElfCore : public lldb_private::PostMortemProcess {
9797

9898
bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override;
9999

100+
// Returns the gnu uuid from matched NT_FILE entry
101+
lldb_private::UUID FindBuildId(const llvm::StringRef path) override;
102+
100103
protected:
101104
void Clear();
102105

lldb/source/Target/Process.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6080,6 +6080,11 @@ bool Process::GetProcessInfo(ProcessInstanceInfo &info) {
60806080
return platform_sp->GetProcessInfo(GetID(), info);
60816081
}
60826082

6083+
lldb_private::UUID Process::FindBuildId(const llvm::StringRef path) {
6084+
lldb_private::UUID invalid_uuid;
6085+
return invalid_uuid;
6086+
}
6087+
60836088
ThreadCollectionSP Process::GetHistoryThreads(lldb::addr_t addr) {
60846089
ThreadCollectionSP threads;
60856090

0 commit comments

Comments
 (0)