Home | History | Annotate | Download | only in llvm-pdbutil
      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/ADT/StringExtras.h"
     13 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
     14 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
     15 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
     16 #include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
     17 #include "llvm/DebugInfo/PDB/PDBTypes.h"
     18 #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
     19 #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
     20 
     21 using namespace llvm;
     22 using namespace llvm::pdb;
     23 using namespace llvm::pdb::yaml;
     24 using namespace llvm::yaml;
     25 
     26 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::NamedStreamMapping)
     27 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::PdbDbiModuleInfo)
     28 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::StreamBlockList)
     29 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::pdb::PdbRaw_FeatureSig)
     30 
     31 namespace llvm {
     32 namespace yaml {
     33 
     34 template <> struct ScalarEnumerationTraits<llvm::pdb::PDB_Machine> {
     35   static void enumeration(IO &io, llvm::pdb::PDB_Machine &Value) {
     36     io.enumCase(Value, "Invalid", PDB_Machine::Invalid);
     37     io.enumCase(Value, "Am33", PDB_Machine::Am33);
     38     io.enumCase(Value, "Amd64", PDB_Machine::Amd64);
     39     io.enumCase(Value, "Arm", PDB_Machine::Arm);
     40     io.enumCase(Value, "ArmNT", PDB_Machine::ArmNT);
     41     io.enumCase(Value, "Ebc", PDB_Machine::Ebc);
     42     io.enumCase(Value, "x86", PDB_Machine::x86);
     43     io.enumCase(Value, "Ia64", PDB_Machine::Ia64);
     44     io.enumCase(Value, "M32R", PDB_Machine::M32R);
     45     io.enumCase(Value, "Mips16", PDB_Machine::Mips16);
     46     io.enumCase(Value, "MipsFpu", PDB_Machine::MipsFpu);
     47     io.enumCase(Value, "MipsFpu16", PDB_Machine::MipsFpu16);
     48     io.enumCase(Value, "PowerPCFP", PDB_Machine::PowerPCFP);
     49     io.enumCase(Value, "R4000", PDB_Machine::R4000);
     50     io.enumCase(Value, "SH3", PDB_Machine::SH3);
     51     io.enumCase(Value, "SH3DSP", PDB_Machine::SH3DSP);
     52     io.enumCase(Value, "Thumb", PDB_Machine::Thumb);
     53     io.enumCase(Value, "WceMipsV2", PDB_Machine::WceMipsV2);
     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 }
    114 
    115 void MappingTraits<MSFHeaders>::mapping(IO &IO, MSFHeaders &Obj) {
    116   IO.mapOptional("SuperBlock", Obj.SuperBlock);
    117   IO.mapOptional("NumDirectoryBlocks", Obj.NumDirectoryBlocks);
    118   IO.mapOptional("DirectoryBlocks", Obj.DirectoryBlocks);
    119   IO.mapOptional("NumStreams", Obj.NumStreams);
    120   IO.mapOptional("FileSize", Obj.FileSize);
    121 }
    122 
    123 void MappingTraits<msf::SuperBlock>::mapping(IO &IO, msf::SuperBlock &SB) {
    124   if (!IO.outputting()) {
    125     ::memcpy(SB.MagicBytes, msf::Magic, sizeof(msf::Magic));
    126   }
    127 
    128   using u32 = support::ulittle32_t;
    129   IO.mapOptional("BlockSize", SB.BlockSize, u32(4096U));
    130   IO.mapOptional("FreeBlockMap", SB.FreeBlockMapBlock, u32(0U));
    131   IO.mapOptional("NumBlocks", SB.NumBlocks, u32(0U));
    132   IO.mapOptional("NumDirectoryBytes", SB.NumDirectoryBytes, u32(0U));
    133   IO.mapOptional("Unknown1", SB.Unknown1, u32(0U));
    134   IO.mapOptional("BlockMapAddr", SB.BlockMapAddr, u32(0U));
    135 }
    136 
    137 void MappingTraits<StreamBlockList>::mapping(IO &IO, StreamBlockList &SB) {
    138   IO.mapRequired("Stream", SB.Blocks);
    139 }
    140 
    141 void MappingTraits<PdbInfoStream>::mapping(IO &IO, PdbInfoStream &Obj) {
    142   IO.mapOptional("Age", Obj.Age, 1U);
    143   IO.mapOptional("Guid", Obj.Guid);
    144   IO.mapOptional("Signature", Obj.Signature, 0U);
    145   IO.mapOptional("Features", Obj.Features);
    146   IO.mapOptional("Version", Obj.Version, PdbImplVC70);
    147 }
    148 
    149 void MappingTraits<PdbDbiStream>::mapping(IO &IO, PdbDbiStream &Obj) {
    150   IO.mapOptional("VerHeader", Obj.VerHeader, PdbDbiV70);
    151   IO.mapOptional("Age", Obj.Age, 1U);
    152   IO.mapOptional("BuildNumber", Obj.BuildNumber, uint16_t(0U));
    153   IO.mapOptional("PdbDllVersion", Obj.PdbDllVersion, 0U);
    154   IO.mapOptional("PdbDllRbld", Obj.PdbDllRbld, uint16_t(0U));
    155   IO.mapOptional("Flags", Obj.Flags, uint16_t(1U));
    156   IO.mapOptional("MachineType", Obj.MachineType, PDB_Machine::x86);
    157   IO.mapOptional("Modules", Obj.ModInfos);
    158 }
    159 
    160 void MappingTraits<PdbTpiStream>::mapping(IO &IO,
    161                                           pdb::yaml::PdbTpiStream &Obj) {
    162   IO.mapOptional("Version", Obj.Version, PdbTpiV80);
    163   IO.mapRequired("Records", Obj.Records);
    164 }
    165 
    166 void MappingTraits<NamedStreamMapping>::mapping(IO &IO,
    167                                                 NamedStreamMapping &Obj) {
    168   IO.mapRequired("Name", Obj.StreamName);
    169   IO.mapRequired("StreamNum", Obj.StreamNumber);
    170 }
    171 
    172 void MappingTraits<PdbModiStream>::mapping(IO &IO, PdbModiStream &Obj) {
    173   IO.mapOptional("Signature", Obj.Signature, 4U);
    174   IO.mapRequired("Records", Obj.Symbols);
    175 }
    176 
    177 void MappingTraits<PdbDbiModuleInfo>::mapping(IO &IO, PdbDbiModuleInfo &Obj) {
    178   IO.mapRequired("Module", Obj.Mod);
    179   IO.mapOptional("ObjFile", Obj.Obj, Obj.Mod);
    180   IO.mapOptional("SourceFiles", Obj.SourceFiles);
    181   IO.mapOptional("Subsections", Obj.Subsections);
    182   IO.mapOptional("Modi", Obj.Modi);
    183 }
    184