Defensive code when walking meta data scopes

This commit is contained in:
Jake Turner
2024-12-19 19:30:09 +00:00
parent 57e875e866
commit 2481208ba4
2 changed files with 7 additions and 1 deletions
+5 -1
View File
@@ -6233,7 +6233,8 @@ ScopedDebugData *Debugger::FindScopedDebugData(const DXIL::Metadata *md) const
const DXIL::Metadata *Debugger::GetMDScope(const DXIL::Metadata *scopeMD) const
{
// Iterate upwards to find DIFile, DISubprogram or DILexicalBlock scope
while((scopeMD->dwarf->type != DIBase::File) && (scopeMD->dwarf->type != DIBase::Subprogram) &&
while(scopeMD && (scopeMD->dwarf->type != DIBase::File) &&
(scopeMD->dwarf->type != DIBase::Subprogram) &&
(scopeMD->dwarf->type != DIBase::LexicalBlock))
scopeMD = m_Program->GetDebugScopeParent(scopeMD->dwarf);
@@ -6243,6 +6244,8 @@ const DXIL::Metadata *Debugger::GetMDScope(const DXIL::Metadata *scopeMD) const
ScopedDebugData *Debugger::AddScopedDebugData(const DXIL::Metadata *scopeMD)
{
scopeMD = GetMDScope(scopeMD);
if(scopeMD == NULL)
return NULL;
ScopedDebugData *scope = FindScopedDebugData(scopeMD);
// Add a new DebugScope
if(!scope)
@@ -6518,6 +6521,7 @@ const TypeData &Debugger::AddDebugType(const DXIL::Metadata *typeMD)
switch(derivedType->tag)
{
case DW_TAG_const_type:
case DW_TAG_pointer_type:
case DW_TAG_typedef: typeData = AddDebugType(derivedType->base); break;
default:
RDCERR("Unhandled DIDerivedType DIDerivedType Tag type %s",
@@ -288,6 +288,8 @@ const Metadata *Program::GetDebugScopeParent(const DIBase *d) const
return d->As<DISubprogram>()->scope;
else if(d->type == DIBase::LexicalBlock)
return d->As<DILexicalBlock>()->scope;
else if(d->type == DIBase::CompositeType)
return d->As<DICompositeType>()->file;
return NULL;
}