From 518cb2d5608b8bedb68c7e626d380a1531d17145 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Sun, 30 Sep 2018 16:19:18 +0000 Subject: [PATCH] [PDB] Add native support for dumping array types. llvm-svn: 343412 --- .../llvm/DebugInfo/PDB/Native/NativeTypeArray.h | 50 +++++++++++++++ llvm/lib/DebugInfo/PDB/CMakeLists.txt | 1 + llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp | 2 + llvm/lib/DebugInfo/PDB/Native/NativeTypeArray.cpp | 67 +++++++++++++++++++++ llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp | 5 ++ llvm/test/DebugInfo/PDB/Inputs/every-array.cpp | 37 ++++++++++++ llvm/test/DebugInfo/PDB/Inputs/every-array.pdb | Bin 0 -> 73728 bytes llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp | 13 ++++ llvm/tools/llvm-pdbutil/PrettyTypeDumper.h | 1 + llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp | 11 +++- llvm/tools/llvm-pdbutil/llvm-pdbutil.h | 1 + 11 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 llvm/include/llvm/DebugInfo/PDB/Native/NativeTypeArray.h create mode 100644 llvm/lib/DebugInfo/PDB/Native/NativeTypeArray.cpp create mode 100644 llvm/test/DebugInfo/PDB/Inputs/every-array.cpp create mode 100644 llvm/test/DebugInfo/PDB/Inputs/every-array.pdb diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/NativeTypeArray.h b/llvm/include/llvm/DebugInfo/PDB/Native/NativeTypeArray.h new file mode 100644 index 0000000..10e68e6 --- /dev/null +++ b/llvm/include/llvm/DebugInfo/PDB/Native/NativeTypeArray.h @@ -0,0 +1,50 @@ +//===- NativeTypeArray.h ------------------------------------------ C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEARRAY_H +#define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEARRAY_H + +#include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" + +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/PDBTypes.h" + +namespace llvm { +namespace pdb { + +class NativeSession; + +class NativeTypeArray : public NativeRawSymbol { +public: + NativeTypeArray(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, + codeview::ArrayRecord Record); + ~NativeTypeArray() override; + + void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const override; + + SymIndexId getArrayIndexTypeId() const override; + + bool isConstType() const override; + bool isUnalignedType() const override; + bool isVolatileType() const override; + + uint32_t getCount() const override; + SymIndexId getTypeId() const override; + uint64_t getLength() const override; + +protected: + codeview::ArrayRecord Record; + codeview::TypeIndex Index; +}; + +} // namespace pdb +} // namespace llvm + +#endif diff --git a/llvm/lib/DebugInfo/PDB/CMakeLists.txt b/llvm/lib/DebugInfo/PDB/CMakeLists.txt index 3ec5d05..ae79c9e 100644 --- a/llvm/lib/DebugInfo/PDB/CMakeLists.txt +++ b/llvm/lib/DebugInfo/PDB/CMakeLists.txt @@ -52,6 +52,7 @@ add_pdb_impl_folder(Native Native/NativeExeSymbol.cpp Native/NativeRawSymbol.cpp Native/NativeSymbolEnumerator.cpp + Native/NativeTypeArray.cpp Native/NativeTypeBuiltin.cpp Native/NativeTypeEnum.cpp Native/NativeTypeFunctionSig.cpp diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp index bcc2198..14a0fb4 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp @@ -41,6 +41,8 @@ NativeExeSymbol::findChildren(PDB_SymType Type) const { return std::unique_ptr(new NativeEnumModules(Session)); break; } + case PDB_SymType::ArrayType: + return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ARRAY); case PDB_SymType::Enum: return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM); case PDB_SymType::PointerType: diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeTypeArray.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeTypeArray.cpp new file mode 100644 index 0000000..a525617 --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/Native/NativeTypeArray.cpp @@ -0,0 +1,67 @@ +//===- NativeTypeArray.cpp - info about arrays ------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/Native/NativeTypeArray.h" + +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h" +#include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h" + +using namespace llvm; +using namespace llvm::codeview; +using namespace llvm::pdb; + +NativeTypeArray::NativeTypeArray(NativeSession &Session, SymIndexId Id, + codeview::TypeIndex TI, + codeview::ArrayRecord Record) + : NativeRawSymbol(Session, PDB_SymType::ArrayType, Id), Record(Record), + Index(TI) {} +NativeTypeArray::~NativeTypeArray() {} + +void NativeTypeArray::dump(raw_ostream &OS, int Indent, + PdbSymbolIdField ShowIdFields, + PdbSymbolIdField RecurseIdFields) const { + NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields); + + dumpSymbolField(OS, "arrayIndexTypeId", getArrayIndexTypeId(), Indent); + dumpSymbolIdField(OS, "elementTypeId", getTypeId(), Indent, Session, + PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields); + + dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session, + PdbSymbolIdField::LexicalParent, ShowIdFields, + RecurseIdFields); + dumpSymbolField(OS, "length", getLength(), Indent); + dumpSymbolField(OS, "count", getCount(), Indent); + dumpSymbolField(OS, "constType", isConstType(), Indent); + dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent); + dumpSymbolField(OS, "volatileType", isVolatileType(), Indent); +} + +SymIndexId NativeTypeArray::getArrayIndexTypeId() const { + return Session.getSymbolCache().findSymbolByTypeIndex(Record.getIndexType()); +} + +bool NativeTypeArray::isConstType() const { return false; } + +bool NativeTypeArray::isUnalignedType() const { return false; } + +bool NativeTypeArray::isVolatileType() const { return false; } + +uint32_t NativeTypeArray::getCount() const { + NativeRawSymbol &Element = + Session.getSymbolCache().getNativeSymbolById(getTypeId()); + return getLength() / Element.getLength(); +} + +SymIndexId NativeTypeArray::getTypeId() const { + return Session.getSymbolCache().findSymbolByTypeIndex( + Record.getElementType()); +} + +uint64_t NativeTypeArray::getLength() const { return Record.Size; } \ No newline at end of file diff --git a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp index d4732fd..40b352a 100644 --- a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp @@ -7,6 +7,7 @@ #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h" #include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h" #include "llvm/DebugInfo/PDB/Native/NativeSession.h" +#include "llvm/DebugInfo/PDB/Native/NativeTypeArray.h" #include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h" #include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h" #include "llvm/DebugInfo/PDB/Native/NativeTypeFunctionSig.h" @@ -168,6 +169,10 @@ SymIndexId SymbolCache::findSymbolByTypeIndex(codeview::TypeIndex Index) { case codeview::LF_ENUM: Id = createSymbolForType(Index, std::move(CVT)); break; + case codeview::LF_ARRAY: + Id = createSymbolForType(Index, + std::move(CVT)); + break; case codeview::LF_CLASS: case codeview::LF_STRUCTURE: case codeview::LF_INTERFACE: diff --git a/llvm/test/DebugInfo/PDB/Inputs/every-array.cpp b/llvm/test/DebugInfo/PDB/Inputs/every-array.cpp new file mode 100644 index 0000000..28e07a0 --- /dev/null +++ b/llvm/test/DebugInfo/PDB/Inputs/every-array.cpp @@ -0,0 +1,37 @@ +// Build with "cl.exe /Zi /GR- /GX- every-array.cpp /link /debug /nodefaultlib /entry:main" + +// clang-format off +void *__purecall = 0; + +void __cdecl operator delete(void *,unsigned int) {} +void __cdecl operator delete(void *,unsigned __int64) {} + + +int func1() { return 42; } +int func2() { return 43; } +int func3() { return 44; } + +template +void Reference(T &t) { } + +int IA[3] = {1, 2, 3}; +const int CIA[3] = {1, 2, 3}; +volatile int VIA[3] = {1, 2, 3}; + +using FuncPtr = decltype(&func1); +FuncPtr FA[3] = {&func1, &func2, &func3}; + +struct S { + int N; + int f() const { return 42; } +}; + +using MemDataPtr = decltype(&S::N); +using MemFunPtr = decltype(&S::f); + +MemDataPtr MDA[1] = {&S::N}; +MemFunPtr MFA[1] = {&S::f}; + + +int main(int argc, char **argv) { +} diff --git a/llvm/test/DebugInfo/PDB/Inputs/every-array.pdb b/llvm/test/DebugInfo/PDB/Inputs/every-array.pdb new file mode 100644 index 0000000000000000000000000000000000000000..a3a84b1002dd2c3d9aaed0edf717e07f7eafa023 GIT binary patch literal 73728 zcmeI5Uu;yz6~^c8+JJ5B?7A^UZj#=#P(>u{8jL7KG+YCwpyI~FAtk9>yx41SSnn?D zHG!z5u1YGkks?2ks+CfSheYZ_+UB8E)l^Dp)k;y-hdk1XNO?$~qAG&+F$(>@xijl) z2Mod}i13Ykc4p2w^Y3^4GXL%!m>8{9rYht0aA$t!!w-i8L%YK-=X!eDTf27+8H9{6 zDMX!+I`atWIMS~Oh=2%)fCz|y2#A0Ph=2%)fCz}d9YWxWf(VF!2#A0Ph=2%)fCz|y z2#A0Ph`^_wfH5C_>c^-7ihu}+fCz|y2#A0Ph=2%)fCz}d-A*8Thn!PTH$^}ML_h>Y zKmYKm=}{0M|dd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s"); + if (opts::pretty::Arrays) + dumpSymbolCategory(Printer, Exe, *this, "Arrays"); + if (opts::pretty::Pointers) dumpSymbolCategory(Printer, Exe, *this, "Pointers"); @@ -284,6 +288,15 @@ void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) { Dumper.start(Symbol); } +void TypeDumper::dump(const PDBSymbolTypeArray &Symbol) { + auto ElementType = Symbol.getElementType(); + + ElementType->dump(*this); + Printer << "["; + WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Symbol.getCount(); + Printer << "]"; +} + void TypeDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) { FunctionDumper Dumper(Printer); Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None); diff --git a/llvm/tools/llvm-pdbutil/PrettyTypeDumper.h b/llvm/tools/llvm-pdbutil/PrettyTypeDumper.h index cb6fcb1..e63ebe0 100644 --- a/llvm/tools/llvm-pdbutil/PrettyTypeDumper.h +++ b/llvm/tools/llvm-pdbutil/PrettyTypeDumper.h @@ -26,6 +26,7 @@ public: void dump(const PDBSymbolTypeEnum &Symbol) override; void dump(const PDBSymbolTypeTypedef &Symbol) override; void dump(const PDBSymbolTypeFunctionSig &Symbol) override; + void dump(const PDBSymbolTypeArray &Symbol) override; void dump(const PDBSymbolTypeBuiltin &Symbol) override; void dump(const PDBSymbolTypePointer &Symbol) override; diff --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp index c9162dd..f71ff9f 100644 --- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -193,6 +193,8 @@ static cl::opt Compilands("compilands", static cl::opt Funcsigs("funcsigs", cl::desc("Dump function signature information"), cl::sub(DiaDumpSubcommand)); +static cl::opt Arrays("arrays", cl::desc("Dump array types"), + cl::sub(DiaDumpSubcommand)); } // namespace diadump namespace pretty { @@ -245,6 +247,8 @@ cl::opt Funcsigs("funcsigs", cl::desc("Display function signatures"), cl::cat(TypeCategory), cl::sub(PrettySubcommand)); cl::opt Pointers("pointers", cl::desc("Display pointer types"), cl::cat(TypeCategory), cl::sub(PrettySubcommand)); +cl::opt Arrays("arrays", cl::desc("Display arrays"), + cl::cat(TypeCategory), cl::sub(PrettySubcommand)); cl::opt SymbolOrder( "symbol-order", cl::desc("symbol sort order"), @@ -1015,7 +1019,8 @@ static void dumpDia(StringRef Path) { SymTypes.push_back(PDB_SymType::UDT); if (opts::diadump::Funcsigs) SymTypes.push_back(PDB_SymType::FunctionSig); - + if (opts::diadump::Arrays) + SymTypes.push_back(PDB_SymType::ArrayType); PdbSymbolIdField Ids = opts::diadump::NoSymIndexIds ? PdbSymbolIdField::None : PdbSymbolIdField::All; PdbSymbolIdField Recurse = PdbSymbolIdField::None; @@ -1182,7 +1187,8 @@ static void dumpPretty(StringRef Path) { } if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs || - opts::pretty::Funcsigs || opts::pretty::Pointers) { + opts::pretty::Funcsigs || opts::pretty::Pointers || + opts::pretty::Arrays) { Printer.NewLine(); WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---"; Printer.Indent(); @@ -1275,6 +1281,7 @@ static void dumpPretty(StringRef Path) { dumpInjectedSources(Printer, *Session); } + Printer.NewLine(); outs().flush(); } diff --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.h b/llvm/tools/llvm-pdbutil/llvm-pdbutil.h index eaedb1a..cbccac2 100644 --- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.h +++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.h @@ -83,6 +83,7 @@ extern llvm::cl::opt Globals; extern llvm::cl::opt Classes; extern llvm::cl::opt Enums; extern llvm::cl::opt Funcsigs; +extern llvm::cl::opt Arrays; extern llvm::cl::opt Typedefs; extern llvm::cl::opt Pointers; extern llvm::cl::opt All; -- 2.7.4