From e527986a9c72e0ac5fb69a68bf2a7191bebbb68e Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Mon, 28 Feb 2022 18:03:07 -0800 Subject: [PATCH] [llvm-pdbutil] Fix crashes when TypeIndex is simple or doesn't exist in type stream - 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 | 11 +++++++++++ llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp | 14 ++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/llvm/test/tools/llvm-pdbutil/partial-type-stream.test b/llvm/test/tools/llvm-pdbutil/partial-type-stream.test index 5a72b62..c007465 100644 --- a/llvm/test/tools/llvm-pdbutil/partial-type-stream.test +++ b/llvm/test/tools/llvm-pdbutil/partial-type-stream.test @@ -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 diff --git a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp index 0e4f103..a3502c4 100644 --- a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp +++ b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp @@ -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 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); + } } } } -- 2.7.4