[LLDB][NativePDB] Add nullptr checking.

This commit is contained in:
Zequan Wu 2022-08-15 19:34:13 -07:00
parent 130b1816c5
commit 7ebbef2b30
2 changed files with 24 additions and 11 deletions

View File

@ -501,6 +501,8 @@ clang::Decl *PdbAstBuilder::GetOrCreateSymbolForId(PdbCompilandSymId id) {
if (isLocalVariableType(cvs.kind())) {
clang::DeclContext *scope = GetParentDeclContext(id);
if (!scope)
return nullptr;
clang::Decl *scope_decl = clang::Decl::castFromDeclContext(scope);
PdbCompilandSymId scope_id =
PdbSymUid(m_decl_to_status[scope_decl].uid).asCompilandSym();
@ -1010,7 +1012,7 @@ PdbAstBuilder::GetOrCreateTypedefDecl(PdbGlobalSymId id) {
PdbTypeSymId real_type_id{udt.Type, false};
clang::QualType qt = GetOrCreateType(real_type_id);
if (qt.isNull())
if (qt.isNull() || !scope)
return nullptr;
std::string uname = std::string(DropNameScope(udt.Name));
@ -1265,7 +1267,7 @@ PdbAstBuilder::CreateFunctionDeclFromId(PdbTypeSymId func_tid,
lldbassert(false && "Invalid function id type!");
}
clang::QualType func_qt = GetOrCreateType(func_ti);
if (func_qt.isNull())
if (func_qt.isNull() || !parent)
return nullptr;
CompilerType func_ct = ToCompilerType(func_qt);
uint32_t param_count =
@ -1280,6 +1282,8 @@ PdbAstBuilder::GetOrCreateFunctionDecl(PdbCompilandSymId func_id) {
return llvm::dyn_cast<clang::FunctionDecl>(decl);
clang::DeclContext *parent = GetParentDeclContext(PdbSymUid(func_id));
if (!parent)
return nullptr;
std::string context_name;
if (clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(parent)) {
context_name = ns->getQualifiedNameAsString();

View File

@ -345,10 +345,13 @@ Block &SymbolFileNativePDB::CreateBlock(PdbCompilandSymId block_id) {
// This is a function. It must be global. Creating the Function entry
// for it automatically creates a block for it.
FunctionSP func = GetOrCreateFunction(block_id, *comp_unit);
Block &block = func->GetBlock(false);
if (block.GetNumRanges() == 0)
block.AddRange(Block::Range(0, func->GetAddressRange().GetByteSize()));
return block;
if (func) {
Block &block = func->GetBlock(false);
if (block.GetNumRanges() == 0)
block.AddRange(Block::Range(0, func->GetAddressRange().GetByteSize()));
return block;
}
break;
}
case S_BLOCK32: {
// This is a block. Its parent is either a function or another block. In
@ -1024,11 +1027,13 @@ uint32_t SymbolFileNativePDB::ResolveSymbolContext(
continue;
if (type == PDB_SymType::Function) {
sc.function = GetOrCreateFunction(csid, *sc.comp_unit).get();
Block &block = sc.function->GetBlock(true);
addr_t func_base =
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
addr_t offset = file_addr - func_base;
sc.block = block.FindInnermostBlockByOffset(offset);
if (sc.function) {
Block &block = sc.function->GetBlock(true);
addr_t func_base =
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
addr_t offset = file_addr - func_base;
sc.block = block.FindInnermostBlockByOffset(offset);
}
}
if (type == PDB_SymType::Block) {
@ -1908,6 +1913,8 @@ SymbolFileNativePDB::GetDeclContextForUID(lldb::user_id_t uid) {
CompilerDeclContext
SymbolFileNativePDB::GetDeclContextContainingUID(lldb::user_id_t uid) {
clang::DeclContext *context = m_ast->GetParentDeclContext(PdbSymUid(uid));
if (!context)
return CompilerDeclContext();
return m_ast->ToCompilerDeclContext(*context);
}
@ -1929,6 +1936,8 @@ Type *SymbolFileNativePDB::ResolveTypeUID(lldb::user_id_t type_uid) {
return nullptr;
TypeSP type_sp = CreateAndCacheType(type_id);
if (!type_sp)
return nullptr;
return &*type_sp;
}