[llvm] r305248 - [pdb] Don't choke on unknown symbol types.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 12 16:10:32 PDT 2017


Author: zturner
Date: Mon Jun 12 18:10:31 2017
New Revision: 305248

URL: http://llvm.org/viewvc/llvm-project?rev=305248&view=rev
Log:
[pdb] Don't choke on unknown symbol types.

When we get an unknown symbol type, we might as well at least
dump it.  Same goes for round-tripping through YAML, we can
dump the record contents as raw bytes even if we don't know
how to interpret it semantically.

Added:
    llvm/trunk/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml
    llvm/trunk/test/DebugInfo/PDB/pdb-unknown-symbol.test
Modified:
    llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp

Modified: llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp?rev=305248&r1=305247&r2=305248&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp Mon Jun 12 18:10:31 2017
@@ -183,8 +183,47 @@ template <typename T> struct SymbolRecor
   mutable T Symbol;
 };
 
+struct UnknownSymbolRecord : public SymbolRecordBase {
+  explicit UnknownSymbolRecord(codeview::SymbolKind K) : SymbolRecordBase(K) {}
+
+  void map(yaml::IO &io) override;
+
+  CVSymbol toCodeViewSymbol(BumpPtrAllocator &Allocator,
+                            CodeViewContainer Container) const override {
+    RecordPrefix Prefix;
+    uint32_t TotalLen = sizeof(RecordPrefix) + Data.size();
+    Prefix.RecordKind = Kind;
+    Prefix.RecordLen = TotalLen - 2;
+    uint8_t *Buffer = Allocator.Allocate<uint8_t>(TotalLen);
+    ::memcpy(Buffer, &Prefix, sizeof(RecordPrefix));
+    ::memcpy(Buffer + sizeof(RecordPrefix), Data.data(), Data.size());
+    return CVSymbol(Kind, ArrayRef<uint8_t>(Buffer, TotalLen));
+  }
+  Error fromCodeViewSymbol(CVSymbol CVS) override {
+    this->Kind = CVS.kind();
+    Data = CVS.RecordData.drop_front(sizeof(RecordPrefix));
+    return Error::success();
+  }
+
+  std::vector<uint8_t> Data;
+};
+
 template <> void SymbolRecordImpl<ScopeEndSym>::map(IO &IO) {}
 
+void UnknownSymbolRecord::map(yaml::IO &io) {
+  yaml::BinaryRef Binary;
+  if (io.outputting())
+    Binary = yaml::BinaryRef(Data);
+  io.mapRequired("Data", Binary);
+  if (!io.outputting()) {
+    std::string Str;
+    raw_string_ostream OS(Str);
+    Binary.writeAsBinary(OS);
+    OS.flush();
+    Data.assign(Str.begin(), Str.end());
+  }
+}
+
 template <> void SymbolRecordImpl<Thunk32Sym>::map(IO &IO) {
   IO.mapRequired("Parent", Symbol.Parent);
   IO.mapRequired("End", Symbol.End);
@@ -461,7 +500,7 @@ static inline Expected<CodeViewYAML::Sym
 fromCodeViewSymbolImpl(CVSymbol Symbol) {
   CodeViewYAML::SymbolRecord Result;
 
-  auto Impl = std::make_shared<SymbolRecordImpl<SymbolType>>(Symbol.kind());
+  auto Impl = std::make_shared<SymbolType>(Symbol.kind());
   if (auto EC = Impl->fromCodeViewSymbol(Symbol))
     return std::move(EC);
   Result.Symbol = Impl;
@@ -472,12 +511,13 @@ Expected<CodeViewYAML::SymbolRecord>
 CodeViewYAML::SymbolRecord::fromCodeViewSymbol(CVSymbol Symbol) {
 #define SYMBOL_RECORD(EnumName, EnumVal, ClassName)                            \
   case EnumName:                                                               \
-    return fromCodeViewSymbolImpl<ClassName>(Symbol);
+    return fromCodeViewSymbolImpl<SymbolRecordImpl<ClassName>>(Symbol);
 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)           \
   SYMBOL_RECORD(EnumName, EnumVal, ClassName)
   switch (Symbol.kind()) {
 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
-  default: { llvm_unreachable("Unknown symbol kind!"); }
+  default:
+    return fromCodeViewSymbolImpl<UnknownSymbolRecord>(Symbol);
   }
   return make_error<CodeViewError>(cv_error_code::corrupt_record);
 }
@@ -486,7 +526,7 @@ template <typename ConcreteType>
 static void mapSymbolRecordImpl(IO &IO, const char *Class, SymbolKind Kind,
                                 CodeViewYAML::SymbolRecord &Obj) {
   if (!IO.outputting())
-    Obj.Symbol = std::make_shared<SymbolRecordImpl<ConcreteType>>(Kind);
+    Obj.Symbol = std::make_shared<ConcreteType>(Kind);
 
   IO.mapRequired(Class, *Obj.Symbol);
 }
@@ -500,12 +540,14 @@ void MappingTraits<CodeViewYAML::SymbolR
 
 #define SYMBOL_RECORD(EnumName, EnumVal, ClassName)                            \
   case EnumName:                                                               \
-    mapSymbolRecordImpl<ClassName>(IO, #ClassName, Kind, Obj);                 \
+    mapSymbolRecordImpl<SymbolRecordImpl<ClassName>>(IO, #ClassName, Kind,     \
+                                                     Obj);                     \
     break;
 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)           \
   SYMBOL_RECORD(EnumName, EnumVal, ClassName)
   switch (Kind) {
 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
-  default: { llvm_unreachable("Unknown symbol kind!"); }
+  default:
+    mapSymbolRecordImpl<UnknownSymbolRecord>(IO, "UnknownSym", Kind, Obj);
   }
 }

Added: llvm/trunk/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml?rev=305248&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml (added)
+++ llvm/trunk/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml Mon Jun 12 18:10:31 2017
@@ -0,0 +1,10 @@
+---
+DbiStream:
+  Modules:
+    - Module:          unknown-symbol.yaml
+      Modi:
+        Records:
+          - Kind:            S_ANNOTATION
+            UnknownSym:
+              Data:          123456789ABCDEF0
+...

Added: llvm/trunk/test/DebugInfo/PDB/pdb-unknown-symbol.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdb-unknown-symbol.test?rev=305248&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdb-unknown-symbol.test (added)
+++ llvm/trunk/test/DebugInfo/PDB/pdb-unknown-symbol.test Mon Jun 12 18:10:31 2017
@@ -0,0 +1,6 @@
+; RUN: llvm-pdbutil yaml2pdb -pdb=%t.pdb %p/Inputs/unknown-symbol.yaml
+; RUN: llvm-pdbutil pdb2yaml -minimal -module-syms -no-file-headers %t.pdb | FileCheck %s
+
+CHECK: - Kind:            S_ANNOTATION
+CHECK:   UnknownSym:
+CHECK:     Data:          123456789ABCDEF0




More information about the llvm-commits mailing list