[Lldb-commits] [lldb] [LLDB][NativePDB] Add PdbAstBuilder null checks (PR #176065)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 14 16:20:54 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Leonard Grey (speednoisemovement)
<details>
<summary>Changes</summary>
`TypeSystem::GetNativePDBParser` returns `nullptr` by default, so using the result without checking can cause a crash.
---
Full diff: https://github.com/llvm/llvm-project/pull/176065.diff
1 Files Affected:
- (modified) lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp (+19-9)
``````````diff
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() {
``````````
</details>
https://github.com/llvm/llvm-project/pull/176065
More information about the lldb-commits
mailing list