[llvm] r310743 - [LLD/PDB] Write actual records to the globals stream.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 12:00:04 PDT 2017


Author: zturner
Date: Fri Aug 11 12:00:03 2017
New Revision: 310743

URL: http://llvm.org/viewvc/llvm-project?rev=310743&view=rev
Log:
[LLD/PDB] Write actual records to the globals stream.

Previously we were writing an empty globals stream.  Windows
tools interpret this as "private symbols are not present in
this PDB", even when they are, so we need to fix this.  Regardless,
without it we don't have information about global variables, so
we need to fix it anyway.  This patch does that.

With this patch, the "lm" command in WinDbg correctly reports
that we have private symbols available, but the "dv" command
still refuses to display local variables.

Differential Revision: https://reviews.llvm.org/D36535

Added:
    llvm/trunk/include/llvm/DebugInfo/CodeView/RecordName.h
    llvm/trunk/lib/DebugInfo/CodeView/RecordName.cpp
Removed:
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeName.h
    llvm/trunk/lib/DebugInfo/CodeView/TypeName.cpp
Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h
    llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt
    llvm/trunk/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp
    llvm/trunk/lib/DebugInfo/CodeView/TypeTableCollection.cpp
    llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp

Added: llvm/trunk/include/llvm/DebugInfo/CodeView/RecordName.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/RecordName.h?rev=310743&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/RecordName.h (added)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/RecordName.h Fri Aug 11 12:00:03 2017
@@ -0,0 +1,24 @@
+//===- RecordName.h ------------------------------------------- *- C++ --*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_CODEVIEW_RECORDNAME_H
+#define LLVM_DEBUGINFO_CODEVIEW_RECORDNAME_H
+
+#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
+#include "llvm/DebugInfo/CodeView/TypeCollection.h"
+#include "llvm/DebugInfo/CodeView/TypeIndex.h"
+
+namespace llvm {
+namespace codeview {
+std::string computeTypeName(TypeCollection &Types, TypeIndex Index);
+StringRef getSymbolName(CVSymbol Sym);
+} // namespace codeview
+} // namespace llvm
+
+#endif

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h?rev=310743&r1=310742&r2=310743&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDeserializer.h Fri Aug 11 12:00:03 2017
@@ -54,14 +54,12 @@ public:
 
   template <typename T>
   static Expected<T> deserializeAs(ArrayRef<uint8_t> Data) {
-    CVType CVT;
-    CVT.RecordData = Data;
-    MappingInfo I(CVT.content());
     const RecordPrefix *Prefix =
         reinterpret_cast<const RecordPrefix *>(Data.data());
     TypeRecordKind K =
         static_cast<TypeRecordKind>(uint16_t(Prefix->RecordKind));
     T Record(K);
+    CVType CVT(static_cast<TypeLeafKind>(K), Data);
     if (auto EC = deserializeAs<T>(CVT, Record))
       return std::move(EC);
     return Record;

Removed: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeName.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeName.h?rev=310742&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeName.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeName.h (removed)
@@ -1,22 +0,0 @@
-//===- TypeName.h --------------------------------------------- *- C++ --*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_CODEVIEW_TYPENAME_H
-#define LLVM_DEBUGINFO_CODEVIEW_TYPENAME_H
-
-#include "llvm/DebugInfo/CodeView/TypeCollection.h"
-#include "llvm/DebugInfo/CodeView/TypeIndex.h"
-
-namespace llvm {
-namespace codeview {
-std::string computeTypeName(TypeCollection &Types, TypeIndex Index);
-}
-} // namespace llvm
-
-#endif

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h?rev=310743&r1=310742&r2=310743&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeRecord.h Fri Aug 11 12:00:03 2017
@@ -412,6 +412,10 @@ public:
     return (Options & ClassOptions::HasUniqueName) != ClassOptions::None;
   }
 
+  bool isNested() const {
+    return (Options & ClassOptions::Nested) != ClassOptions::None;
+  }
+
   uint16_t getMemberCount() const { return MemberCount; }
   ClassOptions getOptions() const { return Options; }
   TypeIndex getFieldList() const { return FieldList; }

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h?rev=310743&r1=310742&r2=310743&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h Fri Aug 11 12:00:03 2017
@@ -58,6 +58,12 @@ public:
 
   void addPublicSymbol(const codeview::PublicSym32 &Pub);
 
+  void addGlobalSymbol(const codeview::ProcRefSym &Sym);
+  void addGlobalSymbol(const codeview::DataSym &Sym);
+  void addGlobalSymbol(const codeview::ConstantSym &Sym);
+  void addGlobalSymbol(const codeview::UDTSym &Sym);
+  void addGlobalSymbol(const codeview::CVSymbol &Sym);
+
 private:
   uint32_t calculatePublicsHashStreamSize() const;
   uint32_t calculateGlobalsHashStreamSize() const;

Modified: llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt?rev=310743&r1=310742&r2=310743&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt Fri Aug 11 12:00:03 2017
@@ -19,6 +19,7 @@ add_llvm_library(LLVMDebugInfoCodeView
   Formatters.cpp
   LazyRandomTypeCollection.cpp
   Line.cpp
+  RecordName.cpp
   RecordSerialization.cpp
   StringsAndChecksums.cpp
   SymbolRecordMapping.cpp
@@ -27,7 +28,6 @@ add_llvm_library(LLVMDebugInfoCodeView
   TypeDumpVisitor.cpp
   TypeIndex.cpp
   TypeIndexDiscovery.cpp
-  TypeName.cpp
   TypeRecordMapping.cpp
   TypeSerializer.cpp
   TypeStreamMerger.cpp

Modified: llvm/trunk/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp?rev=310743&r1=310742&r2=310743&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp Fri Aug 11 12:00:03 2017
@@ -13,7 +13,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
-#include "llvm/DebugInfo/CodeView/TypeName.h"
+#include "llvm/DebugInfo/CodeView/RecordName.h"
 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
 #include "llvm/Support/BinaryStreamReader.h"
 #include "llvm/Support/Endian.h"

Added: llvm/trunk/lib/DebugInfo/CodeView/RecordName.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/RecordName.cpp?rev=310743&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/RecordName.cpp (added)
+++ llvm/trunk/lib/DebugInfo/CodeView/RecordName.cpp Fri Aug 11 12:00:03 2017
@@ -0,0 +1,320 @@
+//===- RecordName.cpp ----------------------------------------- *- C++ --*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DebugInfo/CodeView/RecordName.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h"
+#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
+#include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h"
+#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
+#include "llvm/Support/FormatVariadic.h"
+
+using namespace llvm;
+using namespace llvm::codeview;
+
+namespace {
+class TypeNameComputer : public TypeVisitorCallbacks {
+  /// The type collection.  Used to calculate names of nested types.
+  TypeCollection &Types;
+  TypeIndex CurrentTypeIndex = TypeIndex::None();
+
+  /// Name of the current type. Only valid before visitTypeEnd.
+  SmallString<256> Name;
+
+public:
+  explicit TypeNameComputer(TypeCollection &Types) : Types(Types) {}
+
+  StringRef name() const { return Name; }
+
+  /// Paired begin/end actions for all types. Receives all record data,
+  /// including the fixed-length record prefix.
+  Error visitTypeBegin(CVType &Record) override;
+  Error visitTypeBegin(CVType &Record, TypeIndex Index) override;
+  Error visitTypeEnd(CVType &Record) override;
+
+#define TYPE_RECORD(EnumName, EnumVal, Name)                                   \
+  Error visitKnownRecord(CVType &CVR, Name##Record &Record) override;
+#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
+#define MEMBER_RECORD(EnumName, EnumVal, Name)
+#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
+};
+} // namespace
+
+Error TypeNameComputer::visitTypeBegin(CVType &Record) {
+  llvm_unreachable("Must call visitTypeBegin with a TypeIndex!");
+  return Error::success();
+}
+
+Error TypeNameComputer::visitTypeBegin(CVType &Record, TypeIndex Index) {
+  // Reset Name to the empty string. If the visitor sets it, we know it.
+  Name = "";
+  CurrentTypeIndex = Index;
+  return Error::success();
+}
+
+Error TypeNameComputer::visitTypeEnd(CVType &CVR) { return Error::success(); }
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR,
+                                         FieldListRecord &FieldList) {
+  Name = "<field list>";
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVRecord<TypeLeafKind> &CVR,
+                                         StringIdRecord &String) {
+  Name = String.getString();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, ArgListRecord &Args) {
+  auto Indices = Args.getIndices();
+  uint32_t Size = Indices.size();
+  Name = "(";
+  for (uint32_t I = 0; I < Size; ++I) {
+    assert(Indices[I] < CurrentTypeIndex);
+
+    Name.append(Types.getTypeName(Indices[I]));
+    if (I + 1 != Size)
+      Name.append(", ");
+  }
+  Name.push_back(')');
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR,
+                                         StringListRecord &Strings) {
+  auto Indices = Strings.getIndices();
+  uint32_t Size = Indices.size();
+  Name = "\"";
+  for (uint32_t I = 0; I < Size; ++I) {
+    Name.append(Types.getTypeName(Indices[I]));
+    if (I + 1 != Size)
+      Name.append("\" \"");
+  }
+  Name.push_back('\"');
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, ClassRecord &Class) {
+  Name = Class.getName();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, UnionRecord &Union) {
+  Name = Union.getName();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, EnumRecord &Enum) {
+  Name = Enum.getName();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, ArrayRecord &AT) {
+  Name = AT.getName();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, VFTableRecord &VFT) {
+  Name = VFT.getName();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, MemberFuncIdRecord &Id) {
+  Name = Id.getName();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, ProcedureRecord &Proc) {
+  StringRef Ret = Types.getTypeName(Proc.getReturnType());
+  StringRef Params = Types.getTypeName(Proc.getArgumentList());
+  Name = formatv("{0} {1}", Ret, Params).sstr<256>();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR,
+                                         MemberFunctionRecord &MF) {
+  StringRef Ret = Types.getTypeName(MF.getReturnType());
+  StringRef Class = Types.getTypeName(MF.getClassType());
+  StringRef Params = Types.getTypeName(MF.getArgumentList());
+  Name = formatv("{0} {1}::{2}", Ret, Class, Params).sstr<256>();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, FuncIdRecord &Func) {
+  Name = Func.getName();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) {
+  Name = TS.getName();
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) {
+
+  if (Ptr.isPointerToMember()) {
+    const MemberPointerInfo &MI = Ptr.getMemberInfo();
+
+    StringRef Pointee = Types.getTypeName(Ptr.getReferentType());
+    StringRef Class = Types.getTypeName(MI.getContainingType());
+    Name = formatv("{0} {1}::*", Pointee, Class);
+  } else {
+    if (Ptr.isConst())
+      Name.append("const ");
+    if (Ptr.isVolatile())
+      Name.append("volatile ");
+    if (Ptr.isUnaligned())
+      Name.append("__unaligned ");
+
+    Name.append(Types.getTypeName(Ptr.getReferentType()));
+
+    if (Ptr.getMode() == PointerMode::LValueReference)
+      Name.append("&");
+    else if (Ptr.getMode() == PointerMode::RValueReference)
+      Name.append("&&");
+    else if (Ptr.getMode() == PointerMode::Pointer)
+      Name.append("*");
+  }
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, ModifierRecord &Mod) {
+  uint16_t Mods = static_cast<uint16_t>(Mod.getModifiers());
+
+  SmallString<256> TypeName;
+  if (Mods & uint16_t(ModifierOptions::Const))
+    Name.append("const ");
+  if (Mods & uint16_t(ModifierOptions::Volatile))
+    Name.append("volatile ");
+  if (Mods & uint16_t(ModifierOptions::Unaligned))
+    Name.append("__unaligned ");
+  Name.append(Types.getTypeName(Mod.getModifiedType()));
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR,
+                                         VFTableShapeRecord &Shape) {
+  Name = formatv("<vftable {0} methods>", Shape.getEntryCount());
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(
+    CVType &CVR, UdtModSourceLineRecord &ModSourceLine) {
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR,
+                                         UdtSourceLineRecord &SourceLine) {
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, BitFieldRecord &BF) {
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR,
+                                         MethodOverloadListRecord &Overloads) {
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, BuildInfoRecord &BI) {
+  return Error::success();
+}
+
+Error TypeNameComputer::visitKnownRecord(CVType &CVR, LabelRecord &R) {
+  return Error::success();
+}
+
+std::string llvm::codeview::computeTypeName(TypeCollection &Types,
+                                            TypeIndex Index) {
+  TypeNameComputer Computer(Types);
+  CVType Record = Types.getType(Index);
+  if (auto EC = visitTypeRecord(Record, Index, Computer)) {
+    consumeError(std::move(EC));
+    return "<unknown UDT>";
+  }
+  return Computer.name();
+}
+
+static int getSymbolNameOffset(CVSymbol Sym) {
+  switch (Sym.kind()) {
+  // See ProcSym
+  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:
+    return 35;
+  // See Thunk32Sym
+  case SymbolKind::S_THUNK32:
+    return 21;
+  // See SectionSym
+  case SymbolKind::S_SECTION:
+    return 16;
+  // See CoffGroupSym
+  case SymbolKind::S_COFFGROUP:
+    return 14;
+  // See PublicSym32, FileStaticSym, RegRelativeSym, DataSym, ThreadLocalDataSym
+  case SymbolKind::S_PUB32:
+  case SymbolKind::S_FILESTATIC:
+  case SymbolKind::S_REGREL32:
+  case SymbolKind::S_GDATA32:
+  case SymbolKind::S_LDATA32:
+  case SymbolKind::S_LMANDATA:
+  case SymbolKind::S_GMANDATA:
+  case SymbolKind::S_LTHREAD32:
+  case SymbolKind::S_GTHREAD32:
+    return 10;
+  // See RegisterSym and LocalSym
+  case SymbolKind::S_REGISTER:
+  case SymbolKind::S_LOCAL:
+    return 6;
+  // See BlockSym
+  case SymbolKind::S_BLOCK32:
+    return 18;
+  // See LabelSym
+  case SymbolKind::S_LABEL32:
+    return 7;
+  // See ObjNameSym, ExportSym, and UDTSym
+  case SymbolKind::S_OBJNAME:
+  case SymbolKind::S_EXPORT:
+  case SymbolKind::S_UDT:
+    return 4;
+  // See BPRelativeSym
+  case SymbolKind::S_BPREL32:
+    return 8;
+  default:
+    return -1;
+  }
+}
+
+StringRef llvm::codeview::getSymbolName(CVSymbol Sym) {
+  if (Sym.kind() == SymbolKind::S_CONSTANT) {
+    // S_CONSTANT is preceded by an APSInt, which has a variable length.  So we
+    // have to do a full deserialization.
+    BinaryStreamReader Reader(Sym.content(), llvm::support::little);
+    // The container doesn't matter for single records.
+    SymbolRecordMapping Mapping(Reader, CodeViewContainer::ObjectFile);
+    ConstantSym Const(SymbolKind::S_CONSTANT);
+    cantFail(Mapping.visitSymbolBegin(Sym));
+    cantFail(Mapping.visitKnownRecord(Sym, Const));
+    cantFail(Mapping.visitSymbolEnd(Sym));
+    return Const.Name;
+  }
+
+  int Offset = getSymbolNameOffset(Sym);
+  if (Offset == -1)
+    return StringRef();
+
+  StringRef StringData = toStringRef(Sym.content()).drop_front(Offset);
+  return StringData.split('\0').first;
+}

Removed: llvm/trunk/lib/DebugInfo/CodeView/TypeName.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeName.cpp?rev=310742&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeName.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeName.cpp (removed)
@@ -1,243 +0,0 @@
-//===- TypeName.cpp ------------------------------------------- *- C++ --*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/DebugInfo/CodeView/TypeName.h"
-
-#include "llvm/ADT/SmallString.h"
-#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
-#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
-#include "llvm/Support/FormatVariadic.h"
-
-using namespace llvm;
-using namespace llvm::codeview;
-
-namespace {
-class TypeNameComputer : public TypeVisitorCallbacks {
-  /// The type collection.  Used to calculate names of nested types.
-  TypeCollection &Types;
-  TypeIndex CurrentTypeIndex = TypeIndex::None();
-
-  /// Name of the current type. Only valid before visitTypeEnd.
-  SmallString<256> Name;
-
-public:
-  explicit TypeNameComputer(TypeCollection &Types) : Types(Types) {}
-
-  StringRef name() const { return Name; }
-
-  /// Paired begin/end actions for all types. Receives all record data,
-  /// including the fixed-length record prefix.
-  Error visitTypeBegin(CVType &Record) override;
-  Error visitTypeBegin(CVType &Record, TypeIndex Index) override;
-  Error visitTypeEnd(CVType &Record) override;
-
-#define TYPE_RECORD(EnumName, EnumVal, Name)                                   \
-  Error visitKnownRecord(CVType &CVR, Name##Record &Record) override;
-#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
-#define MEMBER_RECORD(EnumName, EnumVal, Name)
-#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
-};
-} // namespace
-
-Error TypeNameComputer::visitTypeBegin(CVType &Record) {
-  llvm_unreachable("Must call visitTypeBegin with a TypeIndex!");
-  return Error::success();
-}
-
-Error TypeNameComputer::visitTypeBegin(CVType &Record, TypeIndex Index) {
-  // Reset Name to the empty string. If the visitor sets it, we know it.
-  Name = "";
-  CurrentTypeIndex = Index;
-  return Error::success();
-}
-
-Error TypeNameComputer::visitTypeEnd(CVType &CVR) { return Error::success(); }
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR,
-                                         FieldListRecord &FieldList) {
-  Name = "<field list>";
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVRecord<TypeLeafKind> &CVR,
-                                         StringIdRecord &String) {
-  Name = String.getString();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, ArgListRecord &Args) {
-  auto Indices = Args.getIndices();
-  uint32_t Size = Indices.size();
-  Name = "(";
-  for (uint32_t I = 0; I < Size; ++I) {
-    assert(Indices[I] < CurrentTypeIndex);
-
-    Name.append(Types.getTypeName(Indices[I]));
-    if (I + 1 != Size)
-      Name.append(", ");
-  }
-  Name.push_back(')');
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR,
-                                         StringListRecord &Strings) {
-  auto Indices = Strings.getIndices();
-  uint32_t Size = Indices.size();
-  Name = "\"";
-  for (uint32_t I = 0; I < Size; ++I) {
-    Name.append(Types.getTypeName(Indices[I]));
-    if (I + 1 != Size)
-      Name.append("\" \"");
-  }
-  Name.push_back('\"');
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, ClassRecord &Class) {
-  Name = Class.getName();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, UnionRecord &Union) {
-  Name = Union.getName();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, EnumRecord &Enum) {
-  Name = Enum.getName();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, ArrayRecord &AT) {
-  Name = AT.getName();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, VFTableRecord &VFT) {
-  Name = VFT.getName();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, MemberFuncIdRecord &Id) {
-  Name = Id.getName();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, ProcedureRecord &Proc) {
-  StringRef Ret = Types.getTypeName(Proc.getReturnType());
-  StringRef Params = Types.getTypeName(Proc.getArgumentList());
-  Name = formatv("{0} {1}", Ret, Params).sstr<256>();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR,
-                                         MemberFunctionRecord &MF) {
-  StringRef Ret = Types.getTypeName(MF.getReturnType());
-  StringRef Class = Types.getTypeName(MF.getClassType());
-  StringRef Params = Types.getTypeName(MF.getArgumentList());
-  Name = formatv("{0} {1}::{2}", Ret, Class, Params).sstr<256>();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, FuncIdRecord &Func) {
-  Name = Func.getName();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) {
-  Name = TS.getName();
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) {
-
-  if (Ptr.isPointerToMember()) {
-    const MemberPointerInfo &MI = Ptr.getMemberInfo();
-
-    StringRef Pointee = Types.getTypeName(Ptr.getReferentType());
-    StringRef Class = Types.getTypeName(MI.getContainingType());
-    Name = formatv("{0} {1}::*", Pointee, Class);
-  } else {
-    if (Ptr.isConst())
-      Name.append("const ");
-    if (Ptr.isVolatile())
-      Name.append("volatile ");
-    if (Ptr.isUnaligned())
-      Name.append("__unaligned ");
-
-    Name.append(Types.getTypeName(Ptr.getReferentType()));
-
-    if (Ptr.getMode() == PointerMode::LValueReference)
-      Name.append("&");
-    else if (Ptr.getMode() == PointerMode::RValueReference)
-      Name.append("&&");
-    else if (Ptr.getMode() == PointerMode::Pointer)
-      Name.append("*");
-  }
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, ModifierRecord &Mod) {
-  uint16_t Mods = static_cast<uint16_t>(Mod.getModifiers());
-
-  SmallString<256> TypeName;
-  if (Mods & uint16_t(ModifierOptions::Const))
-    Name.append("const ");
-  if (Mods & uint16_t(ModifierOptions::Volatile))
-    Name.append("volatile ");
-  if (Mods & uint16_t(ModifierOptions::Unaligned))
-    Name.append("__unaligned ");
-  Name.append(Types.getTypeName(Mod.getModifiedType()));
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR,
-                                         VFTableShapeRecord &Shape) {
-  Name = formatv("<vftable {0} methods>", Shape.getEntryCount());
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(
-    CVType &CVR, UdtModSourceLineRecord &ModSourceLine) {
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR,
-                                         UdtSourceLineRecord &SourceLine) {
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, BitFieldRecord &BF) {
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR,
-                                         MethodOverloadListRecord &Overloads) {
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, BuildInfoRecord &BI) {
-  return Error::success();
-}
-
-Error TypeNameComputer::visitKnownRecord(CVType &CVR, LabelRecord &R) {
-  return Error::success();
-}
-
-std::string llvm::codeview::computeTypeName(TypeCollection &Types,
-                                            TypeIndex Index) {
-  TypeNameComputer Computer(Types);
-  CVType Record = Types.getType(Index);
-  if (auto EC = visitTypeRecord(Record, Index, Computer)) {
-    consumeError(std::move(EC));
-    return "<unknown UDT>";
-  }
-  return Computer.name();
-}

Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeTableCollection.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeTableCollection.cpp?rev=310743&r1=310742&r2=310743&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeTableCollection.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeTableCollection.cpp Fri Aug 11 12:00:03 2017
@@ -10,7 +10,7 @@
 #include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
 
 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
-#include "llvm/DebugInfo/CodeView/TypeName.h"
+#include "llvm/DebugInfo/CodeView/RecordName.h"
 #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
 #include "llvm/Support/BinaryByteStream.h"
 #include "llvm/Support/BinaryStreamReader.h"

Modified: llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp?rev=310743&r1=310742&r2=310743&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp Fri Aug 11 12:00:03 2017
@@ -9,6 +9,7 @@
 
 #include "llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h"
 
+#include "llvm/DebugInfo/CodeView/RecordName.h"
 #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
 #include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
@@ -27,13 +28,6 @@ using namespace llvm::msf;
 using namespace llvm::pdb;
 using namespace llvm::codeview;
 
-static StringRef getSymbolName(const CVSymbol &Sym) {
-  assert(Sym.kind() == S_PUB32 && "handle other kinds");
-  PublicSym32 PSL =
-      cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(Sym));
-  return PSL.Name;
-}
-
 struct llvm::pdb::GSIHashStreamBuilder {
   std::vector<CVSymbol> Records;
   uint32_t StreamIndex;
@@ -45,6 +39,13 @@ struct llvm::pdb::GSIHashStreamBuilder {
   uint32_t calculateRecordByteSize() const;
   Error commit(BinaryStreamWriter &Writer);
   void finalizeBuckets(uint32_t RecordZeroOffset);
+
+  template <typename T> void addSymbol(const T &Symbol, MSFBuilder &Msf) {
+    T Copy(Symbol);
+    Records.push_back(SymbolSerializer::writeOneSymbol(Copy, Msf.getAllocator(),
+                                                       CodeViewContainer::Pdb));
+  }
+  void addSymbol(const CVSymbol &Symbol) { Records.push_back(Symbol); }
 };
 
 uint32_t GSIHashStreamBuilder::calculateSerializedLength() const {
@@ -222,9 +223,27 @@ uint32_t GSIStreamBuilder::getGlobalsStr
 }
 
 void GSIStreamBuilder::addPublicSymbol(const PublicSym32 &Pub) {
-  PublicSym32 Copy(Pub);
-  PSH->Records.push_back(SymbolSerializer::writeOneSymbol(
-      Copy, Msf.getAllocator(), CodeViewContainer::Pdb));
+  PSH->addSymbol(Pub, Msf);
+}
+
+void GSIStreamBuilder::addGlobalSymbol(const ProcRefSym &Sym) {
+  GSH->addSymbol(Sym, Msf);
+}
+
+void GSIStreamBuilder::addGlobalSymbol(const DataSym &Sym) {
+  GSH->addSymbol(Sym, Msf);
+}
+
+void GSIStreamBuilder::addGlobalSymbol(const ConstantSym &Sym) {
+  GSH->addSymbol(Sym, Msf);
+}
+
+void GSIStreamBuilder::addGlobalSymbol(const UDTSym &Sym) {
+  GSH->addSymbol(Sym, Msf);
+}
+
+void GSIStreamBuilder::addGlobalSymbol(const codeview::CVSymbol &Sym) {
+  GSH->addSymbol(Sym);
 }
 
 static Error writeRecords(BinaryStreamWriter &Writer,




More information about the llvm-commits mailing list