summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2017-10-10 14:15:25 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2017-10-10 14:15:25 +0000
commitaa6be823a450abbcabbf4241a59bffc1d4ce3143 (patch)
tree3409e3298c3b3f26c57229859dce09b667ed2c88 /llvm/lib/DebugInfo
parent2a0c4f57dd33c5187ed6d85f2d5be39701fe1692 (diff)
downloadbcm5719-llvm-aa6be823a450abbcabbf4241a59bffc1d4ce3143.tar.gz
bcm5719-llvm-aa6be823a450abbcabbf4241a59bffc1d4ce3143.zip
Re-land "[llvm-dwarfdump] Print type names in DW_AT_type DIEs"
This patch adds printing for DW_AT_type DIEs like it is already the case for DW_AT_specification DIEs. This is a rather naive approach and only a start. We should have pretty printers for different languages. Recommit after being reverted in r315299. Differential revision: https://reviews.llvm.org/D36993 llvm-svn: 315316
Diffstat (limited to 'llvm/lib/DebugInfo')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFDie.cpp68
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp4
2 files changed, 66 insertions, 6 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index d2890d6139d..1b5744e8bea 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -124,6 +124,64 @@ static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
}
}
+/// Dump the name encoded in the type tag.
+static void dumpTypeTagName(raw_ostream &OS, dwarf::Tag T) {
+ StringRef TagStr = TagString(T);
+ if (!TagStr.startswith("DW_TAG_") || !TagStr.endswith("_type"))
+ return;
+ OS << TagStr.substr(7, TagStr.size() - 12) << " ";
+}
+
+/// Recursively dump the DIE type name when applicable.
+static void dumpTypeName(raw_ostream &OS, const DWARFDie &Die) {
+ DWARFDie D = Die.getAttributeValueAsReferencedDie(DW_AT_type);
+
+ if (!D.isValid())
+ return;
+
+ if (const char *Name = D.getName(DINameKind::LinkageName)) {
+ OS << Name;
+ return;
+ }
+
+ // FIXME: We should have pretty printers per language. Currently we print
+ // everything as if it was C++ and fall back to the TAG type name.
+ const dwarf::Tag T = D.getTag();
+ switch (T) {
+ case DW_TAG_array_type:
+ case DW_TAG_pointer_type:
+ case DW_TAG_ptr_to_member_type:
+ case DW_TAG_reference_type:
+ case DW_TAG_rvalue_reference_type:
+ break;
+ default:
+ dumpTypeTagName(OS, T);
+ }
+
+ // Follow the DW_AT_type if possible.
+ dumpTypeName(OS, D);
+
+ switch (T) {
+ case DW_TAG_array_type:
+ OS << "[]";
+ break;
+ case DW_TAG_pointer_type:
+ OS << '*';
+ break;
+ case DW_TAG_ptr_to_member_type:
+ OS << '*';
+ break;
+ case DW_TAG_reference_type:
+ OS << '&';
+ break;
+ case DW_TAG_rvalue_reference_type:
+ OS << "&&";
+ break;
+ default:
+ break;
+ }
+}
+
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
uint32_t *OffsetPtr, dwarf::Attribute Attr,
dwarf::Form Form, unsigned Indent,
@@ -188,6 +246,10 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
if (const char *Name = Die.getAttributeValueAsReferencedDie(Attr).getName(
DINameKind::LinkageName))
OS << " \"" << Name << '\"';
+ } else if (Attr == DW_AT_type) {
+ OS << " \"";
+ dumpTypeName(OS, Die);
+ OS << '"';
} else if (Attr == DW_AT_APPLE_property_attribute) {
if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant())
dumpApplePropertyAttribute(OS, *OptVal);
@@ -250,10 +312,8 @@ DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {
DWARFDie
DWARFDie::getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const {
- auto SpecRef = toReference(find(Attr));
- if (SpecRef) {
- auto SpecUnit = U->getUnitSection().getUnitForOffset(*SpecRef);
- if (SpecUnit)
+ if (auto SpecRef = toReference(find(Attr))) {
+ if (auto SpecUnit = U->getUnitSection().getUnitForOffset(*SpecRef))
return SpecUnit->getDIEForOffset(*SpecRef);
}
return DWARFDie();
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index bec6e922ceb..b10697c9a31 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -262,6 +262,8 @@ bool DWARFVerifier::handleDebugInfo() {
bool isUnitDWARF64 = false;
bool isHeaderChainValid = true;
bool hasDIE = DebugInfoData.isValidOffset(Offset);
+ DWARFUnitSection<DWARFTypeUnit> TUSection{};
+ DWARFUnitSection<DWARFCompileUnit> CUSection{};
while (hasDIE) {
OffsetStart = Offset;
if (!verifyUnitHeader(DebugInfoData, &Offset, UnitIdx, UnitType,
@@ -274,7 +276,6 @@ bool DWARFVerifier::handleDebugInfo() {
switch (UnitType) {
case dwarf::DW_UT_type:
case dwarf::DW_UT_split_type: {
- DWARFUnitSection<DWARFTypeUnit> TUSection{};
Unit.reset(new DWARFTypeUnit(
DCtx, DObj.getInfoSection(), DCtx.getDebugAbbrev(),
&DObj.getRangeSection(), DObj.getStringSection(),
@@ -290,7 +291,6 @@ bool DWARFVerifier::handleDebugInfo() {
// UnitType = 0 means that we are
// verifying a compile unit in DWARF v4.
case 0: {
- DWARFUnitSection<DWARFCompileUnit> CUSection{};
Unit.reset(new DWARFCompileUnit(
DCtx, DObj.getInfoSection(), DCtx.getDebugAbbrev(),
&DObj.getRangeSection(), DObj.getStringSection(),
OpenPOWER on IntegriCloud