[PDB] Improve warning for corrupt debug info

The S_[GL]PROC32_ID symbol records are supposed to point to function ID
records. If they don't, they are corrupt. The warning message here was
very technical, but a user has encountered it in the wild. Add some more
information and some more testing.
This commit is contained in:
Reid Kleckner 2021-03-11 13:53:14 -08:00
parent c92ec0dd92
commit b552adf8b3

View File

@ -374,22 +374,27 @@ static void translateIdSymbols(MutableArrayRef<uint8_t> &recordData,
// Note that LF_FUNC_ID and LF_MFUNC_ID have the same record layout, and
// in both cases we just need the second type index.
if (!ti->isSimple() && !ti->isNoneType()) {
TypeIndex newType = TypeIndex(SimpleTypeKind::NotTranslated);
if (config->debugGHashes) {
auto idToType = tMerger.funcIdToType.find(*ti);
if (idToType == tMerger.funcIdToType.end()) {
warn(formatv("S_[GL]PROC32_ID record in {0} refers to PDB item "
"index {1:X} which is not a LF_[M]FUNC_ID record",
source->file->getName(), ti->getIndex()));
*ti = TypeIndex(SimpleTypeKind::NotTranslated);
} else {
*ti = idToType->second;
}
if (idToType != tMerger.funcIdToType.end())
newType = idToType->second;
} else {
CVType funcIdData = tMerger.getIDTable().getType(*ti);
ArrayRef<uint8_t> tiBuf = funcIdData.data().slice(8, 4);
assert(tiBuf.size() == 4 && "corrupt LF_[M]FUNC_ID record");
*ti = *reinterpret_cast<const TypeIndex *>(tiBuf.data());
if (tMerger.getIDTable().contains(*ti)) {
CVType funcIdData = tMerger.getIDTable().getType(*ti);
if (funcIdData.length() >= 8 && (funcIdData.kind() == LF_FUNC_ID ||
funcIdData.kind() == LF_MFUNC_ID)) {
newType = *reinterpret_cast<const TypeIndex *>(&funcIdData.data()[8]);
}
}
}
if (newType == TypeIndex(SimpleTypeKind::NotTranslated)) {
warn(formatv("procedure symbol record for `{0}` in {1} refers to PDB "
"item index {2:X} which is not a valid function ID record",
getSymbolName(CVSymbol(recordData)),
source->file->getName(), ti->getIndex()));
}
*ti = newType;
}
kind = (kind == SymbolKind::S_GPROC32_ID) ? SymbolKind::S_GPROC32