From e075b10f6bfc46a15d402c3939951f8f6a021b95 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 19 Jun 2017 16:54:51 +0000 Subject: [PATCH] [CodeView] Fix dumping of public symbol record flags I noticed nonsensical type information while dumping PDBs produced by MSVC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305708 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/CodeView/CodeView.h | 10 ++++++++++ include/llvm/DebugInfo/CodeView/EnumTables.h | 1 + include/llvm/DebugInfo/CodeView/SymbolRecord.h | 2 +- lib/DebugInfo/CodeView/EnumTables.cpp | 10 ++++++++++ lib/DebugInfo/CodeView/SymbolDumper.cpp | 2 +- lib/DebugInfo/CodeView/SymbolRecordMapping.cpp | 2 +- lib/ObjectYAML/CodeViewYAMLSymbols.cpp | 11 ++++++++++- test/DebugInfo/PDB/pdbdump-headers.test | 4 ++-- tools/llvm-pdbutil/MinimalSymbolDumper.cpp | 16 +++++++++++++++- 9 files changed, 51 insertions(+), 7 deletions(-) diff --git a/include/llvm/DebugInfo/CodeView/CodeView.h b/include/llvm/DebugInfo/CodeView/CodeView.h index 6820e26b754..b7a7e33abad 100644 --- a/include/llvm/DebugInfo/CodeView/CodeView.h +++ b/include/llvm/DebugInfo/CodeView/CodeView.h @@ -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, diff --git a/include/llvm/DebugInfo/CodeView/EnumTables.h b/include/llvm/DebugInfo/CodeView/EnumTables.h index 013e440613f..5d54bb4cca8 100644 --- a/include/llvm/DebugInfo/CodeView/EnumTables.h +++ b/include/llvm/DebugInfo/CodeView/EnumTables.h @@ -22,6 +22,7 @@ namespace codeview { ArrayRef> getSymbolTypeNames(); ArrayRef> getTypeLeafNames(); ArrayRef> getRegisterNames(); +ArrayRef> getPublicSymFlagNames(); ArrayRef> getProcSymFlagNames(); ArrayRef> getLocalFlagNames(); ArrayRef> getFrameCookieKindNames(); diff --git a/include/llvm/DebugInfo/CodeView/SymbolRecord.h b/include/llvm/DebugInfo/CodeView/SymbolRecord.h index 5f85ed28cb3..1cf77fcdecb 100644 --- a/include/llvm/DebugInfo/CodeView/SymbolRecord.h +++ b/include/llvm/DebugInfo/CodeView/SymbolRecord.h @@ -363,7 +363,7 @@ public: : SymbolRecord(SymbolRecordKind::PublicSym32), RecordOffset(RecordOffset) {} - TypeIndex Index; + PublicSymFlags Flags; uint32_t Offset; uint16_t Segment; StringRef Name; diff --git a/lib/DebugInfo/CodeView/EnumTables.cpp b/lib/DebugInfo/CodeView/EnumTables.cpp index 01d8ccf2d31..ec00af28395 100644 --- a/lib/DebugInfo/CodeView/EnumTables.cpp +++ b/lib/DebugInfo/CodeView/EnumTables.cpp @@ -82,6 +82,13 @@ static const EnumEntry RegisterNames[] = { CV_ENUM_CLASS_ENT(RegisterId, R15), }; +static const EnumEntry 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 ProcSymFlagNames[] = { CV_ENUM_CLASS_ENT(ProcSymFlags, HasFP), CV_ENUM_CLASS_ENT(ProcSymFlags, HasIRET), @@ -338,6 +345,9 @@ ArrayRef> getRegisterNames() { return makeArrayRef(RegisterNames); } +ArrayRef> getPublicSymFlagNames() { + return makeArrayRef(PublicSymFlagNames); +} ArrayRef> getProcSymFlagNames() { return makeArrayRef(ProcSymFlagNames); } diff --git a/lib/DebugInfo/CodeView/SymbolDumper.cpp b/lib/DebugInfo/CodeView/SymbolDumper.cpp index 36abafc079e..b9fa9b6a6ad 100644 --- a/lib/DebugInfo/CodeView/SymbolDumper.cpp +++ b/lib/DebugInfo/CodeView/SymbolDumper.cpp @@ -524,7 +524,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, 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); diff --git a/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp b/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp index d731dc1b0a3..923837a45d9 100644 --- a/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp +++ b/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp @@ -361,7 +361,7 @@ Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, 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)); diff --git a/lib/ObjectYAML/CodeViewYAMLSymbols.cpp b/lib/ObjectYAML/CodeViewYAMLSymbols.cpp index ba3a2abe209..2f78676c6c8 100644 --- a/lib/ObjectYAML/CodeViewYAMLSymbols.cpp +++ b/lib/ObjectYAML/CodeViewYAMLSymbols.cpp @@ -40,6 +40,7 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(FrameCookieKind) 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::bitset(IO &io, ExportFlags &Flags) { } } +void ScalarBitSetTraits::bitset(IO &io, PublicSymFlags &Flags) { + auto FlagNames = getProcSymFlagNames(); + for (const auto &E : FlagNames) { + io.bitSetCase(Flags, E.Name.str().c_str(), + static_cast(E.Value)); + } +} + void ScalarBitSetTraits::bitset(IO &io, LocalSymFlags &Flags) { auto FlagNames = getLocalFlagNames(); for (const auto &E : FlagNames) { @@ -298,7 +307,7 @@ template <> void SymbolRecordImpl::map(IO &IO) { } template <> void SymbolRecordImpl::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); diff --git a/test/DebugInfo/PDB/pdbdump-headers.test b/test/DebugInfo/PDB/pdbdump-headers.test index fa9a25108fa..afedbb5c257 100644 --- a/test/DebugInfo/PDB/pdbdump-headers.test +++ b/test/DebugInfo/PDB/pdbdump-headers.test @@ -458,9 +458,9 @@ ALL: Hash Adjusters: ALL: Public Symbols ALL-NEXT: ============================================================ ALL-NEXT: - S_PUB32 [size = 36] `?__purecall@@3PAXA` -ALL-NEXT: type = , addr = 0003:0000 +ALL-NEXT: flags = none, addr = 0003:0000 ALL-NEXT: - S_PUB32 [size = 20] `_main` -ALL-NEXT: type = 0x0002 (), 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` diff --git a/tools/llvm-pdbutil/MinimalSymbolDumper.cpp b/tools/llvm-pdbutil/MinimalSymbolDumper.cpp index 8b36de0b715..7f5412d5988 100644 --- a/tools/llvm-pdbutil/MinimalSymbolDumper.cpp +++ b/tools/llvm-pdbutil/MinimalSymbolDumper.cpp @@ -146,6 +146,19 @@ static std::string formatFrameProcedureOptions(uint32_t IndentLevel, return typesetItemList(Opts, 4, IndentLevel, " | "); } +static std::string formatPublicSymFlags(uint32_t IndentLevel, + PublicSymFlags Flags) { + std::vector 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 Opts; @@ -659,7 +672,8 @@ Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, 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(); } -- 2.50.1