mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-15 07:34:33 +00:00
llvm-dwarfdump/libDebugInfo support for type units
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191234 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cd7c4980d4
commit
438f5391b2
@ -104,6 +104,7 @@ enum DIDumpType {
|
|||||||
DIDT_Frames,
|
DIDT_Frames,
|
||||||
DIDT_Info,
|
DIDT_Info,
|
||||||
DIDT_InfoDwo,
|
DIDT_InfoDwo,
|
||||||
|
DIDT_Types,
|
||||||
DIDT_Line,
|
DIDT_Line,
|
||||||
DIDT_Loc,
|
DIDT_Loc,
|
||||||
DIDT_Ranges,
|
DIDT_Ranges,
|
||||||
|
@ -12,5 +12,6 @@ add_llvm_library(LLVMDebugInfo
|
|||||||
DWARFDebugLoc.cpp
|
DWARFDebugLoc.cpp
|
||||||
DWARFDebugRangeList.cpp
|
DWARFDebugRangeList.cpp
|
||||||
DWARFFormValue.cpp
|
DWARFFormValue.cpp
|
||||||
|
DWARFTypeUnit.cpp
|
||||||
DWARFUnit.cpp
|
DWARFUnit.cpp
|
||||||
)
|
)
|
||||||
|
@ -40,8 +40,14 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) {
|
|||||||
getCompileUnitAtIndex(i)->dump(OS);
|
getCompileUnitAtIndex(i)->dump(OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DumpType == DIDT_All || DumpType == DIDT_Types) {
|
||||||
|
OS << "\n.debug_types contents:\n";
|
||||||
|
for (unsigned i = 0, e = getNumTypeUnits(); i != e; ++i)
|
||||||
|
getTypeUnitAtIndex(i)->dump(OS);
|
||||||
|
}
|
||||||
|
|
||||||
if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
|
if (DumpType == DIDT_All || DumpType == DIDT_Loc) {
|
||||||
OS << ".debug_loc contents:\n";
|
OS << "\n.debug_loc contents:\n";
|
||||||
getDebugLoc()->dump(OS);
|
getDebugLoc()->dump(OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,6 +293,28 @@ void DWARFContext::parseCompileUnits() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DWARFContext::parseTypeUnits() {
|
||||||
|
const std::map<object::SectionRef, Section> &Sections = getTypesSections();
|
||||||
|
for (std::map<object::SectionRef, Section>::const_iterator
|
||||||
|
I = Sections.begin(),
|
||||||
|
E = Sections.end();
|
||||||
|
I != E; ++I) {
|
||||||
|
uint32_t offset = 0;
|
||||||
|
const DataExtractor &DIData =
|
||||||
|
DataExtractor(I->second.Data, isLittleEndian(), 0);
|
||||||
|
while (DIData.isValidOffset(offset)) {
|
||||||
|
OwningPtr<DWARFTypeUnit> TU(new DWARFTypeUnit(
|
||||||
|
getDebugAbbrev(), I->second.Data, getAbbrevSection(),
|
||||||
|
getRangeSection(), getStringSection(), StringRef(), getAddrSection(),
|
||||||
|
&I->second.Relocs, isLittleEndian()));
|
||||||
|
if (!TU->extract(DIData, &offset))
|
||||||
|
break;
|
||||||
|
TUs.push_back(TU.take());
|
||||||
|
offset = TUs.back()->getNextUnitOffset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DWARFContext::parseDWOCompileUnits() {
|
void DWARFContext::parseDWOCompileUnits() {
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
const DataExtractor &DIData =
|
const DataExtractor &DIData =
|
||||||
@ -597,6 +625,8 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
|
|||||||
// FIXME: Use the other dwo range section when we emit it.
|
// FIXME: Use the other dwo range section when we emit it.
|
||||||
RangeDWOSection = data;
|
RangeDWOSection = data;
|
||||||
}
|
}
|
||||||
|
} else if (name == "debug_types") {
|
||||||
|
TypesSections[*i].Data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
section_iterator RelocatedSection = i->getRelocatedSection();
|
section_iterator RelocatedSection = i->getRelocatedSection();
|
||||||
@ -616,8 +646,11 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
|
|||||||
.Case("debug_info.dwo", &InfoDWOSection.Relocs)
|
.Case("debug_info.dwo", &InfoDWOSection.Relocs)
|
||||||
.Case("debug_line", &LineSection.Relocs)
|
.Case("debug_line", &LineSection.Relocs)
|
||||||
.Default(0);
|
.Default(0);
|
||||||
if (!Map)
|
if (!Map) {
|
||||||
|
if (RelSecName != "debug_types")
|
||||||
continue;
|
continue;
|
||||||
|
Map = &TypesSections[*RelocatedSection].Relocs;
|
||||||
|
}
|
||||||
|
|
||||||
if (i->begin_relocations() != i->end_relocations()) {
|
if (i->begin_relocations() != i->end_relocations()) {
|
||||||
uint64_t SectionSize;
|
uint64_t SectionSize;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "DWARFDebugLine.h"
|
#include "DWARFDebugLine.h"
|
||||||
#include "DWARFDebugLoc.h"
|
#include "DWARFDebugLoc.h"
|
||||||
#include "DWARFDebugRangeList.h"
|
#include "DWARFDebugRangeList.h"
|
||||||
|
#include "DWARFTypeUnit.h"
|
||||||
#include "llvm/ADT/OwningPtr.h"
|
#include "llvm/ADT/OwningPtr.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/DebugInfo/DIContext.h"
|
#include "llvm/DebugInfo/DIContext.h"
|
||||||
@ -28,6 +29,7 @@ namespace llvm {
|
|||||||
/// methods that a concrete implementation provides.
|
/// methods that a concrete implementation provides.
|
||||||
class DWARFContext : public DIContext {
|
class DWARFContext : public DIContext {
|
||||||
SmallVector<DWARFCompileUnit *, 1> CUs;
|
SmallVector<DWARFCompileUnit *, 1> CUs;
|
||||||
|
SmallVector<DWARFTypeUnit *, 1> TUs;
|
||||||
OwningPtr<DWARFDebugAbbrev> Abbrev;
|
OwningPtr<DWARFDebugAbbrev> Abbrev;
|
||||||
OwningPtr<DWARFDebugLoc> Loc;
|
OwningPtr<DWARFDebugLoc> Loc;
|
||||||
OwningPtr<DWARFDebugAranges> Aranges;
|
OwningPtr<DWARFDebugAranges> Aranges;
|
||||||
@ -43,6 +45,9 @@ class DWARFContext : public DIContext {
|
|||||||
/// Read compile units from the debug_info section and store them in CUs.
|
/// Read compile units from the debug_info section and store them in CUs.
|
||||||
void parseCompileUnits();
|
void parseCompileUnits();
|
||||||
|
|
||||||
|
/// Read type units from the debug_types sections and store them in CUs.
|
||||||
|
void parseTypeUnits();
|
||||||
|
|
||||||
/// Read compile units from the debug_info.dwo section and store them in
|
/// Read compile units from the debug_info.dwo section and store them in
|
||||||
/// DWOCUs.
|
/// DWOCUs.
|
||||||
void parseDWOCompileUnits();
|
void parseDWOCompileUnits();
|
||||||
@ -69,6 +74,13 @@ public:
|
|||||||
return CUs.size();
|
return CUs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the number of compile units in this context.
|
||||||
|
unsigned getNumTypeUnits() {
|
||||||
|
if (TUs.empty())
|
||||||
|
parseTypeUnits();
|
||||||
|
return TUs.size();
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the number of compile units in the DWO context.
|
/// Get the number of compile units in the DWO context.
|
||||||
unsigned getNumDWOCompileUnits() {
|
unsigned getNumDWOCompileUnits() {
|
||||||
if (DWOCUs.empty())
|
if (DWOCUs.empty())
|
||||||
@ -83,6 +95,13 @@ public:
|
|||||||
return CUs[index];
|
return CUs[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the type unit at the specified index for this compile unit.
|
||||||
|
DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
|
||||||
|
if (TUs.empty())
|
||||||
|
parseTypeUnits();
|
||||||
|
return TUs[index];
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the compile unit at the specified index for the DWO compile units.
|
/// Get the compile unit at the specified index for the DWO compile units.
|
||||||
DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
|
DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
|
||||||
if (DWOCUs.empty())
|
if (DWOCUs.empty())
|
||||||
@ -119,6 +138,7 @@ public:
|
|||||||
virtual bool isLittleEndian() const = 0;
|
virtual bool isLittleEndian() const = 0;
|
||||||
virtual uint8_t getAddressSize() const = 0;
|
virtual uint8_t getAddressSize() const = 0;
|
||||||
virtual const Section &getInfoSection() = 0;
|
virtual const Section &getInfoSection() = 0;
|
||||||
|
virtual const std::map<object::SectionRef, Section> &getTypesSections() = 0;
|
||||||
virtual StringRef getAbbrevSection() = 0;
|
virtual StringRef getAbbrevSection() = 0;
|
||||||
virtual const Section &getLocSection() = 0;
|
virtual const Section &getLocSection() = 0;
|
||||||
virtual StringRef getARangeSection() = 0;
|
virtual StringRef getARangeSection() = 0;
|
||||||
@ -157,6 +177,7 @@ class DWARFContextInMemory : public DWARFContext {
|
|||||||
bool IsLittleEndian;
|
bool IsLittleEndian;
|
||||||
uint8_t AddressSize;
|
uint8_t AddressSize;
|
||||||
Section InfoSection;
|
Section InfoSection;
|
||||||
|
std::map<object::SectionRef, Section> TypesSections;
|
||||||
StringRef AbbrevSection;
|
StringRef AbbrevSection;
|
||||||
Section LocSection;
|
Section LocSection;
|
||||||
StringRef ARangeSection;
|
StringRef ARangeSection;
|
||||||
@ -183,6 +204,9 @@ public:
|
|||||||
virtual bool isLittleEndian() const { return IsLittleEndian; }
|
virtual bool isLittleEndian() const { return IsLittleEndian; }
|
||||||
virtual uint8_t getAddressSize() const { return AddressSize; }
|
virtual uint8_t getAddressSize() const { return AddressSize; }
|
||||||
virtual const Section &getInfoSection() { return InfoSection; }
|
virtual const Section &getInfoSection() { return InfoSection; }
|
||||||
|
virtual const std::map<object::SectionRef, Section> &getTypesSections() {
|
||||||
|
return TypesSections;
|
||||||
|
}
|
||||||
virtual StringRef getAbbrevSection() { return AbbrevSection; }
|
virtual StringRef getAbbrevSection() { return AbbrevSection; }
|
||||||
virtual const Section &getLocSection() { return LocSection; }
|
virtual const Section &getLocSection() { return LocSection; }
|
||||||
virtual StringRef getARangeSection() { return ARangeSection; }
|
virtual StringRef getARangeSection() { return ARangeSection; }
|
||||||
|
39
lib/DebugInfo/DWARFTypeUnit.cpp
Normal file
39
lib/DebugInfo/DWARFTypeUnit.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
//===-- DWARFTypeUnit.cpp -------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "DWARFTypeUnit.h"
|
||||||
|
#include "llvm/Support/Format.h"
|
||||||
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
|
bool DWARFTypeUnit::extractImpl(DataExtractor debug_info,
|
||||||
|
uint32_t *offset_ptr) {
|
||||||
|
if (!DWARFUnit::extractImpl(debug_info, offset_ptr))
|
||||||
|
return false;
|
||||||
|
TypeHash = debug_info.getU64(offset_ptr);
|
||||||
|
TypeOffset = debug_info.getU32(offset_ptr);
|
||||||
|
return TypeOffset < getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DWARFTypeUnit::dump(raw_ostream &OS) {
|
||||||
|
OS << format("0x%08x", getOffset()) << ": Type Unit:"
|
||||||
|
<< " length = " << format("0x%08x", getLength())
|
||||||
|
<< " version = " << format("0x%04x", getVersion())
|
||||||
|
<< " abbr_offset = " << format("0x%04x", getAbbreviations()->getOffset())
|
||||||
|
<< " addr_size = " << format("0x%02x", getAddressByteSize())
|
||||||
|
<< " type_signature = " << format("0x%16lx", TypeHash)
|
||||||
|
<< " type_offset = " << format("0x%04x", TypeOffset)
|
||||||
|
<< " (next unit at " << format("0x%08x", getNextUnitOffset())
|
||||||
|
<< ")\n";
|
||||||
|
|
||||||
|
const DWARFDebugInfoEntryMinimal *CU = getCompileUnitDIE(false);
|
||||||
|
assert(CU && "Null Compile Unit?");
|
||||||
|
CU->dump(OS, this, -1U);
|
||||||
|
}
|
35
lib/DebugInfo/DWARFTypeUnit.h
Normal file
35
lib/DebugInfo/DWARFTypeUnit.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
//===-- DWARFTypeUnit.h -----------------------------------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_DEBUGINFO_DWARFTYPEUNIT_H
|
||||||
|
#define LLVM_DEBUGINFO_DWARFTYPEUNIT_H
|
||||||
|
|
||||||
|
#include "DWARFUnit.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
|
||||||
|
class DWARFTypeUnit : public DWARFUnit {
|
||||||
|
private:
|
||||||
|
uint64_t TypeHash;
|
||||||
|
uint32_t TypeOffset;
|
||||||
|
public:
|
||||||
|
DWARFTypeUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS,
|
||||||
|
StringRef RS, StringRef SS, StringRef SOS, StringRef AOS,
|
||||||
|
const RelocAddrMap *M, bool LE)
|
||||||
|
: DWARFUnit(DA, IS, AS, RS, SS, SOS, AOS, M, LE) {}
|
||||||
|
uint32_t getSize() const LLVM_OVERRIDE { return DWARFUnit::getSize() + 12; }
|
||||||
|
void dump(raw_ostream &OS);
|
||||||
|
protected:
|
||||||
|
bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) LLVM_OVERRIDE;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
15
test/DebugInfo/Inputs/dwarfdump-type-units.cc
Normal file
15
test/DebugInfo/Inputs/dwarfdump-type-units.cc
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
struct foo {};
|
||||||
|
struct bar {};
|
||||||
|
void sink(void*);
|
||||||
|
int main() {
|
||||||
|
foo f;
|
||||||
|
sink(&f);
|
||||||
|
bar b;
|
||||||
|
sink(&b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Built with GCC 4.8.1
|
||||||
|
// $ mkdir -p /tmp/dbginfo
|
||||||
|
// $ cp dwarfdump-type-units.cc /tmp/dbginfo
|
||||||
|
// $ cd /tmp/dbginfo
|
||||||
|
// $ g++-4.8.1 -g -fdebug-types-section -c dwarfdump-type-units.cc -o dwarfdump-type-units.elf-x86-64
|
BIN
test/DebugInfo/Inputs/dwarfdump-type-units.elf-x86-64
Normal file
BIN
test/DebugInfo/Inputs/dwarfdump-type-units.elf-x86-64
Normal file
Binary file not shown.
21
test/DebugInfo/dwarfdump-type-units.test
Normal file
21
test/DebugInfo/dwarfdump-type-units.test
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
RUN: llvm-dwarfdump %p/Inputs/dwarfdump-type-units.elf-x86-64 | FileCheck %s
|
||||||
|
|
||||||
|
CHECK: debug_info contents:
|
||||||
|
CHECK: DW_TAG_variable
|
||||||
|
CHECK-NEXT: DW_AT_name {{.*}}"f"
|
||||||
|
CHECK: DW_AT_type [DW_FORM_ref_sig8] ([[FOO_SIG:0x[0-9a-f]*]])
|
||||||
|
CHECK: DW_TAG_variable
|
||||||
|
CHECK-NEXT: DW_AT_name {{.*}}"b"
|
||||||
|
CHECK: DW_AT_type [DW_FORM_ref_sig8] ([[BAR_SIG:0x[0-9a-f]*]])
|
||||||
|
|
||||||
|
CHECK: debug_types contents:
|
||||||
|
CHECK: 0x00000000: Type Unit: {{.*}} type_signature = [[FOO_SIG]] type_offset = 0x[[FOO_OFF:[0-9a-f]*]] (next unit at
|
||||||
|
CHECK: DW_TAG_type_unit
|
||||||
|
CHECK-NOT: NULL
|
||||||
|
CHECK: 0x0000[[FOO_OFF]]: DW_TAG_structure_type
|
||||||
|
CHECK-NEXT: DW_AT_name {{.*}}"foo"
|
||||||
|
CHECK: 0x00000000: Type Unit: {{.*}} type_signature = [[BAR_SIG]] type_offset = 0x[[BAR_OFF:[0-9a-f]*]] (next unit at
|
||||||
|
CHECK: DW_TAG_type_unit
|
||||||
|
CHECK-NOT: NULL
|
||||||
|
CHECK: 0x0000[[BAR_OFF]]: DW_TAG_structure_type
|
||||||
|
CHECK-NEXT: DW_AT_name {{.*}}"bar"
|
Loading…
x
Reference in New Issue
Block a user