PdbYaml.cpp 7.8 KB

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