Skip to content

Commit a15fedc

Browse files
GeorgeHuyuboGeorge Hu
and
George Hu
authored
[lldb] Correct address calculation for reading segment data (llvm#120655)
This commit addresses a bug introduced in commit bcf654c, which prevented LLDB from parsing the GNU build ID for the main executable from a core file. The fix finds the `p_vaddr` of the first `PT_LOAD` segment as the `base_addr` and subtract this `base_addr` from the virtual address being read. Co-authored-by: George Hu <[email protected]>
1 parent 6c3c90b commit a15fedc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
10311031

10321032
std::vector<uint8_t> ph_bytes;
10331033
ph_bytes.resize(elf_header.e_phentsize);
1034+
lldb::addr_t base_addr = 0;
1035+
bool found_first_load_segment = false;
10341036
for (unsigned int i = 0; i < elf_header.e_phnum; ++i) {
10351037
byte_read = ReadMemory(ph_addr + i * elf_header.e_phentsize,
10361038
ph_bytes.data(), elf_header.e_phentsize, error);
@@ -1041,6 +1043,11 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
10411043
offset = 0;
10421044
elf::ELFProgramHeader program_header;
10431045
program_header.Parse(program_header_data, &offset);
1046+
if (program_header.p_type == llvm::ELF::PT_LOAD &&
1047+
!found_first_load_segment) {
1048+
base_addr = program_header.p_vaddr;
1049+
found_first_load_segment = true;
1050+
}
10441051
if (program_header.p_type != llvm::ELF::PT_NOTE)
10451052
continue;
10461053

@@ -1049,7 +1056,7 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
10491056

10501057
// We need to slide the address of the p_vaddr as these values don't get
10511058
// relocated in memory.
1052-
const lldb::addr_t vaddr = program_header.p_vaddr + address;
1059+
const lldb::addr_t vaddr = program_header.p_vaddr + address - base_addr;
10531060
byte_read =
10541061
ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz, error);
10551062
if (byte_read != program_header.p_memsz)

0 commit comments

Comments
 (0)