From: Zachary Turner Date: Mon, 17 Dec 2018 16:15:36 +0000 (+0000) Subject: [PDB] Add some helper functions for working with scopes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a8e4afaa8d68a0856d950cddc9eb05951e977cda;p=llvm [PDB] Add some helper functions for working with scopes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349361 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/DebugInfo/CodeView/SymbolRecordHelpers.h b/include/llvm/DebugInfo/CodeView/SymbolRecordHelpers.h index 6bfd1b1eb21..3713fe118ea 100644 --- a/include/llvm/DebugInfo/CodeView/SymbolRecordHelpers.h +++ b/include/llvm/DebugInfo/CodeView/SymbolRecordHelpers.h @@ -51,6 +51,7 @@ inline bool symbolEndsScope(SymbolKind Kind) { /// Given a symbol P for which symbolOpensScope(P) == true, return the /// corresponding end offset. uint32_t getScopeEndOffset(const CVSymbol &Symbol); +uint32_t getScopeParentOffset(const CVSymbol &Symbol); CVSymbolArray limitSymbolArrayToScope(const CVSymbolArray &Symbols, uint32_t ScopeBegin); diff --git a/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h b/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h index 19b0ebdfac8..8d590df288f 100644 --- a/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h +++ b/include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h @@ -44,6 +44,8 @@ public: symbols(bool *HadError) const; const codeview::CVSymbolArray &getSymbolArray() const { return SymbolArray; } + const codeview::CVSymbolArray + getSymbolArrayForScope(uint32_t ScopeBegin) const; BinarySubstreamRef getSymbolsSubstream() const; BinarySubstreamRef getC11LinesSubstream() const; diff --git a/lib/DebugInfo/CodeView/SymbolRecordHelpers.cpp b/lib/DebugInfo/CodeView/SymbolRecordHelpers.cpp index 79f39591929..01746138ad1 100644 --- a/lib/DebugInfo/CodeView/SymbolRecordHelpers.cpp +++ b/lib/DebugInfo/CodeView/SymbolRecordHelpers.cpp @@ -21,8 +21,7 @@ template RecordT createRecord(const CVSymbol &sym) { return record; } -uint32_t -llvm::codeview::getScopeEndOffset(const llvm::codeview::CVSymbol &Sym) { +uint32_t llvm::codeview::getScopeEndOffset(const CVSymbol &Sym) { assert(symbolOpensScope(Sym.kind())); switch (Sym.kind()) { case SymbolKind::S_GPROC32: @@ -52,6 +51,37 @@ llvm::codeview::getScopeEndOffset(const llvm::codeview::CVSymbol &Sym) { } } +uint32_t +llvm::codeview::getScopeParentOffset(const llvm::codeview::CVSymbol &Sym) { + assert(symbolOpensScope(Sym.kind())); + switch (Sym.kind()) { + case SymbolKind::S_GPROC32: + case SymbolKind::S_LPROC32: + case SymbolKind::S_GPROC32_ID: + case SymbolKind::S_LPROC32_ID: + case SymbolKind::S_LPROC32_DPC: + case SymbolKind::S_LPROC32_DPC_ID: { + ProcSym Proc = createRecord(Sym); + return Proc.Parent; + } + case SymbolKind::S_BLOCK32: { + BlockSym Block = createRecord(Sym); + return Block.Parent; + } + case SymbolKind::S_THUNK32: { + Thunk32Sym Thunk = createRecord(Sym); + return Thunk.Parent; + } + case SymbolKind::S_INLINESITE: { + InlineSiteSym Site = createRecord(Sym); + return Site.Parent; + } + default: + assert(false && "Unknown record type"); + return 0; + } +} + CVSymbolArray llvm::codeview::limitSymbolArrayToScope(const CVSymbolArray &Symbols, uint32_t ScopeBegin) { diff --git a/lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp b/lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp index 5ff7c1574dd..8c97f4a012f 100644 --- a/lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp +++ b/lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp @@ -11,7 +11,9 @@ #include "llvm/ADT/iterator_range.h" #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" +#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h" #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" #include "llvm/Support/BinaryStreamReader.h" @@ -77,6 +79,11 @@ Error ModuleDebugStreamRef::reload() { return Error::success(); } +const codeview::CVSymbolArray +ModuleDebugStreamRef::getSymbolArrayForScope(uint32_t ScopeBegin) const { + return limitSymbolArrayToScope(SymbolArray, ScopeBegin); +} + BinarySubstreamRef ModuleDebugStreamRef::getSymbolsSubstream() const { return SymbolsSubstream; }