Skip to content

[lldb] Correct address calculation for reading segment data #120655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {

std::vector<uint8_t> ph_bytes;
ph_bytes.resize(elf_header.e_phentsize);
lldb::addr_t base_addr = 0;
bool found_first_load_segment = false;
for (unsigned int i = 0; i < elf_header.e_phnum; ++i) {
byte_read = ReadMemory(ph_addr + i * elf_header.e_phentsize,
ph_bytes.data(), elf_header.e_phentsize, error);
Expand All @@ -1041,6 +1043,11 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
offset = 0;
elf::ELFProgramHeader program_header;
program_header.Parse(program_header_data, &offset);
if (program_header.p_type == llvm::ELF::PT_LOAD &&
!found_first_load_segment) {
base_addr = program_header.p_vaddr;
found_first_load_segment = true;
}
if (program_header.p_type != llvm::ELF::PT_NOTE)
continue;

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

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