1 //===- PdbYAML.cpp -------------------------------------------- *- C++ --*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "PdbYaml.h" 11 12 #include "llvm/DebugInfo/PDB/PDBExtras.h" 13 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" 14 15 using namespace llvm; 16 using namespace llvm::yaml; 17 using namespace llvm::pdb; 18 using namespace llvm::pdb::yaml; 19 20 namespace llvm { 21 namespace yaml { 22 template <> struct ScalarTraits<llvm::pdb::PDB_UniqueId> { 23 static void output(const llvm::pdb::PDB_UniqueId &S, void *, 24 llvm::raw_ostream &OS) { 25 OS << S; 26 } 27 28 static StringRef input(StringRef Scalar, void *Ctx, 29 llvm::pdb::PDB_UniqueId &S) { 30 if (Scalar.size() != 38) 31 return "GUID strings are 38 characters long"; 32 if (Scalar[0] != '{' || Scalar[37] != '}') 33 return "GUID is not enclosed in {}"; 34 if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' || 35 Scalar[24] != '-') 36 return "GUID sections are not properly delineated with dashes"; 37 38 char *OutBuffer = S.Guid; 39 for (auto Iter = Scalar.begin(); Iter != Scalar.end();) { 40 if (*Iter == '-' || *Iter == '{' || *Iter == '}') { 41 ++Iter; 42 continue; 43 } 44 uint8_t Value = (llvm::hexDigitValue(*Iter) << 4); 45 ++Iter; 46 Value |= llvm::hexDigitValue(*Iter); 47 ++Iter; 48 *OutBuffer++ = Value; 49 } 50 51 return ""; 52 } 53 54 static bool mustQuote(StringRef Scalar) { return needsQuotes(Scalar); } 55 }; 56 57 template <> struct ScalarEnumerationTraits<llvm::pdb::PDB_Machine> { 58 static void enumeration(IO &io, llvm::pdb::PDB_Machine &Value) { 59 io.enumCase(Value, "Invalid", PDB_Machine::Invalid); 60 io.enumCase(Value, "Am33", PDB_Machine::Am33); 61 io.enumCase(Value, "Amd64", PDB_Machine::Amd64); 62 io.enumCase(Value, "Arm", PDB_Machine::Arm); 63 io.enumCase(Value, "ArmNT", PDB_Machine::ArmNT); 64 io.enumCase(Value, "Ebc", PDB_Machine::Ebc); 65 io.enumCase(Value, "x86", PDB_Machine::x86); 66 io.enumCase(Value, "Ia64", PDB_Machine::Ia64); 67 io.enumCase(Value, "M32R", PDB_Machine::M32R); 68 io.enumCase(Value, "Mips16", PDB_Machine::Mips16); 69 io.enumCase(Value, "MipsFpu", PDB_Machine::MipsFpu); 70 io.enumCase(Value, "MipsFpu16", PDB_Machine::MipsFpu16); 71 io.enumCase(Value, "PowerPCFP", PDB_Machine::PowerPCFP); 72 io.enumCase(Value, "R4000", PDB_Machine::R4000); 73 io.enumCase(Value, "SH3", PDB_Machine::SH3); 74 io.enumCase(Value, "SH3DSP", PDB_Machine::SH3DSP); 75 io.enumCase(Value, "Thumb", PDB_Machine::Thumb); 76 io.enumCase(Value, "WceMipsV2", PDB_Machine::WceMipsV2); 77 } 78 }; 79 80 template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_DbiVer> { 81 static void enumeration(IO &io, llvm::pdb::PdbRaw_DbiVer &Value) { 82 io.enumCase(Value, "V41", llvm::pdb::PdbRaw_DbiVer::PdbDbiVC41); 83 io.enumCase(Value, "V50", llvm::pdb::PdbRaw_DbiVer::PdbDbiV50); 84 io.enumCase(Value, "V60", llvm::pdb::PdbRaw_DbiVer::PdbDbiV60); 85 io.enumCase(Value, "V70", llvm::pdb::PdbRaw_DbiVer::PdbDbiV70); 86 io.enumCase(Value, "V110", llvm::pdb::PdbRaw_DbiVer::PdbDbiV110); 87 } 88 }; 89 90 template <> struct ScalarEnumerationTraits<llvm::pdb::PdbRaw_ImplVer> { 91 static void enumeration(IO &io, llvm::pdb::PdbRaw_ImplVer &Value) { 92 io.enumCase(Value, "VC2", llvm::pdb::PdbRaw_ImplVer::PdbImplVC2); 93 io.enumCase(Value, "VC4", llvm::pdb::PdbRaw_ImplVer::PdbImplVC4); 94 io.enumCase(Value, "VC41", llvm::pdb::PdbRaw_ImplVer::PdbImplVC41); 95 io.enumCase(Value, "VC50", llvm::pdb::PdbRaw_ImplVer::PdbImplVC50); 96 io.enumCase(Value, "VC98", llvm::pdb::PdbRaw_ImplVer::PdbImplVC98); 97 io.enumCase(Value, "VC70Dep", llvm::pdb::PdbRaw_ImplVer::PdbImplVC70Dep); 98 io.enumCase(Value, "VC70", llvm::pdb::PdbRaw_ImplVer::PdbImplVC70); 99 io.enumCase(Value, "VC80", llvm::pdb::PdbRaw_ImplVer::PdbImplVC80); 100 io.enumCase(Value, "VC110", llvm::pdb::PdbRaw_ImplVer::PdbImplVC110); 101 io.enumCase(Value, "VC140", llvm::pdb::PdbRaw_ImplVer::PdbImplVC140); 102 } 103 }; 104 } 105 } 106 107 void MappingTraits<PdbObject>::mapping(IO &IO, PdbObject &Obj) { 108 IO.mapOptional("MSF", Obj.Headers); 109 IO.mapOptional("StreamSizes", Obj.StreamSizes); 110 IO.mapOptional("StreamMap", Obj.StreamMap); 111 IO.mapOptional("PdbStream", Obj.PdbStream); 112 IO.mapOptional("DbiStream", Obj.DbiStream); 113 } 114 115 void MappingTraits<MsfHeaders>::mapping(IO &IO, MsfHeaders &Obj) { 116 IO.mapRequired("SuperBlock", Obj.SuperBlock); 117 IO.mapRequired("NumDirectoryBlocks", Obj.NumDirectoryBlocks); 118 IO.mapRequired("BlockMapOffset", Obj.BlockMapOffset); 119 IO.mapRequired("DirectoryBlocks", Obj.DirectoryBlocks); 120 IO.mapRequired("NumStreams", Obj.NumStreams); 121 IO.mapRequired("FileSize", Obj.FileSize); 122 } 123 124 void MappingTraits<PDBFile::SuperBlock>::mapping(IO &IO, 125 PDBFile::SuperBlock &SB) { 126 if (!IO.outputting()) { 127 ::memcpy(SB.MagicBytes, MsfMagic, sizeof(MsfMagic)); 128 } 129 130 IO.mapRequired("BlockSize", SB.BlockSize); 131 IO.mapRequired("Unknown0", SB.Unknown0); 132 IO.mapRequired("NumBlocks", SB.NumBlocks); 133 IO.mapRequired("NumDirectoryBytes", SB.NumDirectoryBytes); 134 IO.mapRequired("Unknown1", SB.Unknown1); 135 IO.mapRequired("BlockMapAddr", SB.BlockMapAddr); 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.mapRequired("Age", Obj.Age); 144 IO.mapRequired("Guid", Obj.Guid); 145 IO.mapRequired("Signature", Obj.Signature); 146 IO.mapRequired("Version", Obj.Version); 147 } 148 149 void MappingTraits<PdbDbiStream>::mapping(IO &IO, PdbDbiStream &Obj) { 150 IO.mapRequired("VerHeader", Obj.VerHeader); 151 IO.mapRequired("Age", Obj.Age); 152 IO.mapRequired("BuildNumber", Obj.BuildNumber); 153 IO.mapRequired("PdbDllVersion", Obj.PdbDllVersion); 154 IO.mapRequired("PdbDllRbld", Obj.PdbDllRbld); 155 IO.mapRequired("Flags", Obj.Flags); 156 IO.mapRequired("MachineType", Obj.MachineType); 157 } 158