[llvm] r305708 - [CodeView] Fix dumping of public symbol record flags

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 09:54:51 PDT 2017


Author: rnk
Date: Mon Jun 19 11:54:51 2017
New Revision: 305708

URL: http://llvm.org/viewvc/llvm-project?rev=305708&view=rev
Log:
[CodeView] Fix dumping of public symbol record flags

I noticed nonsensical type information while dumping PDBs produced by
MSVC.

Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/EnumTables.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h
    llvm/trunk/lib/DebugInfo/CodeView/EnumTables.cpp
    llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp
    llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp
    llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
    llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test
    llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h Mon Jun 19 11:54:51 2017
@@ -402,6 +402,16 @@ enum class LocalSymFlags : uint16_t {
 };
 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(LocalSymFlags)
 
+/// Corresponds to the CV_PUBSYMFLAGS bitfield.
+enum class PublicSymFlags : uint32_t {
+  None = 0,
+  Code = 1 << 0,
+  Function = 1 << 1,
+  Managed = 1 << 2,
+  MSIL = 1 << 3,
+};
+CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(PublicSymFlags)
+
 /// Corresponds to the CV_PROCFLAGS bitfield.
 enum class ProcSymFlags : uint8_t {
   None = 0,

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/EnumTables.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/EnumTables.h?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/EnumTables.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/EnumTables.h Mon Jun 19 11:54:51 2017
@@ -22,6 +22,7 @@ namespace codeview {
 ArrayRef<EnumEntry<SymbolKind>> getSymbolTypeNames();
 ArrayRef<EnumEntry<TypeLeafKind>> getTypeLeafNames();
 ArrayRef<EnumEntry<uint16_t>> getRegisterNames();
+ArrayRef<EnumEntry<uint32_t>> getPublicSymFlagNames();
 ArrayRef<EnumEntry<uint8_t>> getProcSymFlagNames();
 ArrayRef<EnumEntry<uint16_t>> getLocalFlagNames();
 ArrayRef<EnumEntry<uint8_t>> getFrameCookieKindNames();

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h Mon Jun 19 11:54:51 2017
@@ -363,7 +363,7 @@ public:
       : SymbolRecord(SymbolRecordKind::PublicSym32),
         RecordOffset(RecordOffset) {}
 
-  TypeIndex Index;
+  PublicSymFlags Flags;
   uint32_t Offset;
   uint16_t Segment;
   StringRef Name;

Modified: llvm/trunk/lib/DebugInfo/CodeView/EnumTables.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/EnumTables.cpp?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/EnumTables.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/EnumTables.cpp Mon Jun 19 11:54:51 2017
@@ -82,6 +82,13 @@ static const EnumEntry<uint16_t> Registe
     CV_ENUM_CLASS_ENT(RegisterId, R15),
 };
 
+static const EnumEntry<uint32_t> PublicSymFlagNames[] = {
+    CV_ENUM_CLASS_ENT(PublicSymFlags, Code),
+    CV_ENUM_CLASS_ENT(PublicSymFlags, Function),
+    CV_ENUM_CLASS_ENT(PublicSymFlags, Managed),
+    CV_ENUM_CLASS_ENT(PublicSymFlags, MSIL),
+};
+
 static const EnumEntry<uint8_t> ProcSymFlagNames[] = {
     CV_ENUM_CLASS_ENT(ProcSymFlags, HasFP),
     CV_ENUM_CLASS_ENT(ProcSymFlags, HasIRET),
@@ -338,6 +345,9 @@ ArrayRef<EnumEntry<uint16_t>> getRegiste
   return makeArrayRef(RegisterNames);
 }
 
+ArrayRef<EnumEntry<uint32_t>> getPublicSymFlagNames() {
+  return makeArrayRef(PublicSymFlagNames);
+}
 ArrayRef<EnumEntry<uint8_t>> getProcSymFlagNames() {
   return makeArrayRef(ProcSymFlagNames);
 }

Modified: llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp Mon Jun 19 11:54:51 2017
@@ -524,7 +524,7 @@ Error CVSymbolDumperImpl::visitKnownReco
 
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, PublicSym32 &Public) {
   DictScope S(W, "PublicSym");
-  printTypeIndex("Type", Public.Index);
+  W.printFlags("Flags", uint32_t(Public.Flags), getPublicSymFlagNames());
   W.printNumber("Seg", Public.Segment);
   W.printNumber("Off", Public.Offset);
   W.printString("Name", Public.Name);

Modified: llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp Mon Jun 19 11:54:51 2017
@@ -361,7 +361,7 @@ Error SymbolRecordMapping::visitKnownRec
 Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
                                             PublicSym32 &Public) {
 
-  error(IO.mapInteger(Public.Index));
+  error(IO.mapEnum(Public.Flags));
   error(IO.mapInteger(Public.Offset));
   error(IO.mapInteger(Public.Segment));
   error(IO.mapStringZ(Public.Name));

Modified: llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/CodeViewYAMLSymbols.cpp Mon Jun 19 11:54:51 2017
@@ -40,6 +40,7 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(FrameCooki
 LLVM_YAML_DECLARE_BITSET_TRAITS(CompileSym2Flags)
 LLVM_YAML_DECLARE_BITSET_TRAITS(CompileSym3Flags)
 LLVM_YAML_DECLARE_BITSET_TRAITS(ExportFlags)
+LLVM_YAML_DECLARE_BITSET_TRAITS(PublicSymFlags)
 LLVM_YAML_DECLARE_BITSET_TRAITS(LocalSymFlags)
 LLVM_YAML_DECLARE_BITSET_TRAITS(ProcSymFlags)
 LLVM_YAML_DECLARE_BITSET_TRAITS(FrameProcedureOptions)
@@ -93,6 +94,14 @@ void ScalarBitSetTraits<ExportFlags>::bi
   }
 }
 
+void ScalarBitSetTraits<PublicSymFlags>::bitset(IO &io, PublicSymFlags &Flags) {
+  auto FlagNames = getProcSymFlagNames();
+  for (const auto &E : FlagNames) {
+    io.bitSetCase(Flags, E.Name.str().c_str(),
+                  static_cast<PublicSymFlags>(E.Value));
+  }
+}
+
 void ScalarBitSetTraits<LocalSymFlags>::bitset(IO &io, LocalSymFlags &Flags) {
   auto FlagNames = getLocalFlagNames();
   for (const auto &E : FlagNames) {
@@ -298,7 +307,7 @@ template <> void SymbolRecordImpl<Regist
 }
 
 template <> void SymbolRecordImpl<PublicSym32>::map(IO &IO) {
-  IO.mapRequired("Type", Symbol.Index);
+  IO.mapRequired("Flags", Symbol.Flags);
   IO.mapRequired("Seg", Symbol.Segment);
   IO.mapRequired("Off", Symbol.Offset);
   IO.mapRequired("Name", Symbol.Name);

Modified: llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test Mon Jun 19 11:54:51 2017
@@ -458,9 +458,9 @@ ALL:        Hash Adjusters:
 ALL:                             Public Symbols
 ALL-NEXT: ============================================================
 ALL-NEXT:   - S_PUB32 [size = 36] `?__purecall@@3PAXA`
-ALL-NEXT:       type = <no type>, addr = 0003:0000
+ALL-NEXT:       flags = none, addr = 0003:0000
 ALL-NEXT:   - S_PUB32 [size = 20] `_main`
-ALL-NEXT:       type = 0x0002 (<unknown simple type>), addr = 0001:0016
+ALL-NEXT:       flags = function, addr = 0001:0016
 ALL-NEXT:   - S_PROCREF [size = 20] `main`
 ALL-NEXT:       module = 1, sum name = 0, offset = 120
 ALL-NEXT:   - S_GDATA32 [size = 28] `__purecall`

Modified: llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp?rev=305708&r1=305707&r2=305708&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/MinimalSymbolDumper.cpp Mon Jun 19 11:54:51 2017
@@ -146,6 +146,19 @@ static std::string formatFrameProcedureO
   return typesetItemList(Opts, 4, IndentLevel, " | ");
 }
 
+static std::string formatPublicSymFlags(uint32_t IndentLevel,
+                                        PublicSymFlags Flags) {
+  std::vector<std::string> Opts;
+  if (Flags == PublicSymFlags::None)
+    return "none";
+
+  PUSH_FLAG(PublicSymFlags, Code, Flags, "code");
+  PUSH_FLAG(PublicSymFlags, Function, Flags, "function");
+  PUSH_FLAG(PublicSymFlags, Managed, Flags, "managed");
+  PUSH_FLAG(PublicSymFlags, MSIL, Flags, "msil");
+  return typesetItemList(Opts, 4, IndentLevel, " | ");
+}
+
 static std::string formatProcSymFlags(uint32_t IndentLevel,
                                       ProcSymFlags Flags) {
   std::vector<std::string> Opts;
@@ -659,7 +672,8 @@ Error MinimalSymbolDumper::visitKnownRec
                                             PublicSym32 &Public) {
   P.format(" `{0}`", Public.Name);
   AutoIndent Indent(P);
-  P.formatLine("type = {0}, addr = {1}", typeIndex(Public.Index),
+  P.formatLine("flags = {0}, addr = {1}",
+               formatPublicSymFlags(P.getIndentLevel() + 9, Public.Flags),
                formatSegmentOffset(Public.Segment, Public.Offset));
   return Error::success();
 }




More information about the llvm-commits mailing list