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/BinaryFormat/COFF.h"
15#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
16#include "llvm/DebugInfo/CodeView/TypeRecord.h"
17#include "llvm/DebugInfo/MSF/MSFCommon.h"
18#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
19#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
20#include "llvm/DebugInfo/PDB/PDBTypes.h"
21#include "llvm/Object/COFF.h"
22#include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h"
23#include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
24#include "llvm/ObjectYAML/CodeViewYAMLTypes.h"
25#include "llvm/ObjectYAML/DXContainerYAML.h"
26#include "llvm/Support/Endian.h"
27#include "llvm/Support/YAMLTraits.h"
28
29#include <optional>
30#include <vector>
31
32namespace llvm {
33namespace pdb {
34
35namespace yaml {
36
37struct MSFHeaders {
38 msf::SuperBlock SuperBlock;
39 uint32_t NumDirectoryBlocks = 0;
40 std::vector<uint32_t> DirectoryBlocks;
41 uint32_t NumStreams = 0;
42 uint64_t FileSize = 0;
43};
44
45struct CoffSectionHeader {
46 CoffSectionHeader();
47 CoffSectionHeader(const object::coff_section &Section);
48
49 object::coff_section toCoffSection() const;
50
51 StringRef Name;
52 uint32_t VirtualSize = 0;
53 uint32_t VirtualAddress = 0;
54 uint32_t SizeOfRawData = 0;
55 uint32_t PointerToRawData = 0;
56 uint32_t PointerToRelocations = 0;
57 uint32_t PointerToLinenumbers = 0;
58 uint16_t NumberOfRelocations = 0;
59 uint16_t NumberOfLinenumbers = 0;
60 uint32_t Characteristics = 0;
61};
62
63struct StreamBlockList {
64 std::vector<uint32_t> Blocks;
65};
66
67struct NamedStreamMapping {
68 StringRef StreamName;
69 uint32_t StreamNumber;
70};
71
72struct PdbInfoStream {
73 PdbRaw_ImplVer Version = PdbImplVC70;
74 uint32_t Signature = 0;
75 uint32_t Age = 1;
76 codeview::GUID Guid;
77 std::vector<PdbRaw_FeatureSig> Features;
78 std::vector<NamedStreamMapping> NamedStreams;
79};
80
81struct PdbModiStream {
82 uint32_t Signature;
83 std::vector<CodeViewYAML::SymbolRecord> Symbols;
84};
85
86struct PdbDbiModuleInfo {
87 StringRef Obj;
88 StringRef Mod;
89 std::vector<StringRef> SourceFiles;
90 std::vector<CodeViewYAML::YAMLDebugSubsection> Subsections;
91 std::optional<PdbModiStream> Modi;
92};
93
94struct PdbDbiStream {
95 PdbRaw_DbiVer VerHeader = PdbDbiV70;
96 uint32_t Age = 1;
97 uint16_t BuildNumber = 0;
98 uint32_t PdbDllVersion = 0;
99 uint16_t PdbDllRbld = 0;
100 uint16_t Flags = 1;
101 PDB_Machine MachineType = PDB_Machine::x86;
102
103 std::vector<PdbDbiModuleInfo> ModInfos;
104 COFF::header FakeHeader;
105 std::vector<CoffSectionHeader> SectionHeaders;
106};
107
108struct PdbTpiStream {
109 PdbRaw_TpiVer Version = PdbTpiV80;
110 std::vector<CodeViewYAML::LeafRecord> Records;
111};
112
113struct PdbDXContainerStream {
114 DXContainerYAML::Object DXC;
115};
116
117struct PdbPublicsStream {
118 std::vector<CodeViewYAML::SymbolRecord> PubSyms;
119};
120
121struct PdbObject {
122 explicit PdbObject(BumpPtrAllocator &Allocator) : Allocator(Allocator) {}
123
124 std::optional<MSFHeaders> Headers;
125 std::optional<std::vector<uint32_t>> StreamSizes;
126 std::optional<std::vector<StreamBlockList>> StreamMap;
127 std::optional<PdbInfoStream> PdbStream;
128 std::optional<PdbDbiStream> DbiStream;
129 std::optional<PdbTpiStream> TpiStream;
130 std::optional<PdbTpiStream> IpiStream;
131 std::optional<PdbDXContainerStream> DXContainerStream;
132 std::optional<PdbPublicsStream> PublicsStream;
133
134 std::optional<std::vector<StringRef>> StringTable;
135
136 BumpPtrAllocator &Allocator;
137};
138}
139}
140}
141
142LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::CoffSectionHeader)
143LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbObject)
144LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::MSFHeaders)
145LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(msf::SuperBlock)
146LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::StreamBlockList)
147LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbInfoStream)
148LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbDbiStream)
149LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbTpiStream)
150LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbPublicsStream)
151LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::NamedStreamMapping)
152LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbModiStream)
153LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbDbiModuleInfo)
154LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbDXContainerStream)
155
156#endif // LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H
157