Implement ObjectFileELF::GetBaseAddress
Summary:
The concept of a base address was already present in the implementation
(it's needed for computing section load addresses properly), but it was
never exposed through this function. This fixes that.
llvm-svn: 350804
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 726aa9b..71b535e 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -806,17 +806,10 @@
SectionList *section_list = GetSectionList();
if (section_list) {
if (!value_is_offset) {
- bool found_offset = false;
- for (const ELFProgramHeader &H : ProgramHeaders()) {
- if (H.p_type != PT_LOAD || H.p_offset != 0)
- continue;
-
- value = value - H.p_vaddr;
- found_offset = true;
- break;
- }
- if (!found_offset)
+ addr_t base = GetBaseAddress().GetFileAddress();
+ if (base == LLDB_INVALID_ADDRESS)
return false;
+ value -= base;
}
const size_t num_sections = section_list->GetSize();
@@ -1055,6 +1048,18 @@
return m_entry_point_address;
}
+Address ObjectFileELF::GetBaseAddress() {
+ for (const auto &EnumPHdr : llvm::enumerate(ProgramHeaders())) {
+ const ELFProgramHeader &H = EnumPHdr.value();
+ if (H.p_type != PT_LOAD || H.p_offset != 0)
+ continue;
+
+ return Address(
+ GetSectionList()->FindSectionByID(SegmentID(EnumPHdr.index())), 0);
+ }
+ return LLDB_INVALID_ADDRESS;
+}
+
//----------------------------------------------------------------------
// ParseDependentModules
//----------------------------------------------------------------------