Skip to content

Commit 26186c7

Browse files
committed
Add type records to TPI stream.
I don't think the data I add to a TPI stream in this patch is correct, but at least it can be displayed using llvm-pdbdump. Until I add more streams to a PDB file, I'm not able to know whether the data will be accepted by MSVC tools or not. llvm-svn: 289183
1 parent f8f391d commit 26186c7

File tree

2 files changed

+285
-111
lines changed

2 files changed

+285
-111
lines changed

lld/COFF/PDB.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,28 @@ static SectionChunk *findByName(std::vector<SectionChunk *> &Sections,
6060
return nullptr;
6161
}
6262

63-
static void dumpDebugT(ScopedPrinter &W, ObjectFile *File) {
63+
static ArrayRef<uint8_t> getDebugT(ObjectFile *File) {
6464
SectionChunk *Sec = findByName(File->getDebugChunks(), ".debug$T");
6565
if (!Sec)
66-
return;
66+
return {};
6767

6868
// First 4 bytes are section magic.
6969
ArrayRef<uint8_t> Data = Sec->getContents();
7070
if (Data.size() < 4)
7171
fatal(".debug$T too short");
7272
if (read32le(Data.data()) != COFF::DEBUG_SECTION_MAGIC)
7373
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;
7481

82+
msf::ByteStream Stream(Data);
7583
CVTypeDumper TypeDumper(&W, false);
76-
if (auto EC = TypeDumper.dump(Data.slice(4)))
84+
if (auto EC = TypeDumper.dump(Data))
7785
fatal(EC, "CVTypeDumper::dump failed");
7886
}
7987

@@ -104,6 +112,23 @@ static void dumpCodeView(SymbolTable *Symtab) {
104112
}
105113
}
106114

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+
107132
// Creates a PDB file.
108133
void coff::createPDB(StringRef Path, SymbolTable *Symtab,
109134
ArrayRef<uint8_t> SectionTable) {
@@ -137,6 +162,7 @@ void coff::createPDB(StringRef Path, SymbolTable *Symtab,
137162
// Add an empty TPI stream.
138163
auto &TpiBuilder = Builder.getTpiBuilder();
139164
TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
165+
addTypeInfo(Symtab, TpiBuilder);
140166

141167
// Add an empty IPI stream.
142168
auto &IpiBuilder = Builder.getIpiBuilder();

0 commit comments

Comments
 (0)