diff --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp --- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp @@ -534,8 +534,12 @@ auto type_def = llvm::dyn_cast(&type); assert(type_def); + SymbolFile *symbol_file = m_ast.GetSymbolFile(); + if (!symbol_file) + return nullptr; + lldb_private::Type *target_type = - m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId()); + symbol_file->ResolveTypeUID(type_def->getTypeId()); if (!target_type) return nullptr; @@ -609,8 +613,13 @@ auto arg = arg_enum->getChildAtIndex(arg_idx); if (!arg) break; + + SymbolFile *symbol_file = m_ast.GetSymbolFile(); + if (!symbol_file) + return nullptr; + lldb_private::Type *arg_type = - m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId()); + symbol_file->ResolveTypeUID(arg->getSymIndexId()); // If there's some error looking up one of the dependent types of this // function signature, bail. if (!arg_type) @@ -621,8 +630,12 @@ lldbassert(arg_list.size() <= num_args); auto pdb_return_type = func_sig->getReturnType(); + SymbolFile *symbol_file = m_ast.GetSymbolFile(); + if (!symbol_file) + return nullptr; + lldb_private::Type *return_type = - m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId()); + symbol_file->ResolveTypeUID(pdb_return_type->getSymIndexId()); // If there's some error looking up one of the dependent types of this // function signature, bail. if (!return_type) @@ -654,10 +667,13 @@ if (uint64_t size = array_type->getLength()) bytes = size; + SymbolFile *symbol_file = m_ast.GetSymbolFile(); + if (!symbol_file) + return nullptr; + // If array rank > 0, PDB gives the element type at N=0. So element type // will parsed in the order N=0, N=1,..., N=rank sequentially. - lldb_private::Type *element_type = - m_ast.GetSymbolFile()->ResolveTypeUID(element_uid); + lldb_private::Type *element_type = symbol_file->ResolveTypeUID(element_uid); if (!element_type) return nullptr; @@ -711,7 +727,12 @@ case PDB_SymType::PointerType: { auto *pointer_type = llvm::dyn_cast(&type); assert(pointer_type); - Type *pointee_type = m_ast.GetSymbolFile()->ResolveTypeUID( + + SymbolFile *symbol_file = m_ast.GetSymbolFile(); + if (!symbol_file) + return nullptr; + + Type *pointee_type = symbol_file->ResolveTypeUID( pointer_type->getPointeeType()->getSymIndexId()); if (!pointee_type) return nullptr; @@ -719,8 +740,7 @@ if (pointer_type->isPointerToDataMember() || pointer_type->isPointerToMemberFunction()) { auto class_parent_uid = pointer_type->getRawSymbol().getClassParentId(); - auto class_parent_type = - m_ast.GetSymbolFile()->ResolveTypeUID(class_parent_uid); + auto class_parent_type = symbol_file->ResolveTypeUID(class_parent_uid); assert(class_parent_type); CompilerType pointer_ast_type; diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -9306,11 +9306,11 @@ std::vector TypeSystemClang::DeclContextFindDeclByName( void *opaque_decl_ctx, ConstString name, const bool ignore_using_decls) { std::vector found_decls; - if (opaque_decl_ctx) { + SymbolFile *symbol_file = GetSymbolFile(); + if (opaque_decl_ctx && symbol_file) { DeclContext *root_decl_ctx = (DeclContext *)opaque_decl_ctx; std::set searched; std::multimap search_queue; - SymbolFile *symbol_file = GetSymbolFile(); for (clang::DeclContext *decl_context = root_decl_ctx; decl_context != nullptr && found_decls.empty(); @@ -9404,10 +9404,10 @@ clang::DeclContext *child_decl_ctx, ConstString *child_name, CompilerType *child_type) { - if (frame_decl_ctx) { + SymbolFile *symbol_file = GetSymbolFile(); + if (frame_decl_ctx && symbol_file) { std::set searched; std::multimap search_queue; - SymbolFile *symbol_file = GetSymbolFile(); // Get the lookup scope for the decl we're trying to find. clang::DeclContext *parent_decl_ctx = child_decl_ctx->getParent(); diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -730,7 +730,8 @@ ModuleSP Type::GetExeModule() { if (m_compiler_type) { SymbolFile *symbol_file = m_compiler_type.GetTypeSystem()->GetSymbolFile(); - return symbol_file->GetObjectFile()->GetModule(); + if (symbol_file) + return symbol_file->GetObjectFile()->GetModule(); } return ModuleSP(); } diff --git a/lldb/unittests/Symbol/TestTypeSystemClang.cpp b/lldb/unittests/Symbol/TestTypeSystemClang.cpp --- a/lldb/unittests/Symbol/TestTypeSystemClang.cpp +++ b/lldb/unittests/Symbol/TestTypeSystemClang.cpp @@ -741,3 +741,15 @@ ScratchTypeSystemClang::IsolatedASTKind::CppModules, ScratchTypeSystemClang::InferIsolatedASTKindFromLangOpts(lang_opts)); } + +TEST_F(TestTypeSystemClang, GetExeModuleWhenMissingSymbolFile) { + CompilerType compiler_type = m_ast->GetBasicTypeFromAST(lldb::eBasicTypeInt); + lldb_private::Type t(0, nullptr, ConstString("MyType"), llvm::None, nullptr, + 0, {}, {}, compiler_type, + lldb_private::Type::ResolveState::Full); + // Test that getting the execution module when no type system is present + // is handled gracefully. + ModuleSP module = t.GetExeModule(); + EXPECT_EQ(module.get(), nullptr); +} +