From 3c488ca5a4628568f7e9d3d1d35b57c8221ae746 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 22 Mar 2017 01:37:38 +0000 Subject: [PATCH] [codeview] Use separate records for LF_SUBSTR_LIST and LF_ARGLIST They are structurally the same, but now we need to distinguish them because one record lives in the IPI stream and the other lives in TPI. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298474 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/CodeView/TypeRecord.h | 19 ++++++++++++++++++- .../llvm/DebugInfo/CodeView/TypeRecords.def | 4 +--- .../CodeView/TypeDatabaseVisitor.cpp | 16 ++++++++++++++++ lib/DebugInfo/CodeView/TypeDumpVisitor.cpp | 11 +++++++++++ lib/DebugInfo/CodeView/TypeRecord.cpp | 7 +++++++ lib/DebugInfo/CodeView/TypeRecordMapping.cpp | 9 +++++++++ test/DebugInfo/PDB/pdbdump-headers.test | 6 +++--- tools/llvm-pdbdump/YamlTypeDumper.cpp | 6 +++++- 8 files changed, 70 insertions(+), 8 deletions(-) diff --git a/include/llvm/DebugInfo/CodeView/TypeRecord.h b/include/llvm/DebugInfo/CodeView/TypeRecord.h index 0b7c41d864a..64e30af908a 100644 --- a/include/llvm/DebugInfo/CodeView/TypeRecord.h +++ b/include/llvm/DebugInfo/CodeView/TypeRecord.h @@ -236,12 +236,29 @@ public: StringRef Name; }; -// LF_ARGLIST, LF_SUBSTR_LIST +// LF_ARGLIST class ArgListRecord : public TypeRecord { public: explicit ArgListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} ArgListRecord(TypeRecordKind Kind, ArrayRef Indices) + : TypeRecord(Kind), ArgIndices(Indices) {} + + /// Rewrite member type indices with IndexMap. Returns false if a type index + /// is not in the map. + bool remapTypeIndices(ArrayRef IndexMap); + + ArrayRef getIndices() const { return ArgIndices; } + + std::vector ArgIndices; +}; + +// LF_SUBSTR_LIST +class StringListRecord : public TypeRecord { +public: + explicit StringListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + + StringListRecord(TypeRecordKind Kind, ArrayRef Indices) : TypeRecord(Kind), StringIndices(Indices) {} /// Rewrite member type indices with IndexMap. Returns false if a type index diff --git a/include/llvm/DebugInfo/CodeView/TypeRecords.def b/include/llvm/DebugInfo/CodeView/TypeRecords.def index c98dbac21a7..1ca061d0ac1 100644 --- a/include/llvm/DebugInfo/CodeView/TypeRecords.def +++ b/include/llvm/DebugInfo/CodeView/TypeRecords.def @@ -79,9 +79,7 @@ MEMBER_RECORD(LF_INDEX, 0x1404, ListContinuation) TYPE_RECORD(LF_FUNC_ID, 0x1601, FuncId) TYPE_RECORD(LF_MFUNC_ID, 0x1602, MemberFuncId) TYPE_RECORD(LF_BUILDINFO, 0x1603, BuildInfo) -// FIXME: We reuse the structure of ArgListRecord for substring lists, but it -// makes for confusing dumper output. -TYPE_RECORD_ALIAS(LF_SUBSTR_LIST, 0x1604, StringList, ArgList) +TYPE_RECORD(LF_SUBSTR_LIST, 0x1604, StringList) TYPE_RECORD(LF_STRING_ID, 0x1605, StringId) TYPE_RECORD(LF_UDT_SRC_LINE, 0x1606, UdtSourceLine) TYPE_RECORD(LF_UDT_MOD_SRC_LINE, 0x1607, UdtModSourceLine) diff --git a/lib/DebugInfo/CodeView/TypeDatabaseVisitor.cpp b/lib/DebugInfo/CodeView/TypeDatabaseVisitor.cpp index d9d56390218..4c56ab03644 100644 --- a/lib/DebugInfo/CodeView/TypeDatabaseVisitor.cpp +++ b/lib/DebugInfo/CodeView/TypeDatabaseVisitor.cpp @@ -83,6 +83,22 @@ Error TypeDatabaseVisitor::visitKnownRecord(CVType &CVR, ArgListRecord &Args) { return Error::success(); } +Error TypeDatabaseVisitor::visitKnownRecord(CVType &CVR, + StringListRecord &Strings) { + auto Indices = Strings.getIndices(); + uint32_t Size = Indices.size(); + SmallString<256> TypeName("\""); + for (uint32_t I = 0; I < Size; ++I) { + StringRef ArgTypeName = TypeDB.getTypeName(Indices[I]); + TypeName.append(ArgTypeName); + if (I + 1 != Size) + TypeName.append("\" \""); + } + TypeName.push_back('\"'); + Name = TypeDB.saveTypeName(TypeName); + return Error::success(); +} + Error TypeDatabaseVisitor::visitKnownRecord(CVType &CVR, ClassRecord &Class) { Name = Class.getName(); return Error::success(); diff --git a/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp b/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp index 636985b7899..d4d03482419 100644 --- a/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp +++ b/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp @@ -228,6 +228,17 @@ Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ArgListRecord &Args) { return Error::success(); } +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, StringListRecord &Strs) { + auto Indices = Strs.getIndices(); + uint32_t Size = Indices.size(); + W->printNumber("NumStrings", Size); + ListScope Arguments(*W, "Strings"); + for (uint32_t I = 0; I < Size; ++I) { + printTypeIndex("String", Indices[I]); + } + return Error::success(); +} + Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ClassRecord &Class) { uint16_t Props = static_cast(Class.getOptions()); W->printNumber("MemberCount", Class.getMemberCount()); diff --git a/lib/DebugInfo/CodeView/TypeRecord.cpp b/lib/DebugInfo/CodeView/TypeRecord.cpp index 386694a611a..6482f291898 100644 --- a/lib/DebugInfo/CodeView/TypeRecord.cpp +++ b/lib/DebugInfo/CodeView/TypeRecord.cpp @@ -64,6 +64,13 @@ bool MemberFuncIdRecord::remapTypeIndices(ArrayRef IndexMap) { } bool ArgListRecord::remapTypeIndices(ArrayRef IndexMap) { + bool Success = true; + for (TypeIndex &Arg : ArgIndices) + Success &= remapIndex(IndexMap, Arg); + return Success; +} + +bool StringListRecord::remapTypeIndices(ArrayRef IndexMap) { bool Success = true; for (TypeIndex &Str : StringIndices) Success &= remapIndex(IndexMap, Str); diff --git a/lib/DebugInfo/CodeView/TypeRecordMapping.cpp b/lib/DebugInfo/CodeView/TypeRecordMapping.cpp index 2e1ee978f47..a81caed8a37 100644 --- a/lib/DebugInfo/CodeView/TypeRecordMapping.cpp +++ b/lib/DebugInfo/CodeView/TypeRecordMapping.cpp @@ -170,6 +170,15 @@ Error TypeRecordMapping::visitKnownRecord(CVType &CVR, } Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ArgListRecord &Record) { + error(IO.mapVectorN( + Record.ArgIndices, + [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); })); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + StringListRecord &Record) { error(IO.mapVectorN( Record.StringIndices, [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); })); diff --git a/test/DebugInfo/PDB/pdbdump-headers.test b/test/DebugInfo/PDB/pdbdump-headers.test index c10d866f4a8..ec661344a84 100644 --- a/test/DebugInfo/PDB/pdbdump-headers.test +++ b/test/DebugInfo/PDB/pdbdump-headers.test @@ -1111,9 +1111,9 @@ ; ALL: { ; ALL: StringList (0x1057) { ; ALL: TypeLeafKind: LF_SUBSTR_LIST (0x1604) -; ALL: NumArgs: 1 -; ALL: Arguments [ -; ALL: ArgType: __vc_attributes::threadingAttribute (0x100B) +; ALL: NumStrings: 1 +; ALL: Strings [ +; ALL: String: __vc_attributes::threadingAttribute (0x100B) ; ALL: ] ; ALL: } ; ALL: } diff --git a/tools/llvm-pdbdump/YamlTypeDumper.cpp b/tools/llvm-pdbdump/YamlTypeDumper.cpp index e2b901be868..c7ad02b746e 100644 --- a/tools/llvm-pdbdump/YamlTypeDumper.cpp +++ b/tools/llvm-pdbdump/YamlTypeDumper.cpp @@ -291,7 +291,11 @@ void MappingTraits::mapping(IO &IO, StringIdRecord &String) { } void MappingTraits::mapping(IO &IO, ArgListRecord &Args) { - IO.mapRequired("ArgIndices", Args.StringIndices); + IO.mapRequired("ArgIndices", Args.ArgIndices); +} + +void MappingTraits::mapping(IO &IO, StringListRecord &Strings) { + IO.mapRequired("StringIndices", Strings.StringIndices); } void MappingTraits::mapping(IO &IO, ClassRecord &Class) { -- 2.50.1