xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-pdbutil/PdbYaml.h (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1 //===- PdbYAML.h ---------------------------------------------- *- 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 #ifndef LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H
10 #define LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H
11 
12 #include "OutputStyle.h"
13 
14 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
15 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
16 #include "llvm/DebugInfo/MSF/MSFCommon.h"
17 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
18 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
19 #include "llvm/DebugInfo/PDB/PDBTypes.h"
20 #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
21 #include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
22 #include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
23 #include "llvm/Support/Endian.h"
24 #include "llvm/Support/YAMLTraits.h"
25 
26 #include <optional>
27 #include <vector>
28 
29 namespace llvm {
30 namespace pdb {
31 
32 namespace yaml {
33 
34 struct MSFHeaders {
35   msf::SuperBlock SuperBlock;
36   uint32_t NumDirectoryBlocks = 0;
37   std::vector<uint32_t> DirectoryBlocks;
38   uint32_t NumStreams = 0;
39   uint64_t FileSize = 0;
40 };
41 
42 struct StreamBlockList {
43   std::vector<uint32_t> Blocks;
44 };
45 
46 struct NamedStreamMapping {
47   StringRef StreamName;
48   uint32_t StreamNumber;
49 };
50 
51 struct PdbInfoStream {
52   PdbRaw_ImplVer Version = PdbImplVC70;
53   uint32_t Signature = 0;
54   uint32_t Age = 1;
55   codeview::GUID Guid;
56   std::vector<PdbRaw_FeatureSig> Features;
57   std::vector<NamedStreamMapping> NamedStreams;
58 };
59 
60 struct PdbModiStream {
61   uint32_t Signature;
62   std::vector<CodeViewYAML::SymbolRecord> Symbols;
63 };
64 
65 struct PdbDbiModuleInfo {
66   StringRef Obj;
67   StringRef Mod;
68   std::vector<StringRef> SourceFiles;
69   std::vector<CodeViewYAML::YAMLDebugSubsection> Subsections;
70   std::optional<PdbModiStream> Modi;
71 };
72 
73 struct PdbDbiStream {
74   PdbRaw_DbiVer VerHeader = PdbDbiV70;
75   uint32_t Age = 1;
76   uint16_t BuildNumber = 0;
77   uint32_t PdbDllVersion = 0;
78   uint16_t PdbDllRbld = 0;
79   uint16_t Flags = 1;
80   PDB_Machine MachineType = PDB_Machine::x86;
81 
82   std::vector<PdbDbiModuleInfo> ModInfos;
83 };
84 
85 struct PdbTpiStream {
86   PdbRaw_TpiVer Version = PdbTpiV80;
87   std::vector<CodeViewYAML::LeafRecord> Records;
88 };
89 
90 struct PdbPublicsStream {
91   std::vector<CodeViewYAML::SymbolRecord> PubSyms;
92 };
93 
94 struct PdbObject {
95   explicit PdbObject(BumpPtrAllocator &Allocator) : Allocator(Allocator) {}
96 
97   std::optional<MSFHeaders> Headers;
98   std::optional<std::vector<uint32_t>> StreamSizes;
99   std::optional<std::vector<StreamBlockList>> StreamMap;
100   std::optional<PdbInfoStream> PdbStream;
101   std::optional<PdbDbiStream> DbiStream;
102   std::optional<PdbTpiStream> TpiStream;
103   std::optional<PdbTpiStream> IpiStream;
104   std::optional<PdbPublicsStream> PublicsStream;
105 
106   std::optional<std::vector<StringRef>> StringTable;
107 
108   BumpPtrAllocator &Allocator;
109 };
110 }
111 }
112 }
113 
114 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::PdbObject)
115 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::MSFHeaders)
116 LLVM_YAML_DECLARE_MAPPING_TRAITS(msf::SuperBlock)
117 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::StreamBlockList)
118 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::PdbInfoStream)
119 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::PdbDbiStream)
120 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::PdbTpiStream)
121 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::PdbPublicsStream)
122 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::NamedStreamMapping)
123 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::PdbModiStream)
124 LLVM_YAML_DECLARE_MAPPING_TRAITS(pdb::yaml::PdbDbiModuleInfo)
125 
126 #endif // LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H
127