[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 20 14:15:53 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Kazuki Sakamoto (splhack)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/117070.diff


5 Files Affected:

- (modified) lldb/include/lldb/Target/Process.h (+2) 
- (modified) lldb/source/Core/DynamicLoader.cpp (+4) 
- (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp (+9-1) 
- (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.h (+3) 
- (modified) lldb/source/Target/Process.cpp (+5) 


``````````diff
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index b8c53a474ba6b9..2f0cf78f260c5a 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1380,6 +1380,8 @@ class Process : public std::enable_shared_from_this<Process>,
 
   virtual bool GetProcessInfo(ProcessInstanceInfo &info);
 
+  virtual lldb_private::UUID FindBuildId(const llvm::StringRef path);
+
   /// Get the exit status for a process.
   ///
   /// \return
diff --git a/lldb/source/Core/DynamicLoader.cpp b/lldb/source/Core/DynamicLoader.cpp
index 68d6ab0850853f..cc396e92721123 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -157,6 +157,10 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP module) const {
 ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
   Target &target = m_process->GetTarget();
   ModuleSpec module_spec(file, target.GetArchitecture());
+  if (UUID uuid = m_process->FindBuildId(file.GetPath())) {
+    // Process may have the UUID for the module, e.g. ELF core.
+    module_spec.GetUUID().SetFromStringRef(uuid.GetAsString());
+  }
 
   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 7955594bf5d94c..8ad6b83d77effe 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -281,6 +281,13 @@ void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
   }
 }
 
+UUID ProcessElfCore::FindBuildId(const llvm::StringRef path) {
+  for (NT_FILE_Entry &entry : m_nt_file_entries)
+    if (path == entry.path)
+      return entry.uuid;
+  return UUID();
+}
+
 lldb_private::DynamicLoader *ProcessElfCore::GetDynamicLoader() {
   if (m_dyld_up.get() == nullptr)
     m_dyld_up.reset(DynamicLoader::FindPlugin(
@@ -1034,7 +1041,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
     std::vector<uint8_t> note_bytes;
     note_bytes.resize(program_header.p_memsz);
 
-    byte_read = ReadMemory(program_header.p_vaddr, note_bytes.data(),
+    const lldb::addr_t program_header_vaddr = program_header.p_vaddr + address;
+    byte_read = ReadMemory(program_header_vaddr, note_bytes.data(),
                            program_header.p_memsz, error);
     if (byte_read != program_header.p_memsz)
       continue;
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
index 280c61ed376396..303f18249a976e 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
@@ -97,6 +97,9 @@ class ProcessElfCore : public lldb_private::PostMortemProcess {
 
   bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override;
 
+  // Returns the gnu uuid from matched NT_FILE entry
+  lldb_private::UUID FindBuildId(const llvm::StringRef path) override;
+
 protected:
   void Clear();
 
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 9125ceca74a003..d2921f623bbefc 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6080,6 +6080,11 @@ bool Process::GetProcessInfo(ProcessInstanceInfo &info) {
   return platform_sp->GetProcessInfo(GetID(), info);
 }
 
+lldb_private::UUID Process::FindBuildId(const llvm::StringRef path) {
+  lldb_private::UUID invalid_uuid;
+  return invalid_uuid;
+}
+
 ThreadCollectionSP Process::GetHistoryThreads(lldb::addr_t addr) {
   ThreadCollectionSP threads;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/117070


More information about the lldb-commits mailing list