llvm.org GIT mirror llvm / a93560b
[PDB] Add support for parsing VFTable Shape records. This allows them to be returned from the native API. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343506 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 11 months ago
11 changed file(s) with 132 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
0 //===- NativeTypeVTShape.h - info about virtual table shape ------*- C++-*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEVTSHAPE_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEVTSHAPE_H
11
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/DebugInfo/CodeView/CodeView.h"
14 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
15 #include "llvm/DebugInfo/PDB/Native/NativeRawSymbol.h"
16 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
17
18 namespace llvm {
19 namespace pdb {
20
21 class NativeTypeVTShape : public NativeRawSymbol {
22 public:
23 // Create a pointer record for a non-simple type.
24 NativeTypeVTShape(NativeSession &Session, SymIndexId Id,
25 codeview::TypeIndex TI, codeview::VFTableShapeRecord SR);
26
27 ~NativeTypeVTShape() override;
28
29 void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields,
30 PdbSymbolIdField RecurseIdFields) const override;
31
32 bool isConstType() const override;
33 bool isVolatileType() const override;
34 bool isUnalignedType() const override;
35 uint32_t getCount() const override;
36
37 protected:
38 codeview::TypeIndex TI;
39 codeview::VFTableShapeRecord Record;
40 };
41
42 } // namespace pdb
43 } // namespace llvm
44
45 #endif // LLVM_DEBUGINFO_PDB_NATIVE_NATIVETYPEPOINTER_H
5757 Native/NativeTypeFunctionSig.cpp
5858 Native/NativeTypePointer.cpp
5959 Native/NativeTypeUDT.cpp
60 Native/NativeTypeVTShape.cpp
6061 Native/NamedStreamMap.cpp
6162 Native/NativeSession.cpp
6263 Native/PDBFile.cpp
5050 return Session.getSymbolCache().createTypeEnumerator(
5151 {codeview::LF_STRUCTURE, codeview::LF_CLASS, codeview::LF_UNION,
5252 codeview::LF_INTERFACE});
53 case PDB_SymType::VTableShape:
54 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_VTSHAPE);
5355 case PDB_SymType::FunctionSig:
5456 return Session.getSymbolCache().createTypeEnumerator(
5557 {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION});
161161 TypeIndex ReturnTI =
162162 IsMemberFunction ? MemberFunc.getReturnType() : Proc.getReturnType();
163163
164 return Session.getSymbolCache().findSymbolByTypeIndex(ReturnTI);
164 SymIndexId Result = Session.getSymbolCache().findSymbolByTypeIndex(ReturnTI);
165 return Result;
165166 }
166167
167168 int32_t NativeTypeFunctionSig::getThisAdjust() const {
0 #include "llvm/DebugInfo/PDB/Native/NativeTypeVTShape.h"
1
2 using namespace llvm;
3 using namespace llvm::pdb;
4
5 // Create a pointer record for a non-simple type.
6 NativeTypeVTShape::NativeTypeVTShape(NativeSession &Session, SymIndexId Id,
7 codeview::TypeIndex TI,
8 codeview::VFTableShapeRecord SR)
9 : NativeRawSymbol(Session, PDB_SymType::VTableShape, Id), TI(TI),
10 Record(std::move(SR)) {}
11
12 NativeTypeVTShape::~NativeTypeVTShape() {}
13
14 void NativeTypeVTShape::dump(raw_ostream &OS, int Indent,
15 PdbSymbolIdField ShowIdFields,
16 PdbSymbolIdField RecurseIdFields) const {
17 NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
18
19 dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
20 PdbSymbolIdField::LexicalParent, ShowIdFields,
21 RecurseIdFields);
22 dumpSymbolField(OS, "count", getCount(), Indent);
23 dumpSymbolField(OS, "constType", isConstType(), Indent);
24 dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
25 dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
26 }
27
28 bool NativeTypeVTShape::isConstType() const { return false; }
29
30 bool NativeTypeVTShape::isVolatileType() const { return false; }
31
32 bool NativeTypeVTShape::isUnalignedType() const { return false; }
33
34 uint32_t NativeTypeVTShape::getCount() const { return Record.Slots.size(); }
1212 #include "llvm/DebugInfo/PDB/Native/NativeTypeFunctionSig.h"
1313 #include "llvm/DebugInfo/PDB/Native/NativeTypePointer.h"
1414 #include "llvm/DebugInfo/PDB/Native/NativeTypeUDT.h"
15 #include "llvm/DebugInfo/PDB/Native/NativeTypeVTShape.h"
1516 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
1617 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
1718 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
3132 } BuiltinTypes[] = {
3233 {codeview::SimpleTypeKind::None, PDB_BuiltinType::None, 0},
3334 {codeview::SimpleTypeKind::Void, PDB_BuiltinType::Void, 0},
35 {codeview::SimpleTypeKind::HResult, PDB_BuiltinType::HResult, 4},
3436 {codeview::SimpleTypeKind::Int16Short, PDB_BuiltinType::Int, 2},
3537 {codeview::SimpleTypeKind::UInt16Short, PDB_BuiltinType::UInt, 2},
3638 {codeview::SimpleTypeKind::Int32, PDB_BuiltinType::Int, 4},
4042 {codeview::SimpleTypeKind::Int64Quad, PDB_BuiltinType::Int, 8},
4143 {codeview::SimpleTypeKind::UInt64Quad, PDB_BuiltinType::UInt, 8},
4244 {codeview::SimpleTypeKind::NarrowCharacter, PDB_BuiltinType::Char, 1},
45 {codeview::SimpleTypeKind::WideCharacter, PDB_BuiltinType::WCharT, 2},
46 {codeview::SimpleTypeKind::Character16, PDB_BuiltinType::Char16, 2},
47 {codeview::SimpleTypeKind::Character32, PDB_BuiltinType::Char32, 4},
4348 {codeview::SimpleTypeKind::SignedCharacter, PDB_BuiltinType::Char, 1},
4449 {codeview::SimpleTypeKind::UnsignedCharacter, PDB_BuiltinType::UInt, 1},
45 {codeview::SimpleTypeKind::Boolean8, PDB_BuiltinType::Bool, 1}
50 {codeview::SimpleTypeKind::Float32, PDB_BuiltinType::Float, 4},
51 {codeview::SimpleTypeKind::Float64, PDB_BuiltinType::Float, 8},
52 {codeview::SimpleTypeKind::Float80, PDB_BuiltinType::Float, 10},
53 {codeview::SimpleTypeKind::Boolean8, PDB_BuiltinType::Bool, 1},
4654 // This table can be grown as necessary, but these are the only types we've
4755 // needed so far.
4856 };
195203 Id = createSymbolForType(
196204 Index, std::move(CVT));
197205 break;
206 case codeview::LF_VTSHAPE:
207 Id = createSymbolForType(
208 Index, std::move(CVT));
209 break;
198210 default:
199211 Id = createSymbolPlaceholder();
200212 break;
5252 void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol,
5353 const char *Name, PointerType Pointer) {
5454 auto ReturnType = Symbol.getReturnType();
55 ReturnType->dump(*this);
55 if (!ReturnType)
56 Printer << "";
57 else
58 ReturnType->dump(*this);
5659 Printer << " ";
5760 uint32_t ClassParentId = Symbol.getClassParentId();
5861 auto ClassParent =
224227 // through to the real thing and dump it.
225228 uint32_t TypeId = Symbol.getTypeId();
226229 auto Type = Symbol.getSession().getSymbolById(TypeId);
227 if (!Type)
228 return;
229 Type->dump(*this);
230 if (Type)
231 Printer << "";
232 else
233 Type->dump(*this);
230234 }
231235
232236 void FunctionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
207207 if (opts::pretty::Pointers)
208208 dumpSymbolCategory(Printer, Exe, *this, "Pointers");
209209
210 if (opts::pretty::VTShapes)
211 dumpSymbolCategory(Printer, Exe, *this,
212 "VFTable Shapes");
213
210214 if (opts::pretty::Classes) {
211215 if (auto Classes = Exe.findAllChildren()) {
212216 uint32_t All = Classes->getChildCount();
280284 BD.start(Symbol);
281285 }
282286
287 void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol) {
288 printClassDecl(Printer, Symbol);
289 }
290
283291 void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
284292 assert(opts::pretty::Typedefs);
285293
304312 void TypeDumper::dump(const PDBSymbolTypePointer &Symbol) {
305313 std::unique_ptr P = Symbol.getPointeeType();
306314
307 if (auto *FS = dyn_cast_or_null(P.get())) {
315 if (auto *FS = dyn_cast(P.get())) {
308316 FunctionDumper Dumper(Printer);
309317 FunctionDumper::PointerType PT =
310318 Symbol.isReference() ? FunctionDumper::PointerType::Reference
313321 return;
314322 }
315323
316 if (auto *UDT = dyn_cast_or_null(P.get())) {
324 if (auto *UDT = dyn_cast(P.get())) {
317325 printClassDecl(Printer, *UDT);
318326 } else if (P) {
319327 P->dump(*this);
331339 Printer << "&&";
332340 else
333341 Printer << "*";
342 }
343
344 void TypeDumper::dump(const PDBSymbolTypeVTableShape &Symbol) {
345 Printer.format("", Symbol.getCount());
334346 }
335347
336348 void TypeDumper::dumpClassLayout(const ClassLayout &Class) {
2828 void dump(const PDBSymbolTypeArray &Symbol) override;
2929 void dump(const PDBSymbolTypeBuiltin &Symbol) override;
3030 void dump(const PDBSymbolTypePointer &Symbol) override;
31 void dump(const PDBSymbolTypeVTableShape &Symbol) override;
32 void dump(const PDBSymbolTypeUDT &Symbol) override;
3133
3234 void dumpClassLayout(const ClassLayout &Class);
3335
194194 cl::sub(DiaDumpSubcommand));
195195 static cl::opt Arrays("arrays", cl::desc("Dump array types"),
196196 cl::sub(DiaDumpSubcommand));
197 static cl::opt VTShapes("vtshapes", cl::desc("Dump virtual table shapes"),
198 cl::sub(DiaDumpSubcommand));
197199 } // namespace diadump
198200
199201 namespace pretty {
248250 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
249251 cl::opt Arrays("arrays", cl::desc("Display arrays"),
250252 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
253 cl::opt VTShapes("vtshapes", cl::desc("Display vftable shapes"),
254 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
251255
252256 cl::opt SymbolOrder(
253257 "symbol-order", cl::desc("symbol sort order"),
10201024 SymTypes.push_back(PDB_SymType::FunctionSig);
10211025 if (opts::diadump::Arrays)
10221026 SymTypes.push_back(PDB_SymType::ArrayType);
1027 if (opts::diadump::VTShapes)
1028 SymTypes.push_back(PDB_SymType::VTableShape);
10231029 PdbSymbolIdField Ids = opts::diadump::NoSymIndexIds ? PdbSymbolIdField::None
10241030 : PdbSymbolIdField::All;
1031
10251032 PdbSymbolIdField Recurse = PdbSymbolIdField::None;
10261033 if (opts::diadump::Recurse)
10271034 Recurse = PdbSymbolIdField::All;
11871194
11881195 if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs ||
11891196 opts::pretty::Funcsigs || opts::pretty::Pointers ||
1190 opts::pretty::Arrays) {
1197 opts::pretty::Arrays || opts::pretty::VTShapes) {
11911198 Printer.NewLine();
11921199 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
11931200 Printer.Indent();
8585 extern llvm::cl::opt Arrays;
8686 extern llvm::cl::opt Typedefs;
8787 extern llvm::cl::opt Pointers;
88 extern llvm::cl::opt VTShapes;
8889 extern llvm::cl::opt All;
8990 extern llvm::cl::opt ExcludeCompilerGenerated;
9091