https://github.com/speednoisemovement created 
https://github.com/llvm/llvm-project/pull/176065

`TypeSystem::GetNativePDBParser` returns `nullptr` by default, so using the 
result without checking can cause a crash.

>From 7f8445cea4fe353cb4356ffbe53399e151db82e9 Mon Sep 17 00:00:00 2001
From: Leonard Grey <[email protected]>
Date: Wed, 14 Jan 2026 19:17:31 -0500
Subject: [PATCH] [LLDB][NativePDB] Add PdbAstBuilder null checks

---
 .../NativePDB/SymbolFileNativePDB.cpp         | 28 +++++++++++++------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index 01556133a3ad0..46b4a978dc6a7 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -503,7 +503,8 @@ Block *SymbolFileNativePDB::CreateBlock(PdbCompilandSymId 
block_id) {
           block_id.modi, block_id.offset, block_base,
           block_base + block.CodeSize, func_base);
     }
-    ast_builder->EnsureBlock(block_id);
+    if (ast_builder)
+      ast_builder->EnsureBlock(block_id);
     m_blocks.insert({opaque_block_uid, child_block});
     break;
   }
@@ -516,7 +517,8 @@ Block *SymbolFileNativePDB::CreateBlock(PdbCompilandSymId 
block_id) {
     if (!parent_block)
       return nullptr;
     BlockSP child_block = parent_block->CreateChild(opaque_block_uid);
-    ast_builder->EnsureInlinedFunction(block_id);
+    if (ast_builder)
+      ast_builder->EnsureInlinedFunction(block_id);
     // Copy ranges from InlineSite to Block.
     for (size_t i = 0; i < inline_site->ranges.GetSize(); ++i) {
       auto *entry = inline_site->ranges.GetEntryAtIndex(i);
@@ -587,7 +589,8 @@ lldb::FunctionSP 
SymbolFileNativePDB::CreateFunction(PdbCompilandSymId func_id,
   auto ts = *ts_or_err;
   if (!ts)
     return func_sp;
-  ts->GetNativePDBParser()->EnsureFunction(func_id);
+  if (PdbAstBuilder *ast_builder = ts->GetNativePDBParser())
+    ast_builder->EnsureFunction(func_id);
 
   return func_sp;
 }
@@ -922,7 +925,9 @@ TypeSP SymbolFileNativePDB::CreateAndCacheType(PdbTypeSymId 
type_id) {
   if (!ts)
     return nullptr;
 
-  PdbAstBuilder* ast_builder = ts->GetNativePDBParser();
+  PdbAstBuilder *ast_builder = ts->GetNativePDBParser();
+  if (!ast_builder)
+    return nullptr;
   CompilerType ct = ast_builder->GetOrCreateType(best_decl_id);
   if (!ct)
     return nullptr;
@@ -1022,8 +1027,10 @@ VariableSP 
SymbolFileNativePDB::CreateGlobalVariable(PdbGlobalSymId var_id) {
   auto ts = *ts_or_err;
   if (!ts)
     return nullptr;
-
-  ts->GetNativePDBParser()->EnsureVariable(var_id);
+  PdbAstBuilder *ast_builder = ts->GetNativePDBParser();
+  if (!ast_builder)
+    return nullptr;
+  ast_builder->EnsureVariable(var_id);
 
   ModuleSP module_sp = GetObjectFile()->GetModule();
   DWARFExpressionList location(
@@ -1123,10 +1130,12 @@ Block 
*SymbolFileNativePDB::GetOrCreateBlock(PdbCompilandSymId block_id) {
 
 void SymbolFileNativePDB::ParseDeclsForContext(
     lldb_private::CompilerDeclContext decl_ctx) {
-  TypeSystem* ts_or_err = decl_ctx.GetTypeSystem();
+  TypeSystem *ts_or_err = decl_ctx.GetTypeSystem();
   if (!ts_or_err)
     return;
-  PdbAstBuilder* ast_builder = ts_or_err->GetNativePDBParser();
+  PdbAstBuilder *ast_builder = ts_or_err->GetNativePDBParser();
+  if (!ast_builder)
+    return;
   ast_builder->ParseDeclsForContext(decl_ctx);
 }
 
@@ -1830,7 +1839,8 @@ void SymbolFileNativePDB::DumpClangAST(Stream &s, 
llvm::StringRef filter,
   TypeSystemClang *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
   if (!clang)
     return;
-  clang->GetNativePDBParser()->Dump(s, filter, show_color);
+  if (PdbAstBuilder *ast_builder = clang->GetNativePDBParser())
+    ast_builder->Dump(s, filter, show_color);
 }
 
 void SymbolFileNativePDB::CacheGlobalBaseNames() {

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to