[llvm-pdbutil] Fix crashes when TypeIndex is simple or doesn't exist in type stream
authorZequan Wu <zequanwu@google.com>
Tue, 1 Mar 2022 02:03:07 +0000 (18:03 -0800)
committerZequan Wu <zequanwu@google.com>
Tue, 1 Mar 2022 19:04:56 +0000 (11:04 -0800)
- Print simple TypeIndex
- Print error message when type doesn't exist.

Differential Revision: https://reviews.llvm.org/D120692

llvm/test/tools/llvm-pdbutil/partial-type-stream.test
llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp

index 5a72b62..c007465 100644 (file)
@@ -2,6 +2,8 @@
 ; RUN:     | FileCheck --check-prefix=NODEPS %s
 ; RUN: llvm-pdbutil dump -type-index=0x1019 -dependents -dont-resolve-forward-refs \
 ; RUN:     %p/Inputs/ClassLayoutTest.pdb | FileCheck --check-prefix=DEPS %s
+; RUN: llvm-pdbutil dump -type-index=0x3,0x30,0x44,0x74 \
+; RUN:     %p/Inputs/ClassLayoutTest.pdb | FileCheck --check-prefix=SIMPLE %s 
 
 
 NODEPS:                          Types (TPI Stream)
@@ -27,3 +29,12 @@ DEPS-NEXT:   0x1019 | LF_MFUNCTION [size = 28]
 DEPS-NEXT:            return type = 0x0003 (void), # args = 0, param list = 0x100E
 DEPS-NEXT:            class type = 0x1017, this type = 0x1018, this adjust = 0
 DEPS-NEXT:            calling conv = thiscall, options = None
+
+
+SIMPLE:                          Types (TPI Stream)
+SIMPLE-NEXT: ============================================================
+SIMPLE-NEXT:   Showing 4 records.
+SIMPLE-NEXT:   0x0003 (void) | void
+SIMPLE-NEXT:   0x0030 (bool) | bool
+SIMPLE-NEXT:   0x0044 (__float48) | __float48
+SIMPLE-NEXT:   0x0074 (int) | int
index 0e4f103..a3502c4 100644 (file)
@@ -1352,10 +1352,16 @@ static void dumpPartialTypeStream(LinePrinter &Printer,
 
     for (const auto &I : TiList) {
       TypeIndex TI(I);
-      CVType Type = Types.getType(TI);
-      if (auto EC = codeview::visitTypeRecord(Type, TI, V))
-        Printer.formatLine("An error occurred dumping type record {0}: {1}", TI,
-                           toString(std::move(EC)));
+      if (TI.isSimple()) {
+        Printer.formatLine("{0} | {1}", fmt_align(I, AlignStyle::Right, Width),
+                           Types.getTypeName(TI));
+      } else if (Optional<CVType> Type = Types.tryGetType(TI)) {
+        if (auto EC = codeview::visitTypeRecord(*Type, TI, V))
+          Printer.formatLine("An error occurred dumping type record {0}: {1}",
+                             TI, toString(std::move(EC)));
+      } else {
+        Printer.formatLine("Type {0} doesn't exist in TPI stream", TI);
+      }
     }
   }
 }