]> granicus.if.org Git - llvm/commitdiff
[PDB] Add some helper functions for working with scopes.
authorZachary Turner <zturner@google.com>
Mon, 17 Dec 2018 16:15:36 +0000 (16:15 +0000)
committerZachary Turner <zturner@google.com>
Mon, 17 Dec 2018 16:15:36 +0000 (16:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349361 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/CodeView/SymbolRecordHelpers.h
include/llvm/DebugInfo/PDB/Native/ModuleDebugStream.h
lib/DebugInfo/CodeView/SymbolRecordHelpers.cpp
lib/DebugInfo/PDB/Native/ModuleDebugStream.cpp

index 6bfd1b1eb217fb582b6fe264e8a145b39e67df10..3713fe118eaa9843e100ae60666d58dba4afad41 100644 (file)
@@ -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);
index 19b0ebdfac841b35fdcaba9db94ed57226d2a7fd..8d590df288f378d5010210beb2ccbd9820f0b39c 100644 (file)
@@ -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;
index 79f39591929ce786d2ed00041611b62241bcc9ad..01746138ad1f2df923ff1b1e721f0b140b3352c2 100644 (file)
@@ -21,8 +21,7 @@ template <typename RecordT> 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<ProcSym>(Sym);
+    return Proc.Parent;
+  }
+  case SymbolKind::S_BLOCK32: {
+    BlockSym Block = createRecord<BlockSym>(Sym);
+    return Block.Parent;
+  }
+  case SymbolKind::S_THUNK32: {
+    Thunk32Sym Thunk = createRecord<Thunk32Sym>(Sym);
+    return Thunk.Parent;
+  }
+  case SymbolKind::S_INLINESITE: {
+    InlineSiteSym Site = createRecord<InlineSiteSym>(Sym);
+    return Site.Parent;
+  }
+  default:
+    assert(false && "Unknown record type");
+    return 0;
+  }
+}
+
 CVSymbolArray
 llvm::codeview::limitSymbolArrayToScope(const CVSymbolArray &Symbols,
                                         uint32_t ScopeBegin) {
index 5ff7c1574dd45f16c2a63b1186e2927ab9c6a8d1..8c97f4a012f03d61fde19ae78fce6deab7006946 100644 (file)
@@ -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;
 }