[Lldb-commits] [lldb] [llvm] [lldb][NativePDB] Fix crash in debugger when PDB has bad type index value (PR #166455)

via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 5 04:22:30 PST 2025


================
@@ -93,20 +93,28 @@ CVType LazyRandomTypeCollection::getType(TypeIndex Index) {
   return Records[Index.toArrayIndex()].Type;
 }
 
-std::optional<CVType> LazyRandomTypeCollection::tryGetType(TypeIndex Index) {
+llvm::Expected<CVType>
+LazyRandomTypeCollection::getTypeOrError(TypeIndex Index) {
   if (Index.isSimple())
-    return std::nullopt;
+    return llvm::createStringError("Type index too low (%d)", Index.getIndex());
 
   if (auto EC = ensureTypeExists(Index)) {
-    consumeError(std::move(EC));
-    return std::nullopt;
+    return EC;
   }
 
   if (!contains(Index))
-    return std::nullopt;
+    return llvm::createStringError("Type index too high (%d)",
+                                   Index.getIndex());
   return Records[Index.toArrayIndex()].Type;
 }
 
+std::optional<CVType> LazyRandomTypeCollection::tryGetType(TypeIndex Index) {
+  llvm::Expected<CVType> res = getTypeOrError(Index);
+  if (!res)
+    return std::nullopt;
+  return *res;
----------------
Nerixyz wrote:

You can use `llvm::expectedToOptional` here.

https://github.com/llvm/llvm-project/pull/166455


More information about the lldb-commits mailing list