[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:53 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);
+ lldb::offset_t offset = 0;
+
+ elf::ELFHeader elf_header;
+ elf_header.Parse(data, &offset);
----------------
clayborg wrote:
Use `header_data` to only allow access to the bytes we read.
```
elf_header.Parse(header_data, &offset);
```
https://github.com/llvm/llvm-project/pull/92492
More information about the lldb-commits
mailing list