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

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Wed May 22 15:05:52 PDT 2024


================
@@ -983,6 +1001,66 @@ llvm::Error ProcessElfCore::ParseThreadContextsFromNoteSegment(
   }
 }
 
+bool ProcessElfCore::IsElf(lldb::addr_t address) {
+  uint8_t buf[4];
+  Status error;
+  size_t byte_read = ReadMemory(address, buf, 4, error);
+  if (byte_read != 4)
+    return false;
+  return elf::ELFHeader::MagicBytesMatch(buf);
+}
+
+std::optional<UUID> ProcessElfCore::FindNoteInCoreMemory(lldb::addr_t address,
+                                                         uint32_t type) {
+  if (!IsElf(address))
+    return std::nullopt;
+  const uint32_t addr_size = GetAddressByteSize();
+  const size_t elf_header_size = addr_size == 4 ? sizeof(llvm::ELF::Elf32_Ehdr)
+                                                : sizeof(llvm::ELF::Elf64_Ehdr);
+
+  unsigned char buf[4096];
+  Status error;
+  size_t byte_read = ReadMemory(address, buf, elf_header_size, error);
+  if (byte_read != elf_header_size)
+    return std::nullopt;
+  DataExtractor data(buf, 4096, GetByteOrder(), addr_size);
----------------
clayborg wrote:

It is ok to have a large buffer, but we should make sure the data extractor points to just the data we have read for each place that we use it by contructing new DataExtractor objects:
```
assert(sizeof(buf) >= elf_header_size);
DataExtractor header_data(buf, elf_header_size, GetByteOrder(), addr_size);
```


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


More information about the lldb-commits mailing list