llvm.org GIT mirror llvm / 03937ca
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310915 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 2 years ago
5 changed file(s) with 82 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
2626 public:
2727 virtual ~DWARFObject() = default;
2828 virtual StringRef getFileName() const { llvm_unreachable("unimplemented"); }
29 virtual const object::ObjectFile *getFile() const { return nullptr; }
2930 virtual bool isLittleEndian() const = 0;
3031 virtual uint8_t getAddressSize() const { llvm_unreachable("unimplemented"); }
3132 virtual const DWARFSection &getInfoSection() const { return Dummy; }
932932 bool IsLittleEndian;
933933 uint8_t AddressSize;
934934 StringRef FileName;
935 const object::ObjectFile *Obj = nullptr;
935936
936937 using TypeSectionMap = MapVector
937938 std::map>;
10501051 DWARFObjInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
10511052 function_ref HandleError)
10521053 : IsLittleEndian(Obj.isLittleEndian()),
1053 AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()) {
1054 AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()),
1055 Obj(&Obj) {
10541056
10551057 for (const SectionRef &Section : Obj.sections()) {
10561058 StringRef Name;
11871189 return AI->second;
11881190 }
11891191
1192 const object::ObjectFile *getFile() const override { return Obj; }
1193
11901194 bool isLittleEndian() const override { return IsLittleEndian; }
11911195 StringRef getAbbrevDWOSection() const override { return AbbrevDWOSection; }
11921196 const DWARFSection &getLineDWOSection() const override {
3232 return false;
3333 Offset = *offset_ptr;
3434 while (true) {
35 RangeListEntry entry;
35 RangeListEntry Entry;
36 Entry.SectionIndex = -1ULL;
37
3638 uint32_t prev_offset = *offset_ptr;
37 entry.StartAddress =
38 data.getRelocatedAddress(offset_ptr, &entry.SectionIndex);
39 entry.EndAddress = data.getRelocatedAddress(offset_ptr);
39 Entry.StartAddress = data.getRelocatedAddress(offset_ptr);
40 Entry.EndAddress =
41 data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex);
4042
4143 // Check that both values were extracted correctly.
4244 if (*offset_ptr != prev_offset + 2 * AddressSize) {
4345 clear();
4446 return false;
4547 }
46 if (entry.isEndOfListEntry())
48 if (Entry.isEndOfListEntry())
4749 break;
48 Entries.push_back(entry);
50 Entries.push_back(Entry);
4951 }
5052 return true;
5153 }
1717 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
1818 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1919 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
20 #include "llvm/Object/ObjectFile.h"
2021 #include "llvm/Support/DataExtractor.h"
2122 #include "llvm/Support/Format.h"
2223 #include "llvm/Support/MathExtras.h"
3031
3132 using namespace llvm;
3233 using namespace dwarf;
34 using namespace object;
3335 using namespace syntax;
3436
3537 static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
5052 OS << ")";
5153 }
5254
53 static void dumpRanges(raw_ostream &OS, const DWARFAddressRangesVector& Ranges,
54 unsigned AddressSize, unsigned Indent) {
55 if (Ranges.empty())
56 return;
57
58 for (const auto &Range: Ranges) {
55 static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS,
56 const DWARFAddressRangesVector &Ranges,
57 unsigned AddressSize, unsigned Indent,
58 const DIDumpOptions &DumpOpts) {
59 StringMap SectionAmountMap;
60 std::vector SectionNames;
61 if (Obj.getFile() && !DumpOpts.Brief) {
62 for (const SectionRef &Section : Obj.getFile()->sections()) {
63 StringRef Name;
64 if (Section.getName(Name))
65 Name = "";
66
67 ++SectionAmountMap[Name];
68 SectionNames.push_back(Name);
69 }
70 }
71
72 for (size_t I = 0; I < Ranges.size(); ++I) {
73 const DWARFAddressRange &R = Ranges[I];
74
5975 OS << '\n';
6076 OS.indent(Indent);
61 OS << format("[0x%0*" PRIx64 " - 0x%0*" PRIx64 ")",
62 AddressSize*2, Range.LowPC,
63 AddressSize*2, Range.HighPC);
77 OS << format("[0x%0*" PRIx64 " - 0x%0*" PRIx64 ")", AddressSize * 2,
78 R.LowPC, AddressSize * 2, R.HighPC);
79
80 if (SectionNames.empty() || R.SectionIndex == -1ULL)
81 continue;
82
83 StringRef Name = R.SectionIndex < SectionNames.size()
84 ? SectionNames[R.SectionIndex]
85 : "";
86 OS << format(" \"%s\"", Name.str().c_str());
87
88 // Print section index if there is more than one section with this name.
89 if (SectionAmountMap[Name] > 1)
90 OS << format(" [%u]", R.SectionIndex);
6491 }
6592 }
6693
125152 if (Optional OptVal = formValue.getAsUnsignedConstant())
126153 dumpApplePropertyAttribute(OS, *OptVal);
127154 } else if (Attr == DW_AT_ranges) {
128 dumpRanges(OS, Die.getAddressRanges(), U->getAddressByteSize(),
129 sizeof(BaseIndent)+Indent+4);
130 }
131
155 const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
156 dumpRanges(Obj, OS, Die.getAddressRanges(), U->getAddressByteSize(),
157 sizeof(BaseIndent) + Indent + 4, DumpOpts);
158 }
159
132160 OS << ")\n";
133161 }
134162
0 # RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %s -o %t
11 # RUN: llvm-dwarfdump %t | FileCheck %s
2
3 # CHECK: .debug_info contents:
4 # CHECK: DW_TAG_compile_unit
5 # CHECK: DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
6 # CHECK-NEXT: [0x0000000000000000 - 0x0000000000000001) ".text.foo1"
7 # CHECK-NEXT: [0x0000000000000000 - 0x0000000000000002) ".text.foo2" [4]
8 # CHECK-NEXT: [0x0000000000000000 - 0x0000000000000003) ".text.foo2" [5])
29
310 # CHECK: .debug_ranges contents:
411 # CHECK: 00000000 0000000000000000 0000000000000001
512 # CHECK: 00000000 0000000000000000 0000000000000002
13 # CHECK: 00000000 0000000000000000 0000000000000003
614 # CHECK: 00000000
715
8 ## Asm code for testcase is a reduced output from next invocation and source:
16 # RUN: llvm-dwarfdump -brief=true %t | FileCheck %s --check-prefix=BRIEF
17 # BRIEF: DW_TAG_compile_unit
18 # BRIEF: DW_AT_ranges (0x00000000
19 # BRIEF-NEXT: [0x0000000000000000 - 0x0000000000000001)
20 # BRIEF-NEXT: [0x0000000000000000 - 0x0000000000000002)
21 # BRIEF-NEXT: [0x0000000000000000 - 0x0000000000000003))
22
23 ## Asm code for testcase is a reduced and modified output from next
24 ## invocation and source:
925 # clang test.cpp -S -o test.s -gmlt -ffunction-sections
1026 # test.cpp:
1127 # void foo1() { }
1632 nop
1733 .Lfunc_end0:
1834
19 .section .text.foo2,"ax",@progbits
35 .section .text.foo2,"ax",@progbits, unique, 1
2036 .Lfunc_begin1:
2137 nop
2238 nop
2339 .Lfunc_end1:
40
41 .section .text.foo2,"ax",@progbits, unique, 2
42 .Lfunc_begin2:
43 nop
44 nop
45 nop
46 .Lfunc_end2:
2447
2548 .section .debug_abbrev,"",@progbits
2649 .byte 1 # Abbreviation Code
6588 .quad .Lfunc_end0
6689 .quad .Lfunc_begin1
6790 .quad .Lfunc_end1
91 .quad .Lfunc_begin2
92 .quad .Lfunc_end2
6893 .quad 0
6994 .quad 0