1 //===-- PdbYaml.cpp ------------------------------------------- *- C++ --*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "PdbYaml.h" 10 11 #include "llvm/ADT/StringExtras.h" 12 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" 13 #include "llvm/DebugInfo/PDB/Native/PDBFile.h" 14 #include "llvm/DebugInfo/PDB/Native/RawTypes.h" 15 #include "llvm/DebugInfo/PDB/Native/TpiHashing.h" 16 #include "llvm/DebugInfo/PDB/PDBTypes.h" 17 #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h" 18 #include "llvm/ObjectYAML/CodeViewYAMLTypes.h" 19 20 using namespace llvm; 21 using namespace llvm::pdb; 22 using namespace llvm::pdb::yaml; 23 using namespace llvm::yaml; 24 25 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::NamedStreamMapping) 26 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbDbiModuleInfo) 27 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::StreamBlockList) 28 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::pdb::PdbRaw_FeatureSig) 29 30 namespace llvm { 31 namespace yaml { 32 33 template <> struct ScalarEnumerationTraits<llvm::pdb::PDB_Machine> { 34 static void enumeration(IO &io, llvm::pdb::PDB_Machine &Value) { 35 io.enumCase(Value, "Invalid", PDB_Machine::Invalid); 36 io.enumCase(Value, "Am33", PDB_Machine::Am33); 37 io.enumCase(Value, "Amd64", PDB_Machine::Amd64); 38 io.enumCase(Value, "Arm", PDB_Machine::Arm); 39 io.enumCase(Value, "ArmNT", PDB_Machine::ArmNT); 40 io.enumCase(Value, "Ebc", PDB_Machine::Ebc); 41 io.enumCase(Value, "x86", PDB_Machine::x86); 42 io.enumCase(Value, "Ia64", PDB_Machine::Ia64); 43 io.enumCase(Value, "M32R", PDB_Machine::M32R); 44 io.enumCase(Value, "Mips16", PDB_Machine::Mips16); 45 io.enumCase(Value, "MipsFpu", PDB_Machine::MipsFpu); 46 io.enumCase(Value, "MipsFpu16", PDB_Machine::MipsFpu16); 47 io.enumCase(Value, "PowerPCFP", PDB_Machine::PowerPCFP); 48 io.enumCase(Value, "R4000", PDB_Machine::R4000); 49 io.enumCase(Value, "SH3", PDB_Machine::SH3); 50 io.enumCase(Value, "SH3DSP", PDB_Machine::SH3DSP); 51 io.enumCase(Value, "Thumb", PDB_Machine::Thumb); 52 io.enumCase(Value, "WceMipsV2", PDB_Machine::WceMipsV2); 53 io.enumCase(Value, "Arm64", PDB_Machine::Arm64); 54 } 55 }; 56 57 template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_DbiVer> { 58 static void enumeration(IO &io, llvm::pdb::PdbRaw_DbiVer &Value) { 59 io.enumCase(Value, "V41", llvm::pdb::PdbRaw_DbiVer::PdbDbiVC41); 60 io.enumCase(Value, "V50", llvm::pdb::PdbRaw_DbiVer::PdbDbiV50); 61 io.enumCase(Value, "V60", llvm::pdb::PdbRaw_DbiVer::PdbDbiV60); 62 io.enumCase(Value, "V70", llvm::pdb::PdbRaw_DbiVer::PdbDbiV70); 63 io.enumCase(Value, "V110", llvm::pdb::PdbRaw_DbiVer::PdbDbiV110); 64 } 65 }; 66 67 template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_ImplVer> { 68 static void enumeration(IO &io, llvm::pdb::PdbRaw_ImplVer &Value) { 69 io.enumCase(Value, "VC2", llvm::pdb::PdbRaw_ImplVer::PdbImplVC2); 70 io.enumCase(Value, "VC4", llvm::pdb::PdbRaw_ImplVer::PdbImplVC4); 71 io.enumCase(Value, "VC41", llvm::pdb::PdbRaw_ImplVer::PdbImplVC41); 72 io.enumCase(Value, "VC50", llvm::pdb::PdbRaw_ImplVer::PdbImplVC50); 73 io.enumCase(Value, "VC98", llvm::pdb::PdbRaw_ImplVer::PdbImplVC98); 74 io.enumCase(Value, "VC70Dep", llvm::pdb::PdbRaw_ImplVer::PdbImplVC70Dep); 75 io.enumCase(Value, "VC70", llvm::pdb::PdbRaw_ImplVer::PdbImplVC70); 76 io.enumCase(Value, "VC80", llvm::pdb::PdbRaw_ImplVer::PdbImplVC80); 77 io.enumCase(Value, "VC110", llvm::pdb::PdbRaw_ImplVer::PdbImplVC110); 78 io.enumCase(Value, "VC140", llvm::pdb::PdbRaw_ImplVer::PdbImplVC140); 79 } 80 }; 81 82 template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_TpiVer> { 83 static void enumeration(IO &io, llvm::pdb::PdbRaw_TpiVer &Value) { 84 io.enumCase(Value, "VC40", llvm::pdb::PdbRaw_TpiVer::PdbTpiV40); 85 io.enumCase(Value, "VC41", llvm::pdb::PdbRaw_TpiVer::PdbTpiV41); 86 io.enumCase(Value, "VC50", llvm::pdb::PdbRaw_TpiVer::PdbTpiV50); 87 io.enumCase(Value, "VC70", llvm::pdb::PdbRaw_TpiVer::PdbTpiV70); 88 io.enumCase(Value, "VC80", llvm::pdb::PdbRaw_TpiVer::PdbTpiV80); 89 } 90 }; 91 92 template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_FeatureSig> { 93 static void enumeration(IO &io, PdbRaw_FeatureSig &Features) { 94 io.enumCase(Features, "MinimalDebugInfo", 95 PdbRaw_FeatureSig::MinimalDebugInfo); 96 io.enumCase(Features, "NoTypeMerge", PdbRaw_FeatureSig::NoTypeMerge); 97 io.enumCase(Features, "VC110", PdbRaw_FeatureSig::VC110); 98 io.enumCase(Features, "VC140", PdbRaw_FeatureSig::VC140); 99 } 100 }; 101 } 102 } 103 104 void MappingTraits<PdbObject>::mapping(IO &IO, PdbObject &Obj) { 105 IO.mapOptional("MSF", Obj.Headers); 106 IO.mapOptional("StreamSizes", Obj.StreamSizes); 107 IO.mapOptional("StreamMap", Obj.StreamMap); 108 IO.mapOptional("StringTable", Obj.StringTable); 109 IO.mapOptional("PdbStream", Obj.PdbStream); 110 IO.mapOptional("DbiStream", Obj.DbiStream); 111 IO.mapOptional("TpiStream", Obj.TpiStream); 112 IO.mapOptional("IpiStream", Obj.IpiStream); 113 IO.mapOptional("PublicsStream", Obj.PublicsStream); 114 } 115 116 void MappingTraits<MSFHeaders>::mapping(IO &IO, MSFHeaders &Obj) { 117 IO.mapOptional("SuperBlock", Obj.SuperBlock); 118 IO.mapOptional("NumDirectoryBlocks", Obj.NumDirectoryBlocks); 119 IO.mapOptional("DirectoryBlocks", Obj.DirectoryBlocks); 120 IO.mapOptional("NumStreams", Obj.NumStreams); 121 IO.mapOptional("FileSize", Obj.FileSize); 122 } 123 124 void MappingTraits<msf::SuperBlock>::mapping(IO &IO, msf::SuperBlock &SB) { 125 if (!IO.outputting()) { 126 ::memcpy(SB.MagicBytes, msf::Magic, sizeof(msf::Magic)); 127 } 128 129 using u32 = support::ulittle32_t; 130 IO.mapOptional("BlockSize", SB.BlockSize, u32(4096U)); 131 IO.mapOptional("FreeBlockMap", SB.FreeBlockMapBlock, u32(0U)); 132 IO.mapOptional("NumBlocks", SB.NumBlocks, u32(0U)); 133 IO.mapOptional("NumDirectoryBytes", SB.NumDirectoryBytes, u32(0U)); 134 IO.mapOptional("Unknown1", SB.Unknown1, u32(0U)); 135 IO.mapOptional("BlockMapAddr", SB.BlockMapAddr, u32(0U)); 136 } 137 138 void MappingTraits<StreamBlockList>::mapping(IO &IO, StreamBlockList &SB) { 139 IO.mapRequired("Stream", SB.Blocks); 140 } 141 142 void MappingTraits<PdbInfoStream>::mapping(IO &IO, PdbInfoStream &Obj) { 143 IO.mapOptional("Age", Obj.Age, 1U); 144 IO.mapOptional("Guid", Obj.Guid); 145 IO.mapOptional("Signature", Obj.Signature, 0U); 146 IO.mapOptional("Features", Obj.Features); 147 IO.mapOptional("Version", Obj.Version, PdbImplVC70); 148 } 149 150 void MappingTraits<PdbDbiStream>::mapping(IO &IO, PdbDbiStream &Obj) { 151 IO.mapOptional("VerHeader", Obj.VerHeader, PdbDbiV70); 152 IO.mapOptional("Age", Obj.Age, 1U); 153 IO.mapOptional("BuildNumber", Obj.BuildNumber, uint16_t(0U)); 154 IO.mapOptional("PdbDllVersion", Obj.PdbDllVersion, 0U); 155 IO.mapOptional("PdbDllRbld", Obj.PdbDllRbld, uint16_t(0U)); 156 IO.mapOptional("Flags", Obj.Flags, uint16_t(1U)); 157 IO.mapOptional("MachineType", Obj.MachineType, PDB_Machine::x86); 158 IO.mapOptional("Modules", Obj.ModInfos); 159 } 160 161 void MappingTraits<PdbTpiStream>::mapping(IO &IO, 162 pdb::yaml::PdbTpiStream &Obj) { 163 IO.mapOptional("Version", Obj.Version, PdbTpiV80); 164 IO.mapRequired("Records", Obj.Records); 165 } 166 167 void MappingTraits<PdbPublicsStream>::mapping( 168 IO &IO, pdb::yaml::PdbPublicsStream &Obj) { 169 IO.mapRequired("Records", Obj.PubSyms); 170 } 171 172 void MappingTraits<NamedStreamMapping>::mapping(IO &IO, 173 NamedStreamMapping &Obj) { 174 IO.mapRequired("Name", Obj.StreamName); 175 IO.mapRequired("StreamNum", Obj.StreamNumber); 176 } 177 178 void MappingTraits<PdbModiStream>::mapping(IO &IO, PdbModiStream &Obj) { 179 IO.mapOptional("Signature", Obj.Signature, 4U); 180 IO.mapRequired("Records", Obj.Symbols); 181 } 182 183 void MappingTraits<PdbDbiModuleInfo>::mapping(IO &IO, PdbDbiModuleInfo &Obj) { 184 IO.mapRequired("Module", Obj.Mod); 185 IO.mapOptional("ObjFile", Obj.Obj, Obj.Mod); 186 IO.mapOptional("SourceFiles", Obj.SourceFiles); 187 IO.mapOptional("Subsections", Obj.Subsections); 188 IO.mapOptional("Modi", Obj.Modi); 189 } 190