[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)
Kazuki Sakamoto via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 20 17:04:45 PST 2024
https://github.com/splhack updated https://github.com/llvm/llvm-project/pull/117070
>From 6b8f4a824d39ce557230e610a846d316358b4f20 Mon Sep 17 00:00:00 2001
From: Kazuki Sakamoto <sakamoto at splhack.org>
Date: Wed, 20 Nov 2024 16:20:40 -0800
Subject: [PATCH 1/2] Run clang format.
---
lldb/source/Core/DynamicLoader.cpp | 7 +++---
.../Process/elf-core/ProcessElfCore.cpp | 25 +++++++++----------
2 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/lldb/source/Core/DynamicLoader.cpp b/lldb/source/Core/DynamicLoader.cpp
index 68d6ab0850853f..34f0661a312bb6 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -368,8 +368,7 @@ addr_t DynamicLoader::ReadPointer(addr_t addr) {
return value;
}
-void DynamicLoader::LoadOperatingSystemPlugin(bool flush)
-{
- if (m_process)
- m_process->LoadOperatingSystemPlugin(flush);
+void DynamicLoader::LoadOperatingSystemPlugin(bool flush) {
+ if (m_process)
+ m_process->LoadOperatingSystemPlugin(flush);
}
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 7955594bf5d94c..3a4f42bb8ca392 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -224,7 +224,7 @@ Status ProcessElfCore::DoLoadCore() {
ArchSpec core_arch(m_core_module_sp->GetArchitecture());
target_arch.MergeFrom(core_arch);
GetTarget().SetArchitecture(target_arch);
-
+
SetUnixSignals(UnixSignals::Create(GetArchitecture()));
// Ensure we found at least one thread that was stopped on a signal.
@@ -393,7 +393,7 @@ size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
const lldb::addr_t file_start = address_range->data.GetRangeBase();
const lldb::addr_t file_end = address_range->data.GetRangeEnd();
size_t bytes_to_read = size; // Number of bytes to read from the core file
- size_t bytes_copied = 0; // Number of bytes actually read from the core file
+ size_t bytes_copied = 0; // Number of bytes actually read from the core file
lldb::addr_t bytes_left =
0; // Number of bytes available in the core file from the given address
@@ -476,8 +476,7 @@ lldb::addr_t ProcessElfCore::GetImageInfoAddress() {
// Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
static void ParseFreeBSDPrStatus(ThreadData &thread_data,
- const DataExtractor &data,
- bool lp64) {
+ const DataExtractor &data, bool lp64) {
lldb::offset_t offset = 0;
int pr_version = data.GetU32(&offset);
@@ -504,8 +503,7 @@ static void ParseFreeBSDPrStatus(ThreadData &thread_data,
// Parse a FreeBSD NT_PRPSINFO note - see FreeBSD sys/procfs.h for details.
static void ParseFreeBSDPrPsInfo(ProcessElfCore &process,
- const DataExtractor &data,
- bool lp64) {
+ const DataExtractor &data, bool lp64) {
lldb::offset_t offset = 0;
int pr_version = data.GetU32(&offset);
@@ -524,8 +522,7 @@ static void ParseFreeBSDPrPsInfo(ProcessElfCore &process,
}
static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data,
- uint32_t &cpi_nlwps,
- uint32_t &cpi_signo,
+ uint32_t &cpi_nlwps, uint32_t &cpi_signo,
uint32_t &cpi_siglwp,
uint32_t &cpi_pid) {
lldb::offset_t offset = 0;
@@ -693,8 +690,8 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
if (name == "NetBSD-CORE") {
if (note.info.n_type == NETBSD::NT_PROCINFO) {
- llvm::Error error = ParseNetBSDProcInfo(note.data, nlwps, signo,
- siglwp, pr_pid);
+ llvm::Error error =
+ ParseNetBSDProcInfo(note.data, nlwps, signo, siglwp, pr_pid);
if (error)
return error;
SetID(pr_pid);
@@ -875,7 +872,7 @@ llvm::Error ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef<CoreNote> notes) {
/// - NT_SIGINFO - Information about the signal that terminated the process
/// - NT_AUXV - Process auxiliary vector
/// - NT_FILE - Files mapped into memory
-///
+///
/// Additionally, for each thread in the process the core file will contain at
/// least the NT_PRSTATUS note, containing the thread id and general purpose
/// registers. It may include additional notes for other register sets (floating
@@ -920,7 +917,9 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
Status status = prpsinfo.Parse(note.data, arch);
if (status.Fail())
return status.ToError();
- thread_data.name.assign (prpsinfo.pr_fname, strnlen (prpsinfo.pr_fname, sizeof (prpsinfo.pr_fname)));
+ thread_data.name.assign(
+ prpsinfo.pr_fname,
+ strnlen(prpsinfo.pr_fname, sizeof(prpsinfo.pr_fname)));
SetID(prpsinfo.pr_pid);
break;
}
@@ -975,7 +974,7 @@ llvm::Error ProcessElfCore::ParseThreadContextsFromNoteSegment(
assert(segment_header.p_type == llvm::ELF::PT_NOTE);
auto notes_or_error = parseSegment(segment_data);
- if(!notes_or_error)
+ if (!notes_or_error)
return notes_or_error.takeError();
switch (GetArchitecture().GetTriple().getOS()) {
case llvm::Triple::FreeBSD:
>From b285bba80b7b7ad4e351485d59df41f328462867 Mon Sep 17 00:00:00 2001
From: Kazuki Sakamoto <sakamoto at splhack.org>
Date: Wed, 20 Nov 2024 13:49:26 -0800
Subject: [PATCH 2/2] [lldb] Fix ELF core debugging
DynamicLoader does not use ProcessElfCore NT_FILE entries to get
UUID. Use GetModuleSpec to get UUID from Process.
---
lldb/source/Core/DynamicLoader.cpp | 5 +++++
.../Plugins/Process/elf-core/ProcessElfCore.cpp | 16 ++++++++++++++++
.../Plugins/Process/elf-core/ProcessElfCore.h | 4 ++++
3 files changed, 25 insertions(+)
diff --git a/lldb/source/Core/DynamicLoader.cpp b/lldb/source/Core/DynamicLoader.cpp
index 34f0661a312bb6..03f360c59d65e3 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -157,6 +157,11 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP module) const {
ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
Target &target = m_process->GetTarget();
ModuleSpec module_spec(file, target.GetArchitecture());
+ ModuleSpec module_spec_from_process;
+ // Process may be able to augment the module_spec with UUID, e.g. ELF core.
+ if (m_process->GetModuleSpec(file, target.GetArchitecture(), module_spec_from_process)) {
+ module_spec = module_spec_from_process;
+ }
if (ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec))
return module_sp;
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 3a4f42bb8ca392..568c42089851d8 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -281,6 +281,22 @@ void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
}
}
+bool ProcessElfCore::GetModuleSpec(const FileSpec &module_file_spec,
+ const ArchSpec &arch,
+ ModuleSpec &module_spec) {
+ module_spec.Clear();
+ for (NT_FILE_Entry &entry : m_nt_file_entries) {
+ if (module_file_spec.GetPath() == entry.path) {
+ module_spec.GetFileSpec() = module_file_spec;
+ module_spec.GetArchitecture() = arch;
+ module_spec.GetUUID().SetFromStringRef(entry.uuid.GetAsString());
+ return true;
+ }
+ }
+
+ return false;
+}
+
lldb_private::DynamicLoader *ProcessElfCore::GetDynamicLoader() {
if (m_dyld_up.get() == nullptr)
m_dyld_up.reset(DynamicLoader::FindPlugin(
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
index 280c61ed376396..a7b1822ccf01ff 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
@@ -163,6 +163,10 @@ class ProcessElfCore : public lldb_private::PostMortemProcess {
// Populate gnu uuid for each NT_FILE entry
void UpdateBuildIdForNTFileEntries();
+ bool GetModuleSpec(const lldb_private::FileSpec &module_file_spec,
+ const lldb_private::ArchSpec &arch,
+ lldb_private::ModuleSpec &module_spec) override;
+
// Returns the value of certain type of note of a given start address
lldb_private::UUID FindBuidIdInCoreMemory(lldb::addr_t address);
More information about the lldb-commits
mailing list