llvm.org GIT mirror llvm / 438f539
llvm-dwarfdump/libDebugInfo support for type units git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191234 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 7 years ago
9 changed file(s) with 172 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
103103 DIDT_Frames,
104104 DIDT_Info,
105105 DIDT_InfoDwo,
106 DIDT_Types,
106107 DIDT_Line,
107108 DIDT_Loc,
108109 DIDT_Ranges,
1111 DWARFDebugLoc.cpp
1212 DWARFDebugRangeList.cpp
1313 DWARFFormValue.cpp
14 DWARFTypeUnit.cpp
1415 DWARFUnit.cpp
1516 )
3939 getCompileUnitAtIndex(i)->dump(OS);
4040 }
4141
42 if (DumpType == DIDT_All || DumpType == DIDT_Types) {
43 OS << "\n.debug_types contents:\n";
44 for (unsigned i = 0, e = getNumTypeUnits(); i != e; ++i)
45 getTypeUnitAtIndex(i)->dump(OS);
46 }
47
4248 if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
43 OS << ".debug_loc contents:\n";
49 OS << "\n.debug_loc contents:\n";
4450 getDebugLoc()->dump(OS);
4551 }
4652
283289 }
284290 CUs.push_back(CU.take());
285291 offset = CUs.back()->getNextUnitOffset();
292 }
293 }
294
295 void DWARFContext::parseTypeUnits() {
296 const std::map &Sections = getTypesSections();
297 for (std::map::const_iterator
298 I = Sections.begin(),
299 E = Sections.end();
300 I != E; ++I) {
301 uint32_t offset = 0;
302 const DataExtractor &DIData =
303 DataExtractor(I->second.Data, isLittleEndian(), 0);
304 while (DIData.isValidOffset(offset)) {
305 OwningPtr TU(new DWARFTypeUnit(
306 getDebugAbbrev(), I->second.Data, getAbbrevSection(),
307 getRangeSection(), getStringSection(), StringRef(), getAddrSection(),
308 &I->second.Relocs, isLittleEndian()));
309 if (!TU->extract(DIData, &offset))
310 break;
311 TUs.push_back(TU.take());
312 offset = TUs.back()->getNextUnitOffset();
313 }
286314 }
287315 }
288316
596624 // FIXME: Use the other dwo range section when we emit it.
597625 RangeDWOSection = data;
598626 }
627 } else if (name == "debug_types") {
628 TypesSections[*i].Data = data;
599629 }
600630
601631 section_iterator RelocatedSection = i->getRelocatedSection();
615645 .Case("debug_info.dwo", &InfoDWOSection.Relocs)
616646 .Case("debug_line", &LineSection.Relocs)
617647 .Default(0);
618 if (!Map)
619 continue;
648 if (!Map) {
649 if (RelSecName != "debug_types")
650 continue;
651 Map = &TypesSections[*RelocatedSection].Relocs;
652 }
620653
621654 if (i->begin_relocations() != i->end_relocations()) {
622655 uint64_t SectionSize;
1515 #include "DWARFDebugLine.h"
1616 #include "DWARFDebugLoc.h"
1717 #include "DWARFDebugRangeList.h"
18 #include "DWARFTypeUnit.h"
1819 #include "llvm/ADT/OwningPtr.h"
1920 #include "llvm/ADT/SmallVector.h"
2021 #include "llvm/DebugInfo/DIContext.h"
2728 /// methods that a concrete implementation provides.
2829 class DWARFContext : public DIContext {
2930 SmallVector CUs;
31 SmallVector TUs;
3032 OwningPtr Abbrev;
3133 OwningPtr Loc;
3234 OwningPtr Aranges;
4244 /// Read compile units from the debug_info section and store them in CUs.
4345 void parseCompileUnits();
4446
47 /// Read type units from the debug_types sections and store them in CUs.
48 void parseTypeUnits();
49
4550 /// Read compile units from the debug_info.dwo section and store them in
4651 /// DWOCUs.
4752 void parseDWOCompileUnits();
6873 return CUs.size();
6974 }
7075
76 /// Get the number of compile units in this context.
77 unsigned getNumTypeUnits() {
78 if (TUs.empty())
79 parseTypeUnits();
80 return TUs.size();
81 }
82
7183 /// Get the number of compile units in the DWO context.
7284 unsigned getNumDWOCompileUnits() {
7385 if (DWOCUs.empty())
8092 if (CUs.empty())
8193 parseCompileUnits();
8294 return CUs[index];
95 }
96
97 /// Get the type unit at the specified index for this compile unit.
98 DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
99 if (TUs.empty())
100 parseTypeUnits();
101 return TUs[index];
83102 }
84103
85104 /// Get the compile unit at the specified index for the DWO compile units.
118137 virtual bool isLittleEndian() const = 0;
119138 virtual uint8_t getAddressSize() const = 0;
120139 virtual const Section &getInfoSection() = 0;
140 virtual const std::map &getTypesSections() = 0;
121141 virtual StringRef getAbbrevSection() = 0;
122142 virtual const Section &getLocSection() = 0;
123143 virtual StringRef getARangeSection() = 0;
156176 bool IsLittleEndian;
157177 uint8_t AddressSize;
158178 Section InfoSection;
179 std::map TypesSections;
159180 StringRef AbbrevSection;
160181 Section LocSection;
161182 StringRef ARangeSection;
182203 virtual bool isLittleEndian() const { return IsLittleEndian; }
183204 virtual uint8_t getAddressSize() const { return AddressSize; }
184205 virtual const Section &getInfoSection() { return InfoSection; }
206 virtual const std::map &getTypesSections() {
207 return TypesSections;
208 }
185209 virtual StringRef getAbbrevSection() { return AbbrevSection; }
186210 virtual const Section &getLocSection() { return LocSection; }
187211 virtual StringRef getARangeSection() { return ARangeSection; }
0 //===-- DWARFTypeUnit.cpp -------------------------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "DWARFTypeUnit.h"
10 #include "llvm/Support/Format.h"
11 #include "llvm/Support/raw_ostream.h"
12
13 using namespace llvm;
14
15 bool DWARFTypeUnit::extractImpl(DataExtractor debug_info,
16 uint32_t *offset_ptr) {
17 if (!DWARFUnit::extractImpl(debug_info, offset_ptr))
18 return false;
19 TypeHash = debug_info.getU64(offset_ptr);
20 TypeOffset = debug_info.getU32(offset_ptr);
21 return TypeOffset < getLength();
22 }
23
24 void DWARFTypeUnit::dump(raw_ostream &OS) {
25 OS << format("0x%08x", getOffset()) << ": Type Unit:"
26 << " length = " << format("0x%08x", getLength())
27 << " version = " << format("0x%04x", getVersion())
28 << " abbr_offset = " << format("0x%04x", getAbbreviations()->getOffset())
29 << " addr_size = " << format("0x%02x", getAddressByteSize())
30 << " type_signature = " << format("0x%16lx", TypeHash)
31 << " type_offset = " << format("0x%04x", TypeOffset)
32 << " (next unit at " << format("0x%08x", getNextUnitOffset())
33 << ")\n";
34
35 const DWARFDebugInfoEntryMinimal *CU = getCompileUnitDIE(false);
36 assert(CU && "Null Compile Unit?");
37 CU->dump(OS, this, -1U);
38 }
0 //===-- DWARFTypeUnit.h -----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_DWARFTYPEUNIT_H
10 #define LLVM_DEBUGINFO_DWARFTYPEUNIT_H
11
12 #include "DWARFUnit.h"
13
14 namespace llvm {
15
16 class DWARFTypeUnit : public DWARFUnit {
17 private:
18 uint64_t TypeHash;
19 uint32_t TypeOffset;
20 public:
21 DWARFTypeUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS,
22 StringRef RS, StringRef SS, StringRef SOS, StringRef AOS,
23 const RelocAddrMap *M, bool LE)
24 : DWARFUnit(DA, IS, AS, RS, SS, SOS, AOS, M, LE) {}
25 uint32_t getSize() const LLVM_OVERRIDE { return DWARFUnit::getSize() + 12; }
26 void dump(raw_ostream &OS);
27 protected:
28 bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) LLVM_OVERRIDE;
29 };
30
31 }
32
33 #endif
34
0 struct foo {};
1 struct bar {};
2 void sink(void*);
3 int main() {
4 foo f;
5 sink(&f);
6 bar b;
7 sink(&b);
8 }
9
10 // Built with GCC 4.8.1
11 // $ mkdir -p /tmp/dbginfo
12 // $ cp dwarfdump-type-units.cc /tmp/dbginfo
13 // $ cd /tmp/dbginfo
14 // $ g++-4.8.1 -g -fdebug-types-section -c dwarfdump-type-units.cc -o dwarfdump-type-units.elf-x86-64
0 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-type-units.elf-x86-64 | FileCheck %s
1
2 CHECK: debug_info contents:
3 CHECK: DW_TAG_variable
4 CHECK-NEXT: DW_AT_name {{.*}}"f"
5 CHECK: DW_AT_type [DW_FORM_ref_sig8] ([[FOO_SIG:0x[0-9a-f]*]])
6 CHECK: DW_TAG_variable
7 CHECK-NEXT: DW_AT_name {{.*}}"b"
8 CHECK: DW_AT_type [DW_FORM_ref_sig8] ([[BAR_SIG:0x[0-9a-f]*]])
9
10 CHECK: debug_types contents:
11 CHECK: 0x00000000: Type Unit: {{.*}} type_signature = [[FOO_SIG]] type_offset = 0x[[FOO_OFF:[0-9a-f]*]] (next unit at
12 CHECK: DW_TAG_type_unit
13 CHECK-NOT: NULL
14 CHECK: 0x0000[[FOO_OFF]]: DW_TAG_structure_type
15 CHECK-NEXT: DW_AT_name {{.*}}"foo"
16 CHECK: 0x00000000: Type Unit: {{.*}} type_signature = [[BAR_SIG]] type_offset = 0x[[BAR_OFF:[0-9a-f]*]] (next unit at
17 CHECK: DW_TAG_type_unit
18 CHECK-NOT: NULL
19 CHECK: 0x0000[[BAR_OFF]]: DW_TAG_structure_type
20 CHECK-NEXT: DW_AT_name {{.*}}"bar"