[Lldb-commits] [lldb] Read and store gnu build id from loaded core file (PR #92078)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Tue May 14 11:36:17 PDT 2024


================
@@ -983,6 +995,44 @@ llvm::Error ProcessElfCore::ParseThreadContextsFromNoteSegment(
   }
 }
 
+bool ProcessElfCore::IsElf(const NT_FILE_Entry entry) {
+  const uint8_t elf_header[4] = {0x7f, 0x45, 0x4c,
+                                 0x46}; // ELF file begin with this 4 bytes
+  uint8_t buf[4];
+  Status error;
+  size_t byte_read = ReadMemory(entry.start, buf, 4, error);
+  if (byte_read == 4) {
+    return memcmp(elf_header, buf, 4) == 0;
+  } else {
+    return false;
+  }
+}
+
+UUID ProcessElfCore::FindBuildId(const NT_FILE_Entry entry) {
+  if (!IsElf(entry)) {
+    return UUID();
+  }
+  // Build ID is stored in the ELF file as a section named ".note.gnu.build-id"
+  uint8_t gnu_build_id_bytes[8] = {0x03, 0x00, 0x00, 0x00,
+                                   0x47, 0x4e, 0x55, 0x00};
+  lldb::addr_t gnu_build_id_addr =
+      FastSearch(entry.start, entry.end, gnu_build_id_bytes, 8);
+  if (gnu_build_id_addr == LLDB_INVALID_ADDRESS) {
+    return UUID();
----------------
clayborg wrote:

```
return std::nullopt;
```

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


More information about the lldb-commits mailing list