Skip to content

Commit

Permalink
[LLDB][NativePDB] Add nullptr checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZequanWu committed Aug 16, 2022
1 parent 130b181 commit 7ebbef2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
8 changes: 6 additions & 2 deletions lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 =
Expand All @@ -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();
Expand Down
27 changes: 18 additions & 9 deletions lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 7ebbef2

Please sign in to comment.