[yaml2obj/obj2yaml] - Add support for .stack_sizes sections.
[llvm-complete.git] / tools / llvm-pdbutil / PdbYaml.cpp
bloba26241967b5add128f1958495902636778af272b
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 //===----------------------------------------------------------------------===//
9 #include "PdbYaml.h"
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"
20 using namespace llvm;
21 using namespace llvm::pdb;
22 using namespace llvm::pdb::yaml;
23 using namespace llvm::yaml;
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)
30 namespace llvm {
31 namespace yaml {
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);
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);
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);
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);
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);
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);
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);
124 void MappingTraits<msf::SuperBlock>::mapping(IO &IO, msf::SuperBlock &SB) {
125 if (!IO.outputting()) {
126 ::memcpy(SB.MagicBytes, msf::Magic, sizeof(msf::Magic));
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));
138 void MappingTraits<StreamBlockList>::mapping(IO &IO, StreamBlockList &SB) {
139 IO.mapRequired("Stream", SB.Blocks);
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);
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);
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);
167 void MappingTraits<PdbPublicsStream>::mapping(
168 IO &IO, pdb::yaml::PdbPublicsStream &Obj) {
169 IO.mapRequired("Records", Obj.PubSyms);
172 void MappingTraits<NamedStreamMapping>::mapping(IO &IO,
173 NamedStreamMapping &Obj) {
174 IO.mapRequired("Name", Obj.StreamName);
175 IO.mapRequired("StreamNum", Obj.StreamNumber);
178 void MappingTraits<PdbModiStream>::mapping(IO &IO, PdbModiStream &Obj) {
179 IO.mapOptional("Signature", Obj.Signature, 4U);
180 IO.mapRequired("Records", Obj.Symbols);
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);