Skip to content

Commit 629cb7d

Browse files
author
Zachary Turner
committedJan 11, 2017
[CodeView] Finish decoupling TypeDatabase from TypeDumper.
Previously the type dumper itself was passed around to a lot of different places and manipulated in ways that were more appropriate on the type database. For example, the entire TypeDumper was passed into the symbol dumper, when all the symbol dumper wanted to do was lookup the name of a TypeIndex so it could print it. That's what the TypeDatabase is for -- mapping type indices to names. Another example is how if the user runs llvm-pdbdump with the option to dump symbols but not types, we still have to visit all types so that we can print minimal information about the type of a symbol, but just without dumping full symbol records. The way we did this before is by hacking it up so that we run everything through the type dumper with a null printer, so that the output goes to /dev/null. But really, we don't need to dump anything, all we want to do is build the type database. Since TypeDatabaseVisitor now exists independently of TypeDumper, we can do this. We just build a custom visitor callback pipeline that includes a database visitor but not a dumper. All the hackery around printers etc goes away. After this patch, we could probably even delete the entire CVTypeDumper class since really all it is at this point is a thin wrapper that hides the details of how to build a useful visitation pipeline. It's not a priority though, so CVTypeDumper remains for now. After this patch we will be able to easily plug in a different style of type dumper by only implementing the proper visitation methods to dump one-line output and then sticking it on the pipeline. Differential Revision: https://reviews.llvm.org/D28524 llvm-svn: 291724
1 parent 7e35ee4 commit 629cb7d

File tree

12 files changed

+706
-613
lines changed

12 files changed

+706
-613
lines changed
 

‎lld/COFF/PDB.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "llvm/DebugInfo/CodeView/CVDebugRecord.h"
1717
#include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
1818
#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
19+
#include "llvm/DebugInfo/CodeView/TypeDatabase.h"
20+
#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
1921
#include "llvm/DebugInfo/MSF/ByteStream.h"
2022
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
2123
#include "llvm/DebugInfo/MSF/MSFCommon.h"
@@ -80,9 +82,10 @@ static void dumpDebugT(ScopedPrinter &W, ObjectFile *File) {
8082
if (Data.empty())
8183
return;
8284

83-
msf::ByteStream Stream(Data);
84-
CVTypeDumper TypeDumper(&W, false);
85-
if (auto EC = TypeDumper.dump(Data))
85+
TypeDatabase TDB;
86+
TypeDumpVisitor TDV(TDB, &W, false);
87+
CVTypeDumper TypeDumper(TDB);
88+
if (auto EC = TypeDumper.dump(Data, TDV))
8689
fatal(EC, "CVTypeDumper::dump failed");
8790
}
8891

@@ -97,8 +100,8 @@ static void dumpDebugS(ScopedPrinter &W, ObjectFile *File) {
97100
if (auto EC = Reader.readArray(Symbols, Reader.getLength()))
98101
fatal(EC, "StreamReader.readArray<CVSymbolArray> failed");
99102

100-
CVTypeDumper TypeDumper(&W, false);
101-
CVSymbolDumper SymbolDumper(W, TypeDumper, nullptr, false);
103+
TypeDatabase TDB;
104+
CVSymbolDumper SymbolDumper(W, TDB, nullptr, false);
102105
if (auto EC = SymbolDumper.dump(Symbols))
103106
fatal(EC, "CVSymbolDumper::dump failed");
104107
}

‎llvm/include/llvm/DebugInfo/CodeView/CVTypeDumper.h

+9-39
Original file line numberDiff line numberDiff line change
@@ -16,68 +16,38 @@
1616
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
1717
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
1818
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
19+
#include "llvm/Support/ScopedPrinter.h"
1920

2021
namespace llvm {
21-
class ScopedPrinter;
2222

2323
namespace codeview {
2424

2525
/// Dumper for CodeView type streams found in COFF object files and PDB files.
26-
class CVTypeDumper : public TypeVisitorCallbacks {
26+
class CVTypeDumper {
2727
public:
28-
CVTypeDumper(ScopedPrinter *W, bool PrintRecordBytes)
29-
: W(W), PrintRecordBytes(PrintRecordBytes) {}
30-
31-
void printTypeIndex(StringRef FieldName, TypeIndex TI);
28+
explicit CVTypeDumper(TypeDatabase &TypeDB) : TypeDB(TypeDB) {}
3229

3330
/// Dumps one type record. Returns false if there was a type parsing error,
3431
/// and true otherwise. This should be called in order, since the dumper
3532
/// maintains state about previous records which are necessary for cross
3633
/// type references.
37-
Error dump(const CVRecord<TypeLeafKind> &Record);
34+
Error dump(const CVType &Record, TypeVisitorCallbacks &Dumper);
3835

3936
/// Dumps the type records in Types. Returns false if there was a type stream
4037
/// parse error, and true otherwise.
41-
Error dump(const CVTypeArray &Types);
38+
Error dump(const CVTypeArray &Types, TypeVisitorCallbacks &Dumper);
4239

4340
/// Dumps the type records in Data. Returns false if there was a type stream
4441
/// parse error, and true otherwise. Use this method instead of the
4542
/// CVTypeArray overload when type records are laid out contiguously in
4643
/// memory.
47-
Error dump(ArrayRef<uint8_t> Data);
48-
49-
void setPrinter(ScopedPrinter *P);
50-
ScopedPrinter *getPrinter() { return W; }
51-
52-
/// Action to take on unknown types. By default, they are ignored.
53-
Error visitUnknownType(CVType &Record) override;
54-
Error visitUnknownMember(CVMemberRecord &Record) override;
55-
56-
/// Paired begin/end actions for all types. Receives all record data,
57-
/// including the fixed-length record prefix.
58-
Error visitTypeBegin(CVType &Record) override;
59-
Error visitTypeEnd(CVType &Record) override;
60-
Error visitMemberBegin(CVMemberRecord &Record) override;
61-
Error visitMemberEnd(CVMemberRecord &Record) override;
44+
Error dump(ArrayRef<uint8_t> Data, TypeVisitorCallbacks &Dumper);
6245

63-
#define TYPE_RECORD(EnumName, EnumVal, Name) \
64-
Error visitKnownRecord(CVType &CVR, Name##Record &Record) override;
65-
#define MEMBER_RECORD(EnumName, EnumVal, Name) \
66-
Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override;
67-
#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
68-
#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
69-
#include "TypeRecords.def"
46+
static void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName,
47+
TypeIndex TI, TypeDatabase &DB);
7048

7149
private:
72-
void printMemberAttributes(MemberAttributes Attrs);
73-
void printMemberAttributes(MemberAccess Access, MethodKind Kind,
74-
MethodOptions Options);
75-
76-
ScopedPrinter *W;
77-
78-
bool PrintRecordBytes = false;
79-
80-
TypeDatabase TypeDB;
50+
TypeDatabase &TypeDB;
8151
};
8252

8353
} // end namespace codeview

‎llvm/include/llvm/DebugInfo/CodeView/SymbolDumper.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ namespace llvm {
2020
class ScopedPrinter;
2121

2222
namespace codeview {
23-
class CVTypeDumper;
23+
class TypeDatabase;
2424

2525
/// Dumper for CodeView symbol streams found in COFF object files and PDB files.
2626
class CVSymbolDumper {
2727
public:
28-
CVSymbolDumper(ScopedPrinter &W, CVTypeDumper &CVTD,
28+
CVSymbolDumper(ScopedPrinter &W, TypeDatabase &TypeDB,
2929
std::unique_ptr<SymbolDumpDelegate> ObjDelegate,
3030
bool PrintRecordBytes)
31-
: W(W), CVTD(CVTD), ObjDelegate(std::move(ObjDelegate)),
31+
: W(W), TypeDB(TypeDB), ObjDelegate(std::move(ObjDelegate)),
3232
PrintRecordBytes(PrintRecordBytes) {}
3333

3434
/// Dumps one type record. Returns false if there was a type parsing error,
@@ -43,7 +43,7 @@ class CVSymbolDumper {
4343

4444
private:
4545
ScopedPrinter &W;
46-
CVTypeDumper &CVTD;
46+
TypeDatabase &TypeDB;
4747
std::unique_ptr<SymbolDumpDelegate> ObjDelegate;
4848

4949
bool PrintRecordBytes;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===-- TypeDumpVisitor.h - CodeView type info dumper -----------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_DEBUGINFO_CODEVIEW_TYPEDUMPVISITOR_H
11+
#define LLVM_DEBUGINFO_CODEVIEW_TYPEDUMPVISITOR_H
12+
13+
#include "llvm/ADT/ArrayRef.h"
14+
#include "llvm/ADT/StringSet.h"
15+
#include "llvm/DebugInfo/CodeView/TypeDatabase.h"
16+
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
17+
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
18+
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
19+
20+
namespace llvm {
21+
class ScopedPrinter;
22+
23+
namespace codeview {
24+
25+
/// Dumper for CodeView type streams found in COFF object files and PDB files.
26+
class TypeDumpVisitor : public TypeVisitorCallbacks {
27+
public:
28+
TypeDumpVisitor(TypeDatabase &TypeDB, ScopedPrinter *W, bool PrintRecordBytes)
29+
: W(W), PrintRecordBytes(PrintRecordBytes), TypeDB(TypeDB) {}
30+
31+
void printTypeIndex(StringRef FieldName, TypeIndex TI) const;
32+
33+
/// Action to take on unknown types. By default, they are ignored.
34+
Error visitUnknownType(CVType &Record) override;
35+
Error visitUnknownMember(CVMemberRecord &Record) override;
36+
37+
/// Paired begin/end actions for all types. Receives all record data,
38+
/// including the fixed-length record prefix.
39+
Error visitTypeBegin(CVType &Record) override;
40+
Error visitTypeEnd(CVType &Record) override;
41+
Error visitMemberBegin(CVMemberRecord &Record) override;
42+
Error visitMemberEnd(CVMemberRecord &Record) override;
43+
44+
#define TYPE_RECORD(EnumName, EnumVal, Name) \
45+
Error visitKnownRecord(CVType &CVR, Name##Record &Record) override;
46+
#define MEMBER_RECORD(EnumName, EnumVal, Name) \
47+
Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override;
48+
#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
49+
#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
50+
#include "TypeRecords.def"
51+
52+
private:
53+
void printMemberAttributes(MemberAttributes Attrs);
54+
void printMemberAttributes(MemberAccess Access, MethodKind Kind,
55+
MethodOptions Options);
56+
57+
ScopedPrinter *W;
58+
59+
bool PrintRecordBytes = false;
60+
61+
TypeDatabase &TypeDB;
62+
};
63+
64+
} // end namespace codeview
65+
} // end namespace llvm
66+
67+
#endif

‎llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/DebugInfo/CodeView/Line.h"
2020
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
2121
#include "llvm/DebugInfo/CodeView/TypeDatabase.h"
22+
#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
2223
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
2324
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
2425
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
@@ -468,16 +469,17 @@ void CodeViewDebug::emitTypeInformation() {
468469
CommentPrefix += ' ';
469470
}
470471

471-
CVTypeDumper CVTD(nullptr, /*PrintRecordBytes=*/false);
472+
TypeDatabase TypeDB;
473+
CVTypeDumper CVTD(TypeDB);
472474
TypeTable.ForEachRecord([&](TypeIndex Index, ArrayRef<uint8_t> Record) {
473475
if (OS.isVerboseAsm()) {
474476
// Emit a block comment describing the type record for readability.
475477
SmallString<512> CommentBlock;
476478
raw_svector_ostream CommentOS(CommentBlock);
477479
ScopedPrinter SP(CommentOS);
478480
SP.setPrefix(CommentPrefix);
479-
CVTD.setPrinter(&SP);
480-
Error E = CVTD.dump(Record);
481+
TypeDumpVisitor TDV(TypeDB, &SP, false);
482+
Error E = CVTD.dump(Record, TDV);
481483
if (E) {
482484
logAllUnhandledErrors(std::move(E), errs(), "error: ");
483485
llvm_unreachable("produced malformed type record");

‎llvm/lib/DebugInfo/CodeView/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_llvm_library(LLVMDebugInfoCodeView
1313
SymbolDumper.cpp
1414
TypeDatabase.cpp
1515
TypeDatabaseVisitor.cpp
16+
TypeDumpVisitor.cpp
1617
TypeRecord.cpp
1718
TypeRecordMapping.cpp
1819
TypeSerializer.cpp

‎llvm/lib/DebugInfo/CodeView/CVTypeDumper.cpp

+16-522
Large diffs are not rendered by default.

‎llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp

+22-17
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ namespace {
3232
/// the visitor out of SymbolDumper.h.
3333
class CVSymbolDumperImpl : public SymbolVisitorCallbacks {
3434
public:
35-
CVSymbolDumperImpl(CVTypeDumper &CVTD, SymbolDumpDelegate *ObjDelegate,
35+
CVSymbolDumperImpl(TypeDatabase &TypeDB, SymbolDumpDelegate *ObjDelegate,
3636
ScopedPrinter &W, bool PrintRecordBytes)
37-
: CVTD(CVTD), ObjDelegate(ObjDelegate), W(W),
37+
: TypeDB(TypeDB), ObjDelegate(ObjDelegate), W(W),
3838
PrintRecordBytes(PrintRecordBytes), InFunctionScope(false) {}
3939

4040
/// CVSymbolVisitor overrides.
@@ -51,8 +51,9 @@ class CVSymbolDumperImpl : public SymbolVisitorCallbacks {
5151
void printLocalVariableAddrRange(const LocalVariableAddrRange &Range,
5252
uint32_t RelocationOffset);
5353
void printLocalVariableAddrGap(ArrayRef<LocalVariableAddrGap> Gaps);
54+
void printTypeIndex(StringRef FieldName, TypeIndex TI);
5455

55-
CVTypeDumper &CVTD;
56+
TypeDatabase &TypeDB;
5657
SymbolDumpDelegate *ObjDelegate;
5758
ScopedPrinter &W;
5859

@@ -80,6 +81,10 @@ void CVSymbolDumperImpl::printLocalVariableAddrGap(
8081
}
8182
}
8283

84+
void CVSymbolDumperImpl::printTypeIndex(StringRef FieldName, TypeIndex TI) {
85+
CVTypeDumper::printTypeIndex(W, FieldName, TI, TypeDB);
86+
}
87+
8388
Error CVSymbolDumperImpl::visitSymbolBegin(CVSymbol &CVR) {
8489
return Error::success();
8590
}
@@ -163,7 +168,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
163168
DictScope S(W, "BPRelativeSym");
164169

165170
W.printNumber("Offset", BPRel.Offset);
166-
CVTD.printTypeIndex("Type", BPRel.Type);
171+
printTypeIndex("Type", BPRel.Type);
167172
W.printString("VarName", BPRel.Name);
168173
return Error::success();
169174
}
@@ -187,7 +192,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
187192
CallSiteInfo.CodeOffset, &LinkageName);
188193
}
189194
W.printHex("Segment", CallSiteInfo.Segment);
190-
CVTD.printTypeIndex("Type", CallSiteInfo.Type);
195+
printTypeIndex("Type", CallSiteInfo.Type);
191196
if (!LinkageName.empty())
192197
W.printString("LinkageName", LinkageName);
193198
return Error::success();
@@ -278,7 +283,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
278283
ConstantSym &Constant) {
279284
DictScope S(W, "Constant");
280285

281-
CVTD.printTypeIndex("Type", Constant.Type);
286+
printTypeIndex("Type", Constant.Type);
282287
W.printNumber("Value", Constant.Value);
283288
W.printString("Name", Constant.Name);
284289
return Error::success();
@@ -293,7 +298,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {
293298
ObjDelegate->printRelocatedField("DataOffset", Data.getRelocationOffset(),
294299
Data.DataOffset, &LinkageName);
295300
}
296-
CVTD.printTypeIndex("Type", Data.Type);
301+
printTypeIndex("Type", Data.Type);
297302
W.printString("DisplayName", Data.Name);
298303
if (!LinkageName.empty())
299304
W.printString("LinkageName", LinkageName);
@@ -445,7 +450,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(
445450
}
446451
W.printHex("Segment", HeapAllocSite.Segment);
447452
W.printHex("CallInstructionSize", HeapAllocSite.CallInstructionSize);
448-
CVTD.printTypeIndex("Type", HeapAllocSite.Type);
453+
printTypeIndex("Type", HeapAllocSite.Type);
449454
if (!LinkageName.empty())
450455
W.printString("LinkageName", LinkageName);
451456
return Error::success();
@@ -457,7 +462,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
457462

458463
W.printHex("PtrParent", InlineSite.Parent);
459464
W.printHex("PtrEnd", InlineSite.End);
460-
CVTD.printTypeIndex("Inlinee", InlineSite.Inlinee);
465+
printTypeIndex("Inlinee", InlineSite.Inlinee);
461466

462467
ListScope BinaryAnnotations(W, "BinaryAnnotations");
463468
for (auto &Annotation : InlineSite.annotations()) {
@@ -555,7 +560,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {
555560
Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
556561
DictScope S(W, "Local");
557562

558-
CVTD.printTypeIndex("Type", Local.Type);
563+
printTypeIndex("Type", Local.Type);
559564
W.printFlags("Flags", uint16_t(Local.Flags), getLocalFlagNames());
560565
W.printString("VarName", Local.Name);
561566
return Error::success();
@@ -586,7 +591,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {
586591
W.printHex("CodeSize", Proc.CodeSize);
587592
W.printHex("DbgStart", Proc.DbgStart);
588593
W.printHex("DbgEnd", Proc.DbgEnd);
589-
CVTD.printTypeIndex("FunctionType", Proc.FunctionType);
594+
printTypeIndex("FunctionType", Proc.FunctionType);
590595
if (ObjDelegate) {
591596
ObjDelegate->printRelocatedField("CodeOffset", Proc.getRelocationOffset(),
592597
Proc.CodeOffset, &LinkageName);
@@ -616,7 +621,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
616621
Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {
617622
ListScope S(W, CVR.kind() == S_CALLEES ? "Callees" : "Callers");
618623
for (auto FuncID : Caller.Indices)
619-
CVTD.printTypeIndex("FuncID", FuncID);
624+
printTypeIndex("FuncID", FuncID);
620625
return Error::success();
621626
}
622627

@@ -625,7 +630,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
625630
DictScope S(W, "RegRelativeSym");
626631

627632
W.printHex("Offset", RegRel.Offset);
628-
CVTD.printTypeIndex("Type", RegRel.Type);
633+
printTypeIndex("Type", RegRel.Type);
629634
W.printHex("Register", RegRel.Register);
630635
W.printString("VarName", RegRel.Name);
631636
return Error::success();
@@ -640,7 +645,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
640645
ObjDelegate->printRelocatedField("DataOffset", Data.getRelocationOffset(),
641646
Data.DataOffset, &LinkageName);
642647
}
643-
CVTD.printTypeIndex("Type", Data.Type);
648+
printTypeIndex("Type", Data.Type);
644649
W.printString("DisplayName", Data.Name);
645650
if (!LinkageName.empty())
646651
W.printString("LinkageName", LinkageName);
@@ -649,7 +654,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
649654

650655
Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
651656
DictScope S(W, "UDT");
652-
CVTD.printTypeIndex("Type", UDT.Type);
657+
printTypeIndex("Type", UDT.Type);
653658
W.printString("UDTName", UDT.Name);
654659
return Error::success();
655660
}
@@ -664,7 +669,7 @@ Error CVSymbolDumperImpl::visitUnknownSymbol(CVSymbol &CVR) {
664669
Error CVSymbolDumper::dump(CVRecord<SymbolKind> &Record) {
665670
SymbolVisitorCallbackPipeline Pipeline;
666671
SymbolDeserializer Deserializer(ObjDelegate.get());
667-
CVSymbolDumperImpl Dumper(CVTD, ObjDelegate.get(), W, PrintRecordBytes);
672+
CVSymbolDumperImpl Dumper(TypeDB, ObjDelegate.get(), W, PrintRecordBytes);
668673

669674
Pipeline.addCallbackToPipeline(Deserializer);
670675
Pipeline.addCallbackToPipeline(Dumper);
@@ -675,7 +680,7 @@ Error CVSymbolDumper::dump(CVRecord<SymbolKind> &Record) {
675680
Error CVSymbolDumper::dump(const CVSymbolArray &Symbols) {
676681
SymbolVisitorCallbackPipeline Pipeline;
677682
SymbolDeserializer Deserializer(ObjDelegate.get());
678-
CVSymbolDumperImpl Dumper(CVTD, ObjDelegate.get(), W, PrintRecordBytes);
683+
CVSymbolDumperImpl Dumper(TypeDB, ObjDelegate.get(), W, PrintRecordBytes);
679684

680685
Pipeline.addCallbackToPipeline(Deserializer);
681686
Pipeline.addCallbackToPipeline(Dumper);

‎llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp

+532
Large diffs are not rendered by default.

‎llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp

+24-13
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
#include "LLVMOutputStyle.h"
1111

1212
#include "llvm-pdbdump.h"
13+
#include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
14+
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
1315
#include "llvm/DebugInfo/CodeView/EnumTables.h"
1416
#include "llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h"
1517
#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
18+
#include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h"
19+
#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
20+
#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
21+
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
1622
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
1723
#include "llvm/DebugInfo/MSF/StreamReader.h"
1824
#include "llvm/DebugInfo/PDB/PDBExtras.h"
@@ -83,8 +89,7 @@ static void printSectionOffset(llvm::raw_ostream &OS,
8389
OS << Off.Off << ", " << Off.Isect;
8490
}
8591

86-
LLVMOutputStyle::LLVMOutputStyle(PDBFile &File)
87-
: File(File), P(outs()), Dumper(&P, false) {}
92+
LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) : File(File), P(outs()) {}
8893

8994
Error LLVMOutputStyle::dump() {
9095
if (auto EC = dumpFileHeaders())
@@ -519,6 +524,7 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
519524
if (!Tpi)
520525
return Tpi.takeError();
521526

527+
CVTypeDumper Dumper(TypeDB);
522528
if (DumpRecords || DumpRecordBytes) {
523529
DictScope D(P, Label);
524530

@@ -532,7 +538,8 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
532538
DictScope DD(P, "");
533539

534540
if (DumpRecords) {
535-
if (auto EC = Dumper.dump(Type))
541+
TypeDumpVisitor TDV(TypeDB, &P, false);
542+
if (auto EC = Dumper.dump(Type, TDV))
536543
return EC;
537544
}
538545

@@ -545,19 +552,23 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
545552
"TPI stream contained corrupt record");
546553
} else if (opts::raw::DumpModuleSyms) {
547554
// Even if the user doesn't want to dump type records, we still need to
548-
// iterate them in order to build the list of types so that we can print
549-
// them when dumping module symbols. So when they want to dump symbols
550-
// but not types, use a null output stream.
551-
ScopedPrinter *OldP = Dumper.getPrinter();
552-
Dumper.setPrinter(nullptr);
555+
// iterate them in order to build the type database. So when they want to
556+
// dump symbols but not types, don't stick a dumper on the end, just build
557+
// the type database.
558+
TypeDatabaseVisitor DBV(TypeDB);
559+
TypeDeserializer Deserializer;
560+
TypeVisitorCallbackPipeline Pipeline;
561+
Pipeline.addCallbackToPipeline(Deserializer);
562+
Pipeline.addCallbackToPipeline(DBV);
563+
564+
CVTypeVisitor Visitor(Pipeline);
553565

554566
bool HadError = false;
555-
for (auto &Type : Tpi->types(&HadError)) {
556-
if (auto EC = Dumper.dump(Type))
567+
for (auto Type : Tpi->types(&HadError)) {
568+
if (auto EC = Visitor.visitTypeRecord(Type))
557569
return EC;
558570
}
559571

560-
Dumper.setPrinter(OldP);
561572
dumpTpiHash(P, *Tpi);
562573
if (HadError)
563574
return make_error<RawError>(raw_error_code::corrupt_file,
@@ -640,7 +651,7 @@ Error LLVMOutputStyle::dumpDbiStream() {
640651

641652
if (ShouldDumpSymbols) {
642653
ListScope SS(P, "Symbols");
643-
codeview::CVSymbolDumper SD(P, Dumper, nullptr, false);
654+
codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
644655
bool HadError = false;
645656
for (auto S : ModS.symbols(&HadError)) {
646657
DictScope LL(P, "");
@@ -865,7 +876,7 @@ Error LLVMOutputStyle::dumpPublicsStream() {
865876
P.printList("Section Offsets", Publics->getSectionOffsets(),
866877
printSectionOffset);
867878
ListScope L(P, "Symbols");
868-
codeview::CVSymbolDumper SD(P, Dumper, nullptr, false);
879+
codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
869880
bool HadError = false;
870881
for (auto S : Publics->getSymbols(&HadError)) {
871882
DictScope DD(P, "");

‎llvm/tools/llvm-pdbdump/LLVMOutputStyle.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include "OutputStyle.h"
1414

15-
#include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
15+
#include "llvm/DebugInfo/CodeView/TypeDatabase.h"
1616
#include "llvm/Support/ScopedPrinter.h"
1717

1818
namespace llvm {
@@ -49,7 +49,7 @@ class LLVMOutputStyle : public OutputStyle {
4949

5050
PDBFile &File;
5151
ScopedPrinter P;
52-
codeview::CVTypeDumper Dumper;
52+
codeview::TypeDatabase TypeDB;
5353
std::vector<std::string> StreamPurposes;
5454
};
5555
}

‎llvm/tools/llvm-readobj/COFFDumper.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/DebugInfo/CodeView/SymbolDumpDelegate.h"
3131
#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
3232
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
33+
#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
3334
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
3435
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
3536
#include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
@@ -64,8 +65,7 @@ class COFFDumper : public ObjDumper {
6465
public:
6566
friend class COFFObjectDumpDelegate;
6667
COFFDumper(const llvm::object::COFFObjectFile *Obj, ScopedPrinter &Writer)
67-
: ObjDumper(Writer), Obj(Obj),
68-
CVTD(&Writer, opts::CodeViewSubsectionBytes) {}
68+
: ObjDumper(Writer), Obj(Obj), Writer(Writer) {}
6969

7070
void printFileHeaders() override;
7171
void printSections() override;
@@ -99,7 +99,7 @@ class COFFDumper : public ObjDumper {
9999
void printFileNameForOffset(StringRef Label, uint32_t FileOffset);
100100
void printTypeIndex(StringRef FieldName, TypeIndex TI) {
101101
// Forward to CVTypeDumper for simplicity.
102-
CVTD.printTypeIndex(FieldName, TI);
102+
CVTypeDumper::printTypeIndex(Writer, FieldName, TI, TypeDB);
103103
}
104104

105105
void printCodeViewSymbolsSubsection(StringRef Subsection,
@@ -142,7 +142,8 @@ class COFFDumper : public ObjDumper {
142142
StringRef CVFileChecksumTable;
143143
StringRef CVStringTable;
144144

145-
CVTypeDumper CVTD;
145+
ScopedPrinter &Writer;
146+
TypeDatabase TypeDB;
146147
};
147148

148149
class COFFObjectDumpDelegate : public SymbolDumpDelegate {
@@ -962,7 +963,8 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection,
962963
auto CODD = llvm::make_unique<COFFObjectDumpDelegate>(*this, Section, Obj,
963964
SectionContents);
964965

965-
CVSymbolDumper CVSD(W, CVTD, std::move(CODD), opts::CodeViewSubsectionBytes);
966+
CVSymbolDumper CVSD(W, TypeDB, std::move(CODD),
967+
opts::CodeViewSubsectionBytes);
966968
ByteStream Stream(BinaryData);
967969
CVSymbolArray Symbols;
968970
StreamReader Reader(Stream);
@@ -1106,7 +1108,9 @@ void COFFDumper::printCodeViewTypeSection(StringRef SectionName,
11061108
if (Magic != COFF::DEBUG_SECTION_MAGIC)
11071109
return error(object_error::parse_failed);
11081110

1109-
if (auto EC = CVTD.dump({Data.bytes_begin(), Data.bytes_end()})) {
1111+
CVTypeDumper CVTD(TypeDB);
1112+
TypeDumpVisitor TDV(TypeDB, &W, opts::CodeViewSubsectionBytes);
1113+
if (auto EC = CVTD.dump({Data.bytes_begin(), Data.bytes_end()}, TDV)) {
11101114
W.flush();
11111115
error(llvm::errorToErrorCode(std::move(EC)));
11121116
}
@@ -1552,8 +1556,12 @@ void llvm::dumpCodeViewMergedTypes(ScopedPrinter &Writer,
15521556
CVTypes.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Record) {
15531557
Buf.append(Record.begin(), Record.end());
15541558
});
1555-
CVTypeDumper CVTD(&Writer, opts::CodeViewSubsectionBytes);
1556-
if (auto EC = CVTD.dump({Buf.str().bytes_begin(), Buf.str().bytes_end()})) {
1559+
1560+
TypeDatabase TypeDB;
1561+
CVTypeDumper CVTD(TypeDB);
1562+
TypeDumpVisitor TDV(TypeDB, &Writer, opts::CodeViewSubsectionBytes);
1563+
if (auto EC =
1564+
CVTD.dump({Buf.str().bytes_begin(), Buf.str().bytes_end()}, TDV)) {
15571565
Writer.flush();
15581566
error(llvm::errorToErrorCode(std::move(EC)));
15591567
}

0 commit comments

Comments
 (0)
Please sign in to comment.