dwarfdump: Delay parsing abbreviations until they're needed

This speeds up dumping specific DIEs by not parsing abbreviations for
units that are not used.

(this is also handy to have in eventually to speed up llvm-symbolizer
for .dwp files, where parsing most of the DWP file can be avoided by
using the index)

llvm-svn: 313635
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
index 813960c..4467b4a 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -94,7 +94,6 @@
   // FIXME: Support DWARF64.
   FormParams.Format = DWARF32;
   FormParams.Version = debug_info.getU16(offset_ptr);
-  uint64_t AbbrOffset;
   if (FormParams.Version >= 5) {
     UnitType = debug_info.getU8(offset_ptr);
     FormParams.AddrSize = debug_info.getU8(offset_ptr);
@@ -124,9 +123,7 @@
 
   // Keep track of the highest DWARF version we encounter across all units.
   Context.setMaxVersionIfGreater(getVersion());
-
-  Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset);
-  return Abbrevs != nullptr;
+  return true;
 }
 
 bool DWARFUnit::extract(DataExtractor debug_info, uint32_t *offset_ptr) {
@@ -452,3 +449,9 @@
   }
   return DWARFDie();
 }
+
+const DWARFAbbreviationDeclarationSet *DWARFUnit::getAbbreviations() const {
+  if (!Abbrevs)
+    Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset);
+  return Abbrevs;
+}