[Lldb-commits] [lldb] r350804 - Implement ObjectFileELF::GetBaseAddress
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 10 01:32:32 PST 2019
Author: labath
Date: Thu Jan 10 01:32:31 2019
New Revision: 350804
URL: http://llvm.org/viewvc/llvm-project?rev=350804&view=rev
Log:
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.
Added:
lldb/trunk/lit/Modules/ELF/basic-info.yaml
Modified:
lldb/trunk/lit/Modules/ELF/compressed-sections.yaml
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
lldb/trunk/tools/lldb-test/lldb-test.cpp
Added: lldb/trunk/lit/Modules/ELF/basic-info.yaml
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/ELF/basic-info.yaml?rev=350804&view=auto
==============================================================================
--- lldb/trunk/lit/Modules/ELF/basic-info.yaml (added)
+++ lldb/trunk/lit/Modules/ELF/basic-info.yaml Thu Jan 10 01:32:31 2019
@@ -0,0 +1,27 @@
+# REQUIRES: lld
+
+# RUN: yaml2obj %s > %t.o
+# RUN: ld.lld %t.o -o %t -image-base 0x47000
+# RUN: lldb-test object-file %t | FileCheck %s
+
+# CHECK: Plugin name: elf
+# CHECK: Architecture: x86_64--
+# CHECK: Executable: true
+# CHECK: Stripped: false
+# CHECK: Type: executable
+# CHECK: Strata: user
+# CHECK: Base VM address: 0x47000
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000010
+ Content: 554889E55DC3
+...
Modified: lldb/trunk/lit/Modules/ELF/compressed-sections.yaml
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Modules/ELF/compressed-sections.yaml?rev=350804&r1=350803&r2=350804&view=diff
==============================================================================
--- lldb/trunk/lit/Modules/ELF/compressed-sections.yaml (original)
+++ lldb/trunk/lit/Modules/ELF/compressed-sections.yaml Thu Jan 10 01:32:31 2019
@@ -19,13 +19,15 @@ Sections:
# CHECK: Name: .hello_elf
# CHECK-NEXT: Type: regular
-# CHECK: VM size: 0
+# CHECK: VM address: 0
+# CHECK-NEXT: VM size: 0
# CHECK-NEXT: File size: 28
# CHECK-NEXT: Data:
# CHECK-NEXT: 20304050 60708090
# CHECK: Name: .bogus
# CHECK-NEXT: Type: regular
-# CHECK: VM size: 0
+# CHECK: VM address: 0
+# CHECK-NEXT: VM size: 0
# CHECK-NEXT: File size: 8
# CHECK-NEXT: Data: ()
Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=350804&r1=350803&r2=350804&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Thu Jan 10 01:32:31 2019
@@ -806,17 +806,10 @@ bool ObjectFileELF::SetLoadAddress(Targe
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 @@ lldb_private::Address ObjectFileELF::Get
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
//----------------------------------------------------------------------
Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h?rev=350804&r1=350803&r2=350804&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h Thu Jan 10 01:32:31 2019
@@ -134,6 +134,8 @@ public:
lldb_private::Address GetEntryPointAddress() override;
+ lldb_private::Address GetBaseAddress() override;
+
ObjectFile::Type CalculateType() override;
ObjectFile::Strata CalculateStrata() override;
Modified: lldb/trunk/tools/lldb-test/lldb-test.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/lldb-test.cpp?rev=350804&r1=350803&r2=350804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-test/lldb-test.cpp (original)
+++ lldb/trunk/tools/lldb-test/lldb-test.cpp Thu Jan 10 01:32:31 2019
@@ -785,6 +785,8 @@ static int dumpObjectFiles(Debugger &Dbg
Printer.formatLine("Stripped: {0}", ObjectPtr->IsStripped());
Printer.formatLine("Type: {0}", ObjectPtr->GetType());
Printer.formatLine("Strata: {0}", ObjectPtr->GetStrata());
+ Printer.formatLine("Base VM address: {0:x}",
+ ObjectPtr->GetBaseAddress().GetFileAddress());
dumpSectionList(Printer, *Sections, /*is_subsection*/ false);
More information about the lldb-commits
mailing list