| 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 | |
| 32 | namespace llvm { |
| 33 | namespace pdb { |
| 34 | |
| 35 | namespace yaml { |
| 36 | |
| 37 | struct 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 | |
| 45 | struct 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 | |
| 63 | struct StreamBlockList { |
| 64 | std::vector<uint32_t> Blocks; |
| 65 | }; |
| 66 | |
| 67 | struct NamedStreamMapping { |
| 68 | StringRef StreamName; |
| 69 | uint32_t StreamNumber; |
| 70 | }; |
| 71 | |
| 72 | struct 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 | |
| 81 | struct PdbModiStream { |
| 82 | uint32_t Signature; |
| 83 | std::vector<CodeViewYAML::SymbolRecord> Symbols; |
| 84 | }; |
| 85 | |
| 86 | struct 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 | |
| 94 | struct PdbDbiSectionContrib { |
| 95 | uint16_t ISect = 0; |
| 96 | int32_t Off = 0; |
| 97 | int32_t Size = 0; |
| 98 | uint32_t Characteristics = 0; |
| 99 | uint16_t Imod = 0; |
| 100 | uint32_t DataCrc = 0; |
| 101 | uint32_t RelocCrc = 0; |
| 102 | /// Only in `SectionContrib2`. |
| 103 | uint32_t ISectCoff = 0; |
| 104 | }; |
| 105 | |
| 106 | struct PdbDbiSectionContribs { |
| 107 | PdbRaw_DbiSecContribVer Version = PdbRaw_DbiSecContribVer::DbiSecContribVer60; |
| 108 | std::vector<PdbDbiSectionContrib> Items; |
| 109 | }; |
| 110 | |
| 111 | struct PdbDbiStream { |
| 112 | PdbRaw_DbiVer VerHeader = PdbDbiV70; |
| 113 | uint32_t Age = 1; |
| 114 | uint16_t BuildNumber = 0; |
| 115 | uint32_t PdbDllVersion = 0; |
| 116 | uint16_t PdbDllRbld = 0; |
| 117 | uint16_t Flags = 1; |
| 118 | PDB_Machine MachineType = PDB_Machine::x86; |
| 119 | |
| 120 | std::vector<PdbDbiModuleInfo> ModInfos; |
| 121 | COFF::header FakeHeader; |
| 122 | std::vector<CoffSectionHeader> SectionHeaders; |
| 123 | std::optional<PdbDbiSectionContribs> SectionContribs; |
| 124 | }; |
| 125 | |
| 126 | struct PdbTpiStream { |
| 127 | PdbRaw_TpiVer Version = PdbTpiV80; |
| 128 | std::vector<CodeViewYAML::LeafRecord> Records; |
| 129 | }; |
| 130 | |
| 131 | struct PdbDXContainerStream { |
| 132 | DXContainerYAML::Object DXC; |
| 133 | }; |
| 134 | |
| 135 | struct PdbPublicsStream { |
| 136 | std::vector<CodeViewYAML::SymbolRecord> PubSyms; |
| 137 | }; |
| 138 | |
| 139 | struct PdbObject { |
| 140 | explicit PdbObject(BumpPtrAllocator &Allocator) : Allocator(Allocator) {} |
| 141 | |
| 142 | std::optional<MSFHeaders> Headers; |
| 143 | std::optional<std::vector<uint32_t>> StreamSizes; |
| 144 | std::optional<std::vector<StreamBlockList>> StreamMap; |
| 145 | std::optional<PdbInfoStream> PdbStream; |
| 146 | std::optional<PdbDbiStream> DbiStream; |
| 147 | std::optional<PdbTpiStream> TpiStream; |
| 148 | std::optional<PdbTpiStream> IpiStream; |
| 149 | std::optional<PdbDXContainerStream> DXContainerStream; |
| 150 | std::optional<PdbPublicsStream> PublicsStream; |
| 151 | |
| 152 | std::optional<std::vector<StringRef>> StringTable; |
| 153 | |
| 154 | BumpPtrAllocator &Allocator; |
| 155 | }; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::CoffSectionHeader) |
| 161 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbObject) |
| 162 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::MSFHeaders) |
| 163 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(msf::SuperBlock) |
| 164 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::StreamBlockList) |
| 165 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbInfoStream) |
| 166 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbDbiSectionContrib) |
| 167 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbDbiSectionContribs) |
| 168 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbDbiStream) |
| 169 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbTpiStream) |
| 170 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbPublicsStream) |
| 171 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::NamedStreamMapping) |
| 172 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbModiStream) |
| 173 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbDbiModuleInfo) |
| 174 | LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(pdb::yaml::PdbDXContainerStream) |
| 175 | |
| 176 | #endif // LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H |
| 177 |