[llvm] r310915 - [llvm-dwarfdump] - Print section name and index when dumping .debug_info ranges
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 05:32:55 PDT 2017
Author: grimar
Date: Tue Aug 15 05:32:54 2017
New Revision: 310915
URL: http://llvm.org/viewvc/llvm-project?rev=310915&view=rev
Log:
[llvm-dwarfdump] - Print section name and index when dumping .debug_info ranges
Teaches llvm-dwarfdump to print section index and name of range
when it dumps .debug_info.
Differential revision: https://reviews.llvm.org/D36313
Modified:
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h
llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/trunk/test/DebugInfo/X86/dwarfdump-ranges-unrelocated.s
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h?rev=310915&r1=310914&r2=310915&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h Tue Aug 15 05:32:54 2017
@@ -27,6 +27,7 @@ class DWARFObject {
public:
virtual ~DWARFObject() = default;
virtual StringRef getFileName() const { llvm_unreachable("unimplemented"); }
+ virtual const object::ObjectFile *getFile() const { return nullptr; }
virtual bool isLittleEndian() const = 0;
virtual uint8_t getAddressSize() const { llvm_unreachable("unimplemented"); }
virtual const DWARFSection &getInfoSection() const { return Dummy; }
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=310915&r1=310914&r2=310915&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Tue Aug 15 05:32:54 2017
@@ -933,6 +933,7 @@ class DWARFObjInMemory final : public DW
bool IsLittleEndian;
uint8_t AddressSize;
StringRef FileName;
+ const object::ObjectFile *Obj = nullptr;
using TypeSectionMap = MapVector<object::SectionRef, DWARFSectionMap,
std::map<object::SectionRef, unsigned>>;
@@ -1051,7 +1052,8 @@ public:
DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
function_ref<ErrorPolicy(Error)> HandleError)
: IsLittleEndian(Obj.isLittleEndian()),
- AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()) {
+ AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()),
+ Obj(&Obj) {
for (const SectionRef &Section : Obj.sections()) {
StringRef Name;
@@ -1188,6 +1190,8 @@ public:
return AI->second;
}
+ const object::ObjectFile *getFile() const override { return Obj; }
+
bool isLittleEndian() const override { return IsLittleEndian; }
StringRef getAbbrevDWOSection() const override { return AbbrevDWOSection; }
const DWARFSection &getLineDWOSection() const override {
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp?rev=310915&r1=310914&r2=310915&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp Tue Aug 15 05:32:54 2017
@@ -33,20 +33,22 @@ bool DWARFDebugRangeList::extract(const
return false;
Offset = *offset_ptr;
while (true) {
- RangeListEntry entry;
+ RangeListEntry Entry;
+ Entry.SectionIndex = -1ULL;
+
uint32_t prev_offset = *offset_ptr;
- entry.StartAddress =
- data.getRelocatedAddress(offset_ptr, &entry.SectionIndex);
- entry.EndAddress = data.getRelocatedAddress(offset_ptr);
+ Entry.StartAddress = data.getRelocatedAddress(offset_ptr);
+ Entry.EndAddress =
+ data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex);
// Check that both values were extracted correctly.
if (*offset_ptr != prev_offset + 2 * AddressSize) {
clear();
return false;
}
- if (entry.isEndOfListEntry())
+ if (Entry.isEndOfListEntry())
break;
- Entries.push_back(entry);
+ Entries.push_back(Entry);
}
return true;
}
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=310915&r1=310914&r2=310915&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Tue Aug 15 05:32:54 2017
@@ -18,6 +18,7 @@
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
+#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MathExtras.h"
@@ -31,6 +32,7 @@
using namespace llvm;
using namespace dwarf;
+using namespace object;
using namespace syntax;
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
@@ -51,17 +53,42 @@ static void dumpApplePropertyAttribute(r
OS << ")";
}
-static void dumpRanges(raw_ostream &OS, const DWARFAddressRangesVector& Ranges,
- unsigned AddressSize, unsigned Indent) {
- if (Ranges.empty())
- return;
-
- for (const auto &Range: Ranges) {
+static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS,
+ const DWARFAddressRangesVector &Ranges,
+ unsigned AddressSize, unsigned Indent,
+ const DIDumpOptions &DumpOpts) {
+ StringMap<unsigned> SectionAmountMap;
+ std::vector<StringRef> SectionNames;
+ if (Obj.getFile() && !DumpOpts.Brief) {
+ for (const SectionRef &Section : Obj.getFile()->sections()) {
+ StringRef Name;
+ if (Section.getName(Name))
+ Name = "<error>";
+
+ ++SectionAmountMap[Name];
+ SectionNames.push_back(Name);
+ }
+ }
+
+ for (size_t I = 0; I < Ranges.size(); ++I) {
+ const DWARFAddressRange &R = Ranges[I];
+
OS << '\n';
OS.indent(Indent);
- OS << format("[0x%0*" PRIx64 " - 0x%0*" PRIx64 ")",
- AddressSize*2, Range.LowPC,
- AddressSize*2, Range.HighPC);
+ OS << format("[0x%0*" PRIx64 " - 0x%0*" PRIx64 ")", AddressSize * 2,
+ R.LowPC, AddressSize * 2, R.HighPC);
+
+ if (SectionNames.empty() || R.SectionIndex == -1ULL)
+ continue;
+
+ StringRef Name = R.SectionIndex < SectionNames.size()
+ ? SectionNames[R.SectionIndex]
+ : "<error>";
+ OS << format(" \"%s\"", Name.str().c_str());
+
+ // Print section index if there is more than one section with this name.
+ if (SectionAmountMap[Name] > 1)
+ OS << format(" [%u]", R.SectionIndex);
}
}
@@ -126,10 +153,11 @@ static void dumpAttribute(raw_ostream &O
if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant())
dumpApplePropertyAttribute(OS, *OptVal);
} else if (Attr == DW_AT_ranges) {
- dumpRanges(OS, Die.getAddressRanges(), U->getAddressByteSize(),
- sizeof(BaseIndent)+Indent+4);
+ const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
+ dumpRanges(Obj, OS, Die.getAddressRanges(), U->getAddressByteSize(),
+ sizeof(BaseIndent) + Indent + 4, DumpOpts);
}
-
+
OS << ")\n";
}
Modified: llvm/trunk/test/DebugInfo/X86/dwarfdump-ranges-unrelocated.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dwarfdump-ranges-unrelocated.s?rev=310915&r1=310914&r2=310915&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dwarfdump-ranges-unrelocated.s (original)
+++ llvm/trunk/test/DebugInfo/X86/dwarfdump-ranges-unrelocated.s Tue Aug 15 05:32:54 2017
@@ -1,12 +1,28 @@
# RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %s -o %t
# RUN: llvm-dwarfdump %t | FileCheck %s
+# CHECK: .debug_info contents:
+# CHECK: DW_TAG_compile_unit
+# CHECK: DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
+# CHECK-NEXT: [0x0000000000000000 - 0x0000000000000001) ".text.foo1"
+# CHECK-NEXT: [0x0000000000000000 - 0x0000000000000002) ".text.foo2" [4]
+# CHECK-NEXT: [0x0000000000000000 - 0x0000000000000003) ".text.foo2" [5])
+
# CHECK: .debug_ranges contents:
# CHECK: 00000000 0000000000000000 0000000000000001
# CHECK: 00000000 0000000000000000 0000000000000002
+# CHECK: 00000000 0000000000000000 0000000000000003
# CHECK: 00000000 <End of list>
-## Asm code for testcase is a reduced output from next invocation and source:
+# RUN: llvm-dwarfdump -brief=true %t | FileCheck %s --check-prefix=BRIEF
+# BRIEF: DW_TAG_compile_unit
+# BRIEF: DW_AT_ranges (0x00000000
+# BRIEF-NEXT: [0x0000000000000000 - 0x0000000000000001)
+# BRIEF-NEXT: [0x0000000000000000 - 0x0000000000000002)
+# BRIEF-NEXT: [0x0000000000000000 - 0x0000000000000003))
+
+## Asm code for testcase is a reduced and modified output from next
+## invocation and source:
# clang test.cpp -S -o test.s -gmlt -ffunction-sections
# test.cpp:
# void foo1() { }
@@ -17,12 +33,19 @@
nop
.Lfunc_end0:
-.section .text.foo2,"ax", at progbits
+.section .text.foo2,"ax", at progbits, unique, 1
.Lfunc_begin1:
nop
nop
.Lfunc_end1:
+.section .text.foo2,"ax", at progbits, unique, 2
+.Lfunc_begin2:
+ nop
+ nop
+ nop
+.Lfunc_end2:
+
.section .debug_abbrev,"", at progbits
.byte 1 # Abbreviation Code
.byte 17 # DW_TAG_compile_unit
@@ -66,5 +89,7 @@
.quad .Lfunc_end0
.quad .Lfunc_begin1
.quad .Lfunc_end1
+.quad .Lfunc_begin2
+.quad .Lfunc_end2
.quad 0
.quad 0
More information about the llvm-commits
mailing list