@@ -60,20 +60,28 @@ static SectionChunk *findByName(std::vector<SectionChunk *> &Sections,
60
60
return nullptr ;
61
61
}
62
62
63
- static void dumpDebugT (ScopedPrinter &W, ObjectFile *File) {
63
+ static ArrayRef< uint8_t > getDebugT ( ObjectFile *File) {
64
64
SectionChunk *Sec = findByName (File->getDebugChunks (), " .debug$T" );
65
65
if (!Sec)
66
- return ;
66
+ return {} ;
67
67
68
68
// First 4 bytes are section magic.
69
69
ArrayRef<uint8_t > Data = Sec->getContents ();
70
70
if (Data.size () < 4 )
71
71
fatal (" .debug$T too short" );
72
72
if (read32le (Data.data ()) != COFF::DEBUG_SECTION_MAGIC)
73
73
fatal (" .debug$T has an invalid magic" );
74
+ return Data.slice (4 );
75
+ }
76
+
77
+ static void dumpDebugT (ScopedPrinter &W, ObjectFile *File) {
78
+ ArrayRef<uint8_t > Data = getDebugT (File);
79
+ if (Data.empty ())
80
+ return ;
74
81
82
+ msf::ByteStream Stream (Data);
75
83
CVTypeDumper TypeDumper (&W, false );
76
- if (auto EC = TypeDumper.dump (Data. slice ( 4 ) ))
84
+ if (auto EC = TypeDumper.dump (Data))
77
85
fatal (EC, " CVTypeDumper::dump failed" );
78
86
}
79
87
@@ -104,6 +112,23 @@ static void dumpCodeView(SymbolTable *Symtab) {
104
112
}
105
113
}
106
114
115
+ static void addTypeInfo (SymbolTable *Symtab,
116
+ pdb::TpiStreamBuilder &TpiBuilder) {
117
+ for (ObjectFile *File : Symtab->ObjectFiles ) {
118
+ ArrayRef<uint8_t > Data = getDebugT (File);
119
+ if (Data.empty ())
120
+ continue ;
121
+
122
+ msf::ByteStream Stream (Data);
123
+ codeview::CVTypeArray Records;
124
+ msf::StreamReader Reader (Stream);
125
+ if (auto EC = Reader.readArray (Records, Reader.getLength ()))
126
+ fatal (EC, " Reader.readArray failed" );
127
+ for (const codeview::CVType &Rec : Records)
128
+ TpiBuilder.addTypeRecord (Rec);
129
+ }
130
+ }
131
+
107
132
// Creates a PDB file.
108
133
void coff::createPDB (StringRef Path, SymbolTable *Symtab,
109
134
ArrayRef<uint8_t > SectionTable) {
@@ -137,6 +162,7 @@ void coff::createPDB(StringRef Path, SymbolTable *Symtab,
137
162
// Add an empty TPI stream.
138
163
auto &TpiBuilder = Builder.getTpiBuilder ();
139
164
TpiBuilder.setVersionHeader (pdb::PdbTpiV80);
165
+ addTypeInfo (Symtab, TpiBuilder);
140
166
141
167
// Add an empty IPI stream.
142
168
auto &IpiBuilder = Builder.getIpiBuilder ();
0 commit comments