llvm-dwarfdump support for gnu_pubtypes

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191329 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp
index 0e45322..e629390 100644
--- a/lib/DebugInfo/DWARFContext.cpp
+++ b/lib/DebugInfo/DWARFContext.cpp
@@ -28,6 +28,28 @@
   DeleteContainerPointers(DWOCUs);
 }
 
+static void dumpPubSection(raw_ostream &OS, StringRef Name, StringRef Data,
+                           bool LittleEndian) {
+  OS << "\n." << Name << " contents:\n";
+  DataExtractor pubNames(Data, LittleEndian, 0);
+  uint32_t offset = 0;
+  OS << "Length:                " << pubNames.getU32(&offset) << "\n";
+  OS << "Version:               " << pubNames.getU16(&offset) << "\n";
+  OS << "Offset in .debug_info: " << pubNames.getU32(&offset) << "\n";
+  OS << "Size:                  " << pubNames.getU32(&offset) << "\n";
+  OS << "Offset     Linkage  Kind    Name\n";
+  while (offset < Data.size()) {
+    uint32_t dieRef = pubNames.getU32(&offset);
+    if (dieRef == 0)
+      break;
+    PubIndexEntryDescriptor desc(pubNames.getU8(&offset));
+    OS << format("0x%8.8x ", dieRef)
+       << format("%-8s", dwarf::GDBIndexEntryLinkageString(desc.Linkage)) << ' '
+       << dwarf::GDBIndexEntryKindString(desc.Kind) << " \""
+       << pubNames.getCStr(&offset) << "\"\n";
+  }
+}
+
 void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) {
   if (DumpType == DIDT_All || DumpType == DIDT_Abbrev) {
     OS << ".debug_abbrev contents:\n";
@@ -126,26 +148,13 @@
     }
   }
 
-  if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames) {
-    OS << "\n.debug_gnu_pubnames contents:\n";
-    DataExtractor pubNames(getGnuPubNamesSection(), isLittleEndian(), 0);
-    offset = 0;
-    OS << "Length:                " << pubNames.getU32(&offset) << "\n";
-    OS << "Version:               " << pubNames.getU16(&offset) << "\n";
-    OS << "Offset in .debug_info: " << pubNames.getU32(&offset) << "\n";
-    OS << "Size:                  " << pubNames.getU32(&offset) << "\n";
-    OS << "Offset     Linkage  Kind     Name\n";
-    while (offset < getGnuPubNamesSection().size()) {
-      uint32_t dieRef = pubNames.getU32(&offset);
-      if (dieRef == 0)
-        break;
-      PubIndexEntryDescriptor desc(pubNames.getU8(&offset));
-      OS << format("0x%8.8x ", dieRef)
-         << format("%-8s", dwarf::GDBIndexEntryLinkageString(desc.Linkage))
-         << ' ' << format("%-8s", dwarf::GDBIndexEntryKindString(desc.Kind))
-         << " \"" << pubNames.getCStr(&offset) << "\"\n";
-    }
-  }
+  if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames)
+    dumpPubSection(OS, "debug_gnu_pubnames", getGnuPubNamesSection(),
+                   isLittleEndian());
+
+  if (DumpType == DIDT_All || DumpType == DIDT_GnuPubtypes)
+    dumpPubSection(OS, "debug_gnu_pubtypes", getGnuPubTypesSection(),
+                   isLittleEndian());
 
   if (DumpType == DIDT_All || DumpType == DIDT_AbbrevDwo) {
     const DWARFDebugAbbrev *D = getDebugAbbrevDWO();
@@ -612,6 +621,7 @@
         .Case("debug_ranges", &RangeSection)
         .Case("debug_pubnames", &PubNamesSection)
         .Case("debug_gnu_pubnames", &GnuPubNamesSection)
+        .Case("debug_gnu_pubtypes", &GnuPubTypesSection)
         .Case("debug_info.dwo", &InfoDWOSection.Data)
         .Case("debug_abbrev.dwo", &AbbrevDWOSection)
         .Case("debug_str.dwo", &StringDWOSection)