Skip to content

Commit 2ef9272

Browse files
committed
[lldb][NativePDB] Fix crash in debugger when PDB has bad type index value
Fix crash when an inline site record in the PDB file contains type index which is out of bounds
1 parent 0013b5f commit 2ef9272

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,19 +1719,23 @@ void SymbolFileNativePDB::ParseInlineSite(PdbCompilandSymId id,
17191719
}
17201720

17211721
// Get the inlined function name.
1722-
CVType inlinee_cvt = m_index->ipi().getType(inline_site.Inlinee);
17231722
std::string inlinee_name;
1724-
if (inlinee_cvt.kind() == LF_MFUNC_ID) {
1723+
llvm::Expected<CVType> inlinee_cvt =
1724+
m_index->ipi().typeCollection().getTypeOrError(inline_site.Inlinee);
1725+
if (!inlinee_cvt) {
1726+
inlinee_name = "[error reading function name: " +
1727+
llvm::toString(inlinee_cvt.takeError()) + "]";
1728+
} else if (inlinee_cvt->kind() == LF_MFUNC_ID) {
17251729
MemberFuncIdRecord mfr;
17261730
cantFail(
1727-
TypeDeserializer::deserializeAs<MemberFuncIdRecord>(inlinee_cvt, mfr));
1731+
TypeDeserializer::deserializeAs<MemberFuncIdRecord>(*inlinee_cvt, mfr));
17281732
LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
17291733
inlinee_name.append(std::string(types.getTypeName(mfr.ClassType)));
17301734
inlinee_name.append("::");
17311735
inlinee_name.append(mfr.getName().str());
1732-
} else if (inlinee_cvt.kind() == LF_FUNC_ID) {
1736+
} else if (inlinee_cvt->kind() == LF_FUNC_ID) {
17331737
FuncIdRecord fir;
1734-
cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(inlinee_cvt, fir));
1738+
cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(*inlinee_cvt, fir));
17351739
TypeIndex parent_idx = fir.getParentScope();
17361740
if (!parent_idx.isNoneType()) {
17371741
LazyRandomTypeCollection &ids = m_index->ipi().typeCollection();

llvm/include/llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class LLVM_ABI LazyRandomTypeCollection : public TypeCollection {
7070
uint32_t getOffsetOfType(TypeIndex Index);
7171

7272
std::optional<CVType> tryGetType(TypeIndex Index);
73-
73+
llvm::Expected<CVType> getTypeOrError(TypeIndex Index);
7474
CVType getType(TypeIndex Index) override;
7575
StringRef getTypeName(TypeIndex Index) override;
7676
bool contains(TypeIndex Index) override;

llvm/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,28 @@ CVType LazyRandomTypeCollection::getType(TypeIndex Index) {
9393
return Records[Index.toArrayIndex()].Type;
9494
}
9595

96-
std::optional<CVType> LazyRandomTypeCollection::tryGetType(TypeIndex Index) {
96+
llvm::Expected<CVType>
97+
LazyRandomTypeCollection::getTypeOrError(TypeIndex Index) {
9798
if (Index.isSimple())
98-
return std::nullopt;
99+
return llvm::createStringError("Type index too low (%d)", Index.getIndex());
99100

100101
if (auto EC = ensureTypeExists(Index)) {
101-
consumeError(std::move(EC));
102-
return std::nullopt;
102+
return EC;
103103
}
104104

105105
if (!contains(Index))
106-
return std::nullopt;
106+
return llvm::createStringError("Type index too high (%d)",
107+
Index.getIndex());
107108
return Records[Index.toArrayIndex()].Type;
108109
}
109110

111+
std::optional<CVType> LazyRandomTypeCollection::tryGetType(TypeIndex Index) {
112+
llvm::Expected<CVType> res = getTypeOrError(Index);
113+
if (!res)
114+
return std::nullopt;
115+
return *res;
116+
}
117+
110118
StringRef LazyRandomTypeCollection::getTypeName(TypeIndex Index) {
111119
if (Index.isNoneType() || Index.isSimple())
112120
return TypeIndex::simpleTypeName(Index);

0 commit comments

Comments
 (0)