diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode.h b/renderdoc/driver/shaders/dxil/dxil_bytecode.h index 54a1f33c5..c45a96fe0 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode.h +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode.h @@ -1589,8 +1589,11 @@ protected: void ParseConstant(ValueList &values, const LLVMBC::BlockOrRecord &constant); bool ParseDebugMetaRecord(MetadataList &metadata, const LLVMBC::BlockOrRecord &metaRecord, Metadata &meta); - rdcstr GetDebugVarName(const DIBase *d); - rdcstr GetFunctionScopeName(const DIBase *d); + rdcstr GetDebugVarName(const DIBase *d) const; + rdcstr GetFunctionScopeName(const DIBase *d) const; + rdcstr GetDebugScopeFilePath(const DIBase *d) const; + uint64_t GetDebugScopeLine(const DIBase *d) const; + const Metadata *GetDebugScopeParent(const DIBase *d) const; rdcstr GetValueSymtabString(Value *v); void SetValueSymtabString(Value *v, const rdcstr &s); diff --git a/renderdoc/driver/shaders/dxil/dxil_debuginfo.cpp b/renderdoc/driver/shaders/dxil/dxil_debuginfo.cpp index 89aba8759..b1952eefe 100644 --- a/renderdoc/driver/shaders/dxil/dxil_debuginfo.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_debuginfo.cpp @@ -282,7 +282,72 @@ bool Program::ParseDebugMetaRecord(MetadataList &metadata, const LLVMBC::BlockOr return true; }; -rdcstr Program::GetDebugVarName(const DIBase *d) +const Metadata *Program::GetDebugScopeParent(const DIBase *d) const +{ + if(d->type == DIBase::Subprogram) + return d->As()->scope; + else if(d->type == DIBase::LexicalBlock) + return d->As()->scope; + + return NULL; +} + +uint64_t Program::GetDebugScopeLine(const DIBase *d) const +{ + if(d->type == DIBase::Subprogram) + return d->As()->line; + else if(d->type == DIBase::LexicalBlock) + return d->As()->line; + else if(d->type == DIBase::File) + return 0; + + RDCERR("Unexpected type %s in GetDebugScopeLine", ToStr(d->type).c_str()); + return UINT64_MAX; +} + +rdcstr Program::GetDebugScopeFilePath(const DIBase *d) const +{ + const Metadata *scope = NULL; + if(d->type == DIBase::Subprogram) + scope = d->As()->scope; + else if(d->type == DIBase::LexicalBlock) + scope = d->As()->scope; + else if(d->type == DIBase::LocalVariable) + scope = d->As()->scope; + + while(scope && scope->dwarf) + { + if(scope->dwarf->type == DIBase::Subprogram) + { + scope = scope->dwarf->As()->scope; + continue; + } + else if(scope->dwarf->type == DIBase::LexicalBlock) + { + scope = scope->dwarf->As()->scope; + continue; + } + break; + } + if(d->type != DIBase::File) + { + if(!scope || !scope->dwarf) + return "???"; + } + + const DXIL::DIBase *dwarf = (d->type != DIBase::File) ? scope->dwarf : d; + RDCASSERT(dwarf->type == DIBase::File); + const DIFile *f = dwarf->As(); + + rdcstr filePath; + if(f->dir) + filePath = f->dir->str + "/"; + + filePath += f->file->str; + return filePath; +} + +rdcstr Program::GetDebugVarName(const DIBase *d) const { if(d->type == DIBase::LocalVariable) return *d->As()->name; @@ -291,7 +356,7 @@ rdcstr Program::GetDebugVarName(const DIBase *d) return "???"; } -rdcstr Program::GetFunctionScopeName(const DIBase *d) +rdcstr Program::GetFunctionScopeName(const DIBase *d) const { const Metadata *scope = NULL; if(d->type == DIBase::LocalVariable)