Skip to content

Commit 896ec79

Browse files
George HuGeorge Hu
George Hu
authored and
George Hu
committed
[lldb] Fix address to read segment data
1 parent 6a01ac7 commit 896ec79

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
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)