diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -57,7 +57,6 @@ #undef DEBUG_TYPE #define DEBUG_TYPE "bolt" -LLVM_ATTRIBUTE_UNUSED static void printDie(const DWARFDie &DIE) { DIDumpOptions DumpOpts; DumpOpts.ShowForm = true; @@ -67,6 +66,28 @@ DIE.dump(dbgs(), 0, DumpOpts); } +/// Lazily parse DWARF DIE and print it out. +LLVM_ATTRIBUTE_UNUSED +static void printDie(DWARFUnit &DU, uint64_t DIEOffset) { + uint64_t OriginalOffsets = DIEOffset; + uint64_t NextCUOffset = DU.getNextUnitOffset(); + DWARFDataExtractor DebugInfoData = DU.getDebugInfoExtractor(); + DWARFDebugInfoEntry DIEEntry; + if (DIEEntry.extractFast(DU, &DIEOffset, DebugInfoData, NextCUOffset, 0)) { + if (const DWARFAbbreviationDeclaration *AbbrDecl = + DIEEntry.getAbbreviationDeclarationPtr()) { + DWARFDie DDie(&DU, &DIEEntry); + printDie(DDie); + } else { + dbgs() << "Failed to extract abbreviation for" + << Twine::utohexstr(OriginalOffsets) << "\n"; + } + } else { + dbgs() << "Failed to extract DIE for " << Twine::utohexstr(OriginalOffsets) + << " \n"; + } +} + namespace llvm { namespace bolt { /// Emits debug information into .debug_info or .debug_types section.