Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 1 | //===- CodeViewYAMLDebugSections.cpp - CodeView YAMLIO debug sections -----===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 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 |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines classes for handling the YAML representation of CodeView |
| 10 | // Debug Info. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/ObjectYAML/CodeViewYAMLDebugSections.h" |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/STLExtras.h" |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringRef.h" |
| 18 | #include "llvm/BinaryFormat/COFF.h" |
| 19 | #include "llvm/DebugInfo/CodeView/CodeView.h" |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/CodeView/CodeViewError.h" |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h" |
| 23 | #include "llvm/DebugInfo/CodeView/DebugCrossImpSubsection.h" |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h" |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 25 | #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" |
| 26 | #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h" |
| 27 | #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 28 | #include "llvm/DebugInfo/CodeView/DebugSubsection.h" |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 29 | #include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h" |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 30 | #include "llvm/DebugInfo/CodeView/DebugSymbolRVASubsection.h" |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 31 | #include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h" |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 32 | #include "llvm/DebugInfo/CodeView/Line.h" |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 33 | #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 34 | #include "llvm/DebugInfo/CodeView/TypeIndex.h" |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 35 | #include "llvm/ObjectYAML/CodeViewYAMLSymbols.h" |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Allocator.h" |
| 37 | #include "llvm/Support/BinaryStreamReader.h" |
| 38 | #include "llvm/Support/Endian.h" |
| 39 | #include "llvm/Support/Error.h" |
| 40 | #include "llvm/Support/ErrorHandling.h" |
| 41 | #include "llvm/Support/YAMLTraits.h" |
| 42 | #include "llvm/Support/raw_ostream.h" |
| 43 | #include <algorithm> |
| 44 | #include <cassert> |
| 45 | #include <cstdint> |
| 46 | #include <memory> |
| 47 | #include <string> |
| 48 | #include <tuple> |
| 49 | #include <vector> |
| 50 | |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 51 | using namespace llvm; |
| 52 | using namespace llvm::codeview; |
| 53 | using namespace llvm::CodeViewYAML; |
| 54 | using namespace llvm::CodeViewYAML::detail; |
| 55 | using namespace llvm::yaml; |
| 56 | |
| 57 | LLVM_YAML_IS_SEQUENCE_VECTOR(SourceFileChecksumEntry) |
| 58 | LLVM_YAML_IS_SEQUENCE_VECTOR(SourceLineEntry) |
| 59 | LLVM_YAML_IS_SEQUENCE_VECTOR(SourceColumnEntry) |
| 60 | LLVM_YAML_IS_SEQUENCE_VECTOR(SourceLineBlock) |
| 61 | LLVM_YAML_IS_SEQUENCE_VECTOR(SourceLineInfo) |
| 62 | LLVM_YAML_IS_SEQUENCE_VECTOR(InlineeSite) |
| 63 | LLVM_YAML_IS_SEQUENCE_VECTOR(InlineeInfo) |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 64 | LLVM_YAML_IS_SEQUENCE_VECTOR(CrossModuleExport) |
| 65 | LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLCrossModuleImport) |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 66 | LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLFrameData) |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 67 | |
Francis Visoiu Mistrih | b213b27 | 2017-12-18 17:38:03 +0000 | [diff] [blame] | 68 | LLVM_YAML_DECLARE_SCALAR_TRAITS(HexFormattedString, QuotingType::None) |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 69 | LLVM_YAML_DECLARE_ENUM_TRAITS(DebugSubsectionKind) |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 70 | LLVM_YAML_DECLARE_ENUM_TRAITS(FileChecksumKind) |
| 71 | LLVM_YAML_DECLARE_BITSET_TRAITS(LineFlags) |
| 72 | |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 73 | LLVM_YAML_DECLARE_MAPPING_TRAITS(CrossModuleExport) |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 74 | LLVM_YAML_DECLARE_MAPPING_TRAITS(YAMLFrameData) |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 75 | LLVM_YAML_DECLARE_MAPPING_TRAITS(YAMLCrossModuleImport) |
| 76 | LLVM_YAML_DECLARE_MAPPING_TRAITS(CrossModuleImportItem) |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 77 | LLVM_YAML_DECLARE_MAPPING_TRAITS(SourceLineEntry) |
| 78 | LLVM_YAML_DECLARE_MAPPING_TRAITS(SourceColumnEntry) |
| 79 | LLVM_YAML_DECLARE_MAPPING_TRAITS(SourceFileChecksumEntry) |
| 80 | LLVM_YAML_DECLARE_MAPPING_TRAITS(SourceLineBlock) |
| 81 | LLVM_YAML_DECLARE_MAPPING_TRAITS(InlineeSite) |
| 82 | |
| 83 | namespace llvm { |
| 84 | namespace CodeViewYAML { |
| 85 | namespace detail { |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 86 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 87 | struct YAMLSubsectionBase { |
| 88 | explicit YAMLSubsectionBase(DebugSubsectionKind Kind) : Kind(Kind) {} |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 89 | virtual ~YAMLSubsectionBase() = default; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 90 | |
| 91 | virtual void map(IO &IO) = 0; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 92 | virtual std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 93 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 94 | const codeview::StringsAndChecksums &SC) const = 0; |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 95 | |
| 96 | DebugSubsectionKind Kind; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 97 | }; |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 98 | |
| 99 | } // end namespace detail |
| 100 | } // end namespace CodeViewYAML |
| 101 | } // end namespace llvm |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 102 | |
| 103 | namespace { |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 104 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 105 | struct YAMLChecksumsSubsection : public YAMLSubsectionBase { |
| 106 | YAMLChecksumsSubsection() |
| 107 | : YAMLSubsectionBase(DebugSubsectionKind::FileChecksums) {} |
| 108 | |
| 109 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 110 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 111 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 112 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 113 | static Expected<std::shared_ptr<YAMLChecksumsSubsection>> |
| 114 | fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings, |
| 115 | const DebugChecksumsSubsectionRef &FC); |
| 116 | |
| 117 | std::vector<SourceFileChecksumEntry> Checksums; |
| 118 | }; |
| 119 | |
| 120 | struct YAMLLinesSubsection : public YAMLSubsectionBase { |
| 121 | YAMLLinesSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Lines) {} |
| 122 | |
| 123 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 124 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 125 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 126 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 127 | static Expected<std::shared_ptr<YAMLLinesSubsection>> |
| 128 | fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings, |
| 129 | const DebugChecksumsSubsectionRef &Checksums, |
| 130 | const DebugLinesSubsectionRef &Lines); |
| 131 | |
| 132 | SourceLineInfo Lines; |
| 133 | }; |
| 134 | |
| 135 | struct YAMLInlineeLinesSubsection : public YAMLSubsectionBase { |
| 136 | YAMLInlineeLinesSubsection() |
| 137 | : YAMLSubsectionBase(DebugSubsectionKind::InlineeLines) {} |
| 138 | |
| 139 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 140 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 141 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 142 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 143 | static Expected<std::shared_ptr<YAMLInlineeLinesSubsection>> |
| 144 | fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings, |
| 145 | const DebugChecksumsSubsectionRef &Checksums, |
| 146 | const DebugInlineeLinesSubsectionRef &Lines); |
| 147 | |
| 148 | InlineeInfo InlineeLines; |
| 149 | }; |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 150 | |
| 151 | struct YAMLCrossModuleExportsSubsection : public YAMLSubsectionBase { |
| 152 | YAMLCrossModuleExportsSubsection() |
| 153 | : YAMLSubsectionBase(DebugSubsectionKind::CrossScopeExports) {} |
| 154 | |
| 155 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 156 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 157 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 158 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 159 | static Expected<std::shared_ptr<YAMLCrossModuleExportsSubsection>> |
| 160 | fromCodeViewSubsection(const DebugCrossModuleExportsSubsectionRef &Exports); |
| 161 | |
| 162 | std::vector<CrossModuleExport> Exports; |
| 163 | }; |
| 164 | |
| 165 | struct YAMLCrossModuleImportsSubsection : public YAMLSubsectionBase { |
| 166 | YAMLCrossModuleImportsSubsection() |
| 167 | : YAMLSubsectionBase(DebugSubsectionKind::CrossScopeImports) {} |
| 168 | |
| 169 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 170 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 171 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 172 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 173 | static Expected<std::shared_ptr<YAMLCrossModuleImportsSubsection>> |
| 174 | fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings, |
| 175 | const DebugCrossModuleImportsSubsectionRef &Imports); |
| 176 | |
| 177 | std::vector<YAMLCrossModuleImport> Imports; |
| 178 | }; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 179 | |
| 180 | struct YAMLSymbolsSubsection : public YAMLSubsectionBase { |
| 181 | YAMLSymbolsSubsection() : YAMLSubsectionBase(DebugSubsectionKind::Symbols) {} |
| 182 | |
| 183 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 184 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 185 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 186 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 187 | static Expected<std::shared_ptr<YAMLSymbolsSubsection>> |
| 188 | fromCodeViewSubsection(const DebugSymbolsSubsectionRef &Symbols); |
| 189 | |
| 190 | std::vector<CodeViewYAML::SymbolRecord> Symbols; |
| 191 | }; |
| 192 | |
| 193 | struct YAMLStringTableSubsection : public YAMLSubsectionBase { |
| 194 | YAMLStringTableSubsection() |
| 195 | : YAMLSubsectionBase(DebugSubsectionKind::StringTable) {} |
| 196 | |
| 197 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 198 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 199 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 200 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 201 | static Expected<std::shared_ptr<YAMLStringTableSubsection>> |
| 202 | fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings); |
| 203 | |
| 204 | std::vector<StringRef> Strings; |
| 205 | }; |
| 206 | |
| 207 | struct YAMLFrameDataSubsection : public YAMLSubsectionBase { |
| 208 | YAMLFrameDataSubsection() |
| 209 | : YAMLSubsectionBase(DebugSubsectionKind::FrameData) {} |
| 210 | |
| 211 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 212 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 213 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 214 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 215 | static Expected<std::shared_ptr<YAMLFrameDataSubsection>> |
| 216 | fromCodeViewSubsection(const DebugStringTableSubsectionRef &Strings, |
| 217 | const DebugFrameDataSubsectionRef &Frames); |
| 218 | |
| 219 | std::vector<YAMLFrameData> Frames; |
| 220 | }; |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 221 | |
| 222 | struct YAMLCoffSymbolRVASubsection : public YAMLSubsectionBase { |
| 223 | YAMLCoffSymbolRVASubsection() |
| 224 | : YAMLSubsectionBase(DebugSubsectionKind::CoffSymbolRVA) {} |
| 225 | |
| 226 | void map(IO &IO) override; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 227 | std::shared_ptr<DebugSubsection> |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 228 | toCodeViewSubsection(BumpPtrAllocator &Allocator, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 229 | const codeview::StringsAndChecksums &SC) const override; |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 230 | static Expected<std::shared_ptr<YAMLCoffSymbolRVASubsection>> |
| 231 | fromCodeViewSubsection(const DebugSymbolRVASubsectionRef &RVAs); |
| 232 | |
| 233 | std::vector<uint32_t> RVAs; |
| 234 | }; |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 235 | |
| 236 | } // end anonymous namespace |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 237 | |
| 238 | void ScalarBitSetTraits<LineFlags>::bitset(IO &io, LineFlags &Flags) { |
| 239 | io.bitSetCase(Flags, "HasColumnInfo", LF_HaveColumns); |
| 240 | io.enumFallback<Hex16>(Flags); |
| 241 | } |
| 242 | |
| 243 | void ScalarEnumerationTraits<FileChecksumKind>::enumeration( |
| 244 | IO &io, FileChecksumKind &Kind) { |
| 245 | io.enumCase(Kind, "None", FileChecksumKind::None); |
| 246 | io.enumCase(Kind, "MD5", FileChecksumKind::MD5); |
| 247 | io.enumCase(Kind, "SHA1", FileChecksumKind::SHA1); |
| 248 | io.enumCase(Kind, "SHA256", FileChecksumKind::SHA256); |
| 249 | } |
| 250 | |
| 251 | void ScalarTraits<HexFormattedString>::output(const HexFormattedString &Value, |
| 252 | void *ctx, raw_ostream &Out) { |
| 253 | StringRef Bytes(reinterpret_cast<const char *>(Value.Bytes.data()), |
| 254 | Value.Bytes.size()); |
| 255 | Out << toHex(Bytes); |
| 256 | } |
| 257 | |
| 258 | StringRef ScalarTraits<HexFormattedString>::input(StringRef Scalar, void *ctxt, |
| 259 | HexFormattedString &Value) { |
| 260 | std::string H = fromHex(Scalar); |
| 261 | Value.Bytes.assign(H.begin(), H.end()); |
| 262 | return StringRef(); |
| 263 | } |
| 264 | |
| 265 | void MappingTraits<SourceLineEntry>::mapping(IO &IO, SourceLineEntry &Obj) { |
| 266 | IO.mapRequired("Offset", Obj.Offset); |
| 267 | IO.mapRequired("LineStart", Obj.LineStart); |
| 268 | IO.mapRequired("IsStatement", Obj.IsStatement); |
| 269 | IO.mapRequired("EndDelta", Obj.EndDelta); |
| 270 | } |
| 271 | |
| 272 | void MappingTraits<SourceColumnEntry>::mapping(IO &IO, SourceColumnEntry &Obj) { |
| 273 | IO.mapRequired("StartColumn", Obj.StartColumn); |
| 274 | IO.mapRequired("EndColumn", Obj.EndColumn); |
| 275 | } |
| 276 | |
| 277 | void MappingTraits<SourceLineBlock>::mapping(IO &IO, SourceLineBlock &Obj) { |
| 278 | IO.mapRequired("FileName", Obj.FileName); |
| 279 | IO.mapRequired("Lines", Obj.Lines); |
| 280 | IO.mapRequired("Columns", Obj.Columns); |
| 281 | } |
| 282 | |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 283 | void MappingTraits<CrossModuleExport>::mapping(IO &IO, CrossModuleExport &Obj) { |
| 284 | IO.mapRequired("LocalId", Obj.Local); |
| 285 | IO.mapRequired("GlobalId", Obj.Global); |
| 286 | } |
| 287 | |
| 288 | void MappingTraits<YAMLCrossModuleImport>::mapping(IO &IO, |
| 289 | YAMLCrossModuleImport &Obj) { |
| 290 | IO.mapRequired("Module", Obj.ModuleName); |
| 291 | IO.mapRequired("Imports", Obj.ImportIds); |
| 292 | } |
| 293 | |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 294 | void MappingTraits<SourceFileChecksumEntry>::mapping( |
| 295 | IO &IO, SourceFileChecksumEntry &Obj) { |
| 296 | IO.mapRequired("FileName", Obj.FileName); |
| 297 | IO.mapRequired("Kind", Obj.Kind); |
| 298 | IO.mapRequired("Checksum", Obj.ChecksumBytes); |
| 299 | } |
| 300 | |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 301 | void MappingTraits<InlineeSite>::mapping(IO &IO, InlineeSite &Obj) { |
| 302 | IO.mapRequired("FileName", Obj.FileName); |
| 303 | IO.mapRequired("LineNum", Obj.SourceLineNum); |
| 304 | IO.mapRequired("Inlinee", Obj.Inlinee); |
| 305 | IO.mapOptional("ExtraFiles", Obj.ExtraFiles); |
| 306 | } |
| 307 | |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 308 | void MappingTraits<YAMLFrameData>::mapping(IO &IO, YAMLFrameData &Obj) { |
| 309 | IO.mapRequired("CodeSize", Obj.CodeSize); |
| 310 | IO.mapRequired("FrameFunc", Obj.FrameFunc); |
| 311 | IO.mapRequired("LocalSize", Obj.LocalSize); |
| 312 | IO.mapOptional("MaxStackSize", Obj.MaxStackSize); |
| 313 | IO.mapOptional("ParamsSize", Obj.ParamsSize); |
| 314 | IO.mapOptional("PrologSize", Obj.PrologSize); |
| 315 | IO.mapOptional("RvaStart", Obj.RvaStart); |
| 316 | IO.mapOptional("SavedRegsSize", Obj.SavedRegsSize); |
| 317 | } |
| 318 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 319 | void YAMLChecksumsSubsection::map(IO &IO) { |
| 320 | IO.mapTag("!FileChecksums", true); |
| 321 | IO.mapRequired("Checksums", Checksums); |
| 322 | } |
| 323 | |
| 324 | void YAMLLinesSubsection::map(IO &IO) { |
| 325 | IO.mapTag("!Lines", true); |
| 326 | IO.mapRequired("CodeSize", Lines.CodeSize); |
| 327 | |
| 328 | IO.mapRequired("Flags", Lines.Flags); |
| 329 | IO.mapRequired("RelocOffset", Lines.RelocOffset); |
| 330 | IO.mapRequired("RelocSegment", Lines.RelocSegment); |
| 331 | IO.mapRequired("Blocks", Lines.Blocks); |
| 332 | } |
| 333 | |
| 334 | void YAMLInlineeLinesSubsection::map(IO &IO) { |
| 335 | IO.mapTag("!InlineeLines", true); |
| 336 | IO.mapRequired("HasExtraFiles", InlineeLines.HasExtraFiles); |
| 337 | IO.mapRequired("Sites", InlineeLines.Sites); |
| 338 | } |
| 339 | |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 340 | void YAMLCrossModuleExportsSubsection::map(IO &IO) { |
| 341 | IO.mapTag("!CrossModuleExports", true); |
| 342 | IO.mapOptional("Exports", Exports); |
| 343 | } |
| 344 | |
| 345 | void YAMLCrossModuleImportsSubsection::map(IO &IO) { |
| 346 | IO.mapTag("!CrossModuleImports", true); |
| 347 | IO.mapOptional("Imports", Imports); |
| 348 | } |
| 349 | |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 350 | void YAMLSymbolsSubsection::map(IO &IO) { |
| 351 | IO.mapTag("!Symbols", true); |
| 352 | IO.mapRequired("Records", Symbols); |
| 353 | } |
| 354 | |
| 355 | void YAMLStringTableSubsection::map(IO &IO) { |
| 356 | IO.mapTag("!StringTable", true); |
| 357 | IO.mapRequired("Strings", Strings); |
| 358 | } |
| 359 | |
| 360 | void YAMLFrameDataSubsection::map(IO &IO) { |
| 361 | IO.mapTag("!FrameData", true); |
| 362 | IO.mapRequired("Frames", Frames); |
| 363 | } |
| 364 | |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 365 | void YAMLCoffSymbolRVASubsection::map(IO &IO) { |
| 366 | IO.mapTag("!COFFSymbolRVAs", true); |
| 367 | IO.mapRequired("RVAs", RVAs); |
| 368 | } |
| 369 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 370 | void MappingTraits<YAMLDebugSubsection>::mapping( |
| 371 | IO &IO, YAMLDebugSubsection &Subsection) { |
| 372 | if (!IO.outputting()) { |
| 373 | if (IO.mapTag("!FileChecksums")) { |
| 374 | auto SS = std::make_shared<YAMLChecksumsSubsection>(); |
| 375 | Subsection.Subsection = SS; |
| 376 | } else if (IO.mapTag("!Lines")) { |
| 377 | Subsection.Subsection = std::make_shared<YAMLLinesSubsection>(); |
| 378 | } else if (IO.mapTag("!InlineeLines")) { |
| 379 | Subsection.Subsection = std::make_shared<YAMLInlineeLinesSubsection>(); |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 380 | } else if (IO.mapTag("!CrossModuleExports")) { |
| 381 | Subsection.Subsection = |
| 382 | std::make_shared<YAMLCrossModuleExportsSubsection>(); |
| 383 | } else if (IO.mapTag("!CrossModuleImports")) { |
| 384 | Subsection.Subsection = |
| 385 | std::make_shared<YAMLCrossModuleImportsSubsection>(); |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 386 | } else if (IO.mapTag("!Symbols")) { |
| 387 | Subsection.Subsection = std::make_shared<YAMLSymbolsSubsection>(); |
| 388 | } else if (IO.mapTag("!StringTable")) { |
| 389 | Subsection.Subsection = std::make_shared<YAMLStringTableSubsection>(); |
| 390 | } else if (IO.mapTag("!FrameData")) { |
| 391 | Subsection.Subsection = std::make_shared<YAMLFrameDataSubsection>(); |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 392 | } else if (IO.mapTag("!COFFSymbolRVAs")) { |
| 393 | Subsection.Subsection = std::make_shared<YAMLCoffSymbolRVASubsection>(); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 394 | } else { |
| 395 | llvm_unreachable("Unexpected subsection tag!"); |
| 396 | } |
| 397 | } |
| 398 | Subsection.Subsection->map(IO); |
| 399 | } |
| 400 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 401 | std::shared_ptr<DebugSubsection> YAMLChecksumsSubsection::toCodeViewSubsection( |
| 402 | BumpPtrAllocator &Allocator, |
| 403 | const codeview::StringsAndChecksums &SC) const { |
| 404 | assert(SC.hasStrings()); |
| 405 | auto Result = std::make_shared<DebugChecksumsSubsection>(*SC.strings()); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 406 | for (const auto &CS : Checksums) { |
| 407 | Result->addChecksum(CS.FileName, CS.Kind, CS.ChecksumBytes.Bytes); |
| 408 | } |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 409 | return Result; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 412 | std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection( |
| 413 | BumpPtrAllocator &Allocator, |
| 414 | const codeview::StringsAndChecksums &SC) const { |
| 415 | assert(SC.hasStrings() && SC.hasChecksums()); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 416 | auto Result = |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 417 | std::make_shared<DebugLinesSubsection>(*SC.checksums(), *SC.strings()); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 418 | Result->setCodeSize(Lines.CodeSize); |
| 419 | Result->setRelocationAddress(Lines.RelocSegment, Lines.RelocOffset); |
| 420 | Result->setFlags(Lines.Flags); |
| 421 | for (const auto &LC : Lines.Blocks) { |
| 422 | Result->createBlock(LC.FileName); |
| 423 | if (Result->hasColumnInfo()) { |
| 424 | for (const auto &Item : zip(LC.Lines, LC.Columns)) { |
| 425 | auto &L = std::get<0>(Item); |
| 426 | auto &C = std::get<1>(Item); |
| 427 | uint32_t LE = L.LineStart + L.EndDelta; |
| 428 | Result->addLineAndColumnInfo(L.Offset, |
| 429 | LineInfo(L.LineStart, LE, L.IsStatement), |
| 430 | C.StartColumn, C.EndColumn); |
| 431 | } |
| 432 | } else { |
| 433 | for (const auto &L : LC.Lines) { |
| 434 | uint32_t LE = L.LineStart + L.EndDelta; |
| 435 | Result->addLineInfo(L.Offset, LineInfo(L.LineStart, LE, L.IsStatement)); |
| 436 | } |
| 437 | } |
| 438 | } |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 439 | return Result; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 442 | std::shared_ptr<DebugSubsection> |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 443 | YAMLInlineeLinesSubsection::toCodeViewSubsection( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 444 | BumpPtrAllocator &Allocator, |
| 445 | const codeview::StringsAndChecksums &SC) const { |
| 446 | assert(SC.hasChecksums()); |
| 447 | auto Result = std::make_shared<DebugInlineeLinesSubsection>( |
| 448 | *SC.checksums(), InlineeLines.HasExtraFiles); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 449 | |
| 450 | for (const auto &Site : InlineeLines.Sites) { |
| 451 | Result->addInlineSite(TypeIndex(Site.Inlinee), Site.FileName, |
| 452 | Site.SourceLineNum); |
| 453 | if (!InlineeLines.HasExtraFiles) |
| 454 | continue; |
| 455 | |
| 456 | for (auto EF : Site.ExtraFiles) { |
| 457 | Result->addExtraFile(EF); |
| 458 | } |
| 459 | } |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 460 | return Result; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 463 | std::shared_ptr<DebugSubsection> |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 464 | YAMLCrossModuleExportsSubsection::toCodeViewSubsection( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 465 | BumpPtrAllocator &Allocator, |
| 466 | const codeview::StringsAndChecksums &SC) const { |
| 467 | auto Result = std::make_shared<DebugCrossModuleExportsSubsection>(); |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 468 | for (const auto &M : Exports) |
| 469 | Result->addMapping(M.Local, M.Global); |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 470 | return Result; |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 473 | std::shared_ptr<DebugSubsection> |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 474 | YAMLCrossModuleImportsSubsection::toCodeViewSubsection( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 475 | BumpPtrAllocator &Allocator, |
| 476 | const codeview::StringsAndChecksums &SC) const { |
| 477 | assert(SC.hasStrings()); |
| 478 | |
| 479 | auto Result = |
| 480 | std::make_shared<DebugCrossModuleImportsSubsection>(*SC.strings()); |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 481 | for (const auto &M : Imports) { |
| 482 | for (const auto Id : M.ImportIds) |
| 483 | Result->addImport(M.ModuleName, Id); |
| 484 | } |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 485 | return Result; |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 488 | std::shared_ptr<DebugSubsection> YAMLSymbolsSubsection::toCodeViewSubsection( |
| 489 | BumpPtrAllocator &Allocator, |
| 490 | const codeview::StringsAndChecksums &SC) const { |
| 491 | auto Result = std::make_shared<DebugSymbolsSubsection>(); |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 492 | for (const auto &Sym : Symbols) |
| 493 | Result->addSymbol( |
| 494 | Sym.toCodeViewSymbol(Allocator, CodeViewContainer::ObjectFile)); |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 495 | return Result; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 498 | std::shared_ptr<DebugSubsection> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 499 | YAMLStringTableSubsection::toCodeViewSubsection( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 500 | BumpPtrAllocator &Allocator, |
| 501 | const codeview::StringsAndChecksums &SC) const { |
| 502 | auto Result = std::make_shared<DebugStringTableSubsection>(); |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 503 | for (const auto &Str : this->Strings) |
| 504 | Result->insert(Str); |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 505 | return Result; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 508 | std::shared_ptr<DebugSubsection> YAMLFrameDataSubsection::toCodeViewSubsection( |
| 509 | BumpPtrAllocator &Allocator, |
| 510 | const codeview::StringsAndChecksums &SC) const { |
| 511 | assert(SC.hasStrings()); |
| 512 | |
Zachary Turner | 42e7cc1b | 2018-09-11 22:35:01 +0000 | [diff] [blame] | 513 | auto Result = std::make_shared<DebugFrameDataSubsection>(true); |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 514 | for (const auto &YF : Frames) { |
| 515 | codeview::FrameData F; |
| 516 | F.CodeSize = YF.CodeSize; |
| 517 | F.Flags = YF.Flags; |
| 518 | F.LocalSize = YF.LocalSize; |
| 519 | F.MaxStackSize = YF.MaxStackSize; |
| 520 | F.ParamsSize = YF.ParamsSize; |
| 521 | F.PrologSize = YF.PrologSize; |
| 522 | F.RvaStart = YF.RvaStart; |
| 523 | F.SavedRegsSize = YF.SavedRegsSize; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 524 | F.FrameFunc = SC.strings()->insert(YF.FrameFunc); |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 525 | Result->addFrameData(F); |
| 526 | } |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 527 | return Result; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 530 | std::shared_ptr<DebugSubsection> |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 531 | YAMLCoffSymbolRVASubsection::toCodeViewSubsection( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 532 | BumpPtrAllocator &Allocator, |
| 533 | const codeview::StringsAndChecksums &SC) const { |
| 534 | auto Result = std::make_shared<DebugSymbolRVASubsection>(); |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 535 | for (const auto &RVA : RVAs) |
| 536 | Result->addRVA(RVA); |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 537 | return Result; |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 540 | static Expected<SourceFileChecksumEntry> |
| 541 | convertOneChecksum(const DebugStringTableSubsectionRef &Strings, |
| 542 | const FileChecksumEntry &CS) { |
| 543 | auto ExpectedString = Strings.getString(CS.FileNameOffset); |
| 544 | if (!ExpectedString) |
| 545 | return ExpectedString.takeError(); |
| 546 | |
| 547 | SourceFileChecksumEntry Result; |
| 548 | Result.ChecksumBytes.Bytes = CS.Checksum; |
| 549 | Result.Kind = CS.Kind; |
| 550 | Result.FileName = *ExpectedString; |
| 551 | return Result; |
| 552 | } |
| 553 | |
| 554 | static Expected<StringRef> |
| 555 | getFileName(const DebugStringTableSubsectionRef &Strings, |
| 556 | const DebugChecksumsSubsectionRef &Checksums, uint32_t FileID) { |
| 557 | auto Iter = Checksums.getArray().at(FileID); |
| 558 | if (Iter == Checksums.getArray().end()) |
| 559 | return make_error<CodeViewError>(cv_error_code::no_records); |
| 560 | uint32_t Offset = Iter->FileNameOffset; |
| 561 | return Strings.getString(Offset); |
| 562 | } |
| 563 | |
| 564 | Expected<std::shared_ptr<YAMLChecksumsSubsection>> |
| 565 | YAMLChecksumsSubsection::fromCodeViewSubsection( |
| 566 | const DebugStringTableSubsectionRef &Strings, |
| 567 | const DebugChecksumsSubsectionRef &FC) { |
| 568 | auto Result = std::make_shared<YAMLChecksumsSubsection>(); |
| 569 | |
| 570 | for (const auto &CS : FC) { |
| 571 | auto ConvertedCS = convertOneChecksum(Strings, CS); |
| 572 | if (!ConvertedCS) |
| 573 | return ConvertedCS.takeError(); |
| 574 | Result->Checksums.push_back(*ConvertedCS); |
| 575 | } |
| 576 | return Result; |
| 577 | } |
| 578 | |
| 579 | Expected<std::shared_ptr<YAMLLinesSubsection>> |
| 580 | YAMLLinesSubsection::fromCodeViewSubsection( |
| 581 | const DebugStringTableSubsectionRef &Strings, |
| 582 | const DebugChecksumsSubsectionRef &Checksums, |
| 583 | const DebugLinesSubsectionRef &Lines) { |
| 584 | auto Result = std::make_shared<YAMLLinesSubsection>(); |
| 585 | Result->Lines.CodeSize = Lines.header()->CodeSize; |
| 586 | Result->Lines.RelocOffset = Lines.header()->RelocOffset; |
| 587 | Result->Lines.RelocSegment = Lines.header()->RelocSegment; |
| 588 | Result->Lines.Flags = static_cast<LineFlags>(uint16_t(Lines.header()->Flags)); |
| 589 | for (const auto &L : Lines) { |
| 590 | SourceLineBlock Block; |
| 591 | auto EF = getFileName(Strings, Checksums, L.NameIndex); |
| 592 | if (!EF) |
| 593 | return EF.takeError(); |
| 594 | Block.FileName = *EF; |
| 595 | if (Lines.hasColumnInfo()) { |
| 596 | for (const auto &C : L.Columns) { |
| 597 | SourceColumnEntry SCE; |
| 598 | SCE.EndColumn = C.EndColumn; |
| 599 | SCE.StartColumn = C.StartColumn; |
| 600 | Block.Columns.push_back(SCE); |
| 601 | } |
| 602 | } |
| 603 | for (const auto &LN : L.LineNumbers) { |
| 604 | SourceLineEntry SLE; |
| 605 | LineInfo LI(LN.Flags); |
| 606 | SLE.Offset = LN.Offset; |
| 607 | SLE.LineStart = LI.getStartLine(); |
| 608 | SLE.EndDelta = LI.getLineDelta(); |
| 609 | SLE.IsStatement = LI.isStatement(); |
| 610 | Block.Lines.push_back(SLE); |
| 611 | } |
| 612 | Result->Lines.Blocks.push_back(Block); |
| 613 | } |
| 614 | return Result; |
| 615 | } |
| 616 | |
| 617 | Expected<std::shared_ptr<YAMLInlineeLinesSubsection>> |
| 618 | YAMLInlineeLinesSubsection::fromCodeViewSubsection( |
| 619 | const DebugStringTableSubsectionRef &Strings, |
| 620 | const DebugChecksumsSubsectionRef &Checksums, |
| 621 | const DebugInlineeLinesSubsectionRef &Lines) { |
| 622 | auto Result = std::make_shared<YAMLInlineeLinesSubsection>(); |
| 623 | |
| 624 | Result->InlineeLines.HasExtraFiles = Lines.hasExtraFiles(); |
| 625 | for (const auto &IL : Lines) { |
| 626 | InlineeSite Site; |
| 627 | auto ExpF = getFileName(Strings, Checksums, IL.Header->FileID); |
| 628 | if (!ExpF) |
| 629 | return ExpF.takeError(); |
| 630 | Site.FileName = *ExpF; |
| 631 | Site.Inlinee = IL.Header->Inlinee.getIndex(); |
| 632 | Site.SourceLineNum = IL.Header->SourceLineNum; |
| 633 | if (Lines.hasExtraFiles()) { |
| 634 | for (const auto EF : IL.ExtraFiles) { |
| 635 | auto ExpF2 = getFileName(Strings, Checksums, EF); |
| 636 | if (!ExpF2) |
| 637 | return ExpF2.takeError(); |
| 638 | Site.ExtraFiles.push_back(*ExpF2); |
| 639 | } |
| 640 | } |
| 641 | Result->InlineeLines.Sites.push_back(Site); |
| 642 | } |
| 643 | return Result; |
| 644 | } |
| 645 | |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 646 | Expected<std::shared_ptr<YAMLCrossModuleExportsSubsection>> |
| 647 | YAMLCrossModuleExportsSubsection::fromCodeViewSubsection( |
| 648 | const DebugCrossModuleExportsSubsectionRef &Exports) { |
| 649 | auto Result = std::make_shared<YAMLCrossModuleExportsSubsection>(); |
| 650 | Result->Exports.assign(Exports.begin(), Exports.end()); |
| 651 | return Result; |
| 652 | } |
| 653 | |
| 654 | Expected<std::shared_ptr<YAMLCrossModuleImportsSubsection>> |
| 655 | YAMLCrossModuleImportsSubsection::fromCodeViewSubsection( |
| 656 | const DebugStringTableSubsectionRef &Strings, |
| 657 | const DebugCrossModuleImportsSubsectionRef &Imports) { |
| 658 | auto Result = std::make_shared<YAMLCrossModuleImportsSubsection>(); |
| 659 | for (const auto &CMI : Imports) { |
| 660 | YAMLCrossModuleImport YCMI; |
| 661 | auto ExpectedStr = Strings.getString(CMI.Header->ModuleNameOffset); |
| 662 | if (!ExpectedStr) |
| 663 | return ExpectedStr.takeError(); |
| 664 | YCMI.ModuleName = *ExpectedStr; |
| 665 | YCMI.ImportIds.assign(CMI.Imports.begin(), CMI.Imports.end()); |
| 666 | Result->Imports.push_back(YCMI); |
| 667 | } |
| 668 | return Result; |
| 669 | } |
| 670 | |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 671 | Expected<std::shared_ptr<YAMLSymbolsSubsection>> |
| 672 | YAMLSymbolsSubsection::fromCodeViewSubsection( |
| 673 | const DebugSymbolsSubsectionRef &Symbols) { |
| 674 | auto Result = std::make_shared<YAMLSymbolsSubsection>(); |
| 675 | for (const auto &Sym : Symbols) { |
| 676 | auto S = CodeViewYAML::SymbolRecord::fromCodeViewSymbol(Sym); |
| 677 | if (!S) |
| 678 | return joinErrors(make_error<CodeViewError>( |
| 679 | cv_error_code::corrupt_record, |
| 680 | "Invalid CodeView Symbol Record in SymbolRecord " |
| 681 | "subsection of .debug$S while converting to YAML!"), |
| 682 | S.takeError()); |
| 683 | |
| 684 | Result->Symbols.push_back(*S); |
| 685 | } |
| 686 | return Result; |
| 687 | } |
| 688 | |
| 689 | Expected<std::shared_ptr<YAMLStringTableSubsection>> |
| 690 | YAMLStringTableSubsection::fromCodeViewSubsection( |
| 691 | const DebugStringTableSubsectionRef &Strings) { |
| 692 | auto Result = std::make_shared<YAMLStringTableSubsection>(); |
| 693 | BinaryStreamReader Reader(Strings.getBuffer()); |
| 694 | StringRef S; |
| 695 | // First item is a single null string, skip it. |
| 696 | if (auto EC = Reader.readCString(S)) |
| 697 | return std::move(EC); |
| 698 | assert(S.empty()); |
| 699 | while (Reader.bytesRemaining() > 0) { |
| 700 | if (auto EC = Reader.readCString(S)) |
| 701 | return std::move(EC); |
| 702 | Result->Strings.push_back(S); |
| 703 | } |
| 704 | return Result; |
| 705 | } |
| 706 | |
| 707 | Expected<std::shared_ptr<YAMLFrameDataSubsection>> |
| 708 | YAMLFrameDataSubsection::fromCodeViewSubsection( |
| 709 | const DebugStringTableSubsectionRef &Strings, |
| 710 | const DebugFrameDataSubsectionRef &Frames) { |
| 711 | auto Result = std::make_shared<YAMLFrameDataSubsection>(); |
| 712 | for (const auto &F : Frames) { |
| 713 | YAMLFrameData YF; |
| 714 | YF.CodeSize = F.CodeSize; |
| 715 | YF.Flags = F.Flags; |
| 716 | YF.LocalSize = F.LocalSize; |
| 717 | YF.MaxStackSize = F.MaxStackSize; |
| 718 | YF.ParamsSize = F.ParamsSize; |
| 719 | YF.PrologSize = F.PrologSize; |
| 720 | YF.RvaStart = F.RvaStart; |
| 721 | YF.SavedRegsSize = F.SavedRegsSize; |
| 722 | |
| 723 | auto ES = Strings.getString(F.FrameFunc); |
| 724 | if (!ES) |
| 725 | return joinErrors( |
| 726 | make_error<CodeViewError>( |
| 727 | cv_error_code::no_records, |
| 728 | "Could not find string for string id while mapping FrameData!"), |
| 729 | ES.takeError()); |
| 730 | YF.FrameFunc = *ES; |
| 731 | Result->Frames.push_back(YF); |
| 732 | } |
| 733 | return Result; |
| 734 | } |
| 735 | |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 736 | Expected<std::shared_ptr<YAMLCoffSymbolRVASubsection>> |
| 737 | YAMLCoffSymbolRVASubsection::fromCodeViewSubsection( |
| 738 | const DebugSymbolRVASubsectionRef &Section) { |
| 739 | auto Result = std::make_shared<YAMLCoffSymbolRVASubsection>(); |
| 740 | for (const auto &RVA : Section) { |
| 741 | Result->RVAs.push_back(RVA); |
| 742 | } |
| 743 | return Result; |
| 744 | } |
| 745 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 746 | Expected<std::vector<std::shared_ptr<DebugSubsection>>> |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 747 | llvm::CodeViewYAML::toCodeViewSubsectionList( |
| 748 | BumpPtrAllocator &Allocator, ArrayRef<YAMLDebugSubsection> Subsections, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 749 | const codeview::StringsAndChecksums &SC) { |
| 750 | std::vector<std::shared_ptr<DebugSubsection>> Result; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 751 | if (Subsections.empty()) |
Zachary Turner | 64726f2 | 2017-06-02 21:00:22 +0000 | [diff] [blame] | 752 | return std::move(Result); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 753 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 754 | for (const auto &SS : Subsections) { |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 755 | std::shared_ptr<DebugSubsection> CVS; |
| 756 | CVS = SS.Subsection->toCodeViewSubsection(Allocator, SC); |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 757 | assert(CVS != nullptr); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 758 | Result.push_back(std::move(CVS)); |
| 759 | } |
| 760 | return std::move(Result); |
| 761 | } |
| 762 | |
| 763 | namespace { |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 764 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 765 | struct SubsectionConversionVisitor : public DebugSubsectionVisitor { |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 766 | SubsectionConversionVisitor() = default; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 767 | |
| 768 | Error visitUnknown(DebugUnknownSubsectionRef &Unknown) override; |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 769 | Error visitLines(DebugLinesSubsectionRef &Lines, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 770 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 771 | Error visitFileChecksums(DebugChecksumsSubsectionRef &Checksums, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 772 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 773 | Error visitInlineeLines(DebugInlineeLinesSubsectionRef &Inlinees, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 774 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 775 | Error visitCrossModuleExports(DebugCrossModuleExportsSubsectionRef &Checksums, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 776 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 777 | Error visitCrossModuleImports(DebugCrossModuleImportsSubsectionRef &Inlinees, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 778 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 779 | Error visitStringTable(DebugStringTableSubsectionRef &ST, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 780 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 781 | Error visitSymbols(DebugSymbolsSubsectionRef &Symbols, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 782 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 783 | Error visitFrameData(DebugFrameDataSubsectionRef &Symbols, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 784 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 785 | Error visitCOFFSymbolRVAs(DebugSymbolRVASubsectionRef &Symbols, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 786 | const StringsAndChecksumsRef &State) override; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 787 | |
| 788 | YAMLDebugSubsection Subsection; |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 789 | }; |
| 790 | |
Eugene Zelenko | 28082ab | 2017-07-01 01:35:55 +0000 | [diff] [blame] | 791 | } // end anonymous namespace |
| 792 | |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 793 | Error SubsectionConversionVisitor::visitUnknown( |
| 794 | DebugUnknownSubsectionRef &Unknown) { |
| 795 | return make_error<CodeViewError>(cv_error_code::operation_unsupported); |
| 796 | } |
| 797 | |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 798 | Error SubsectionConversionVisitor::visitLines( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 799 | DebugLinesSubsectionRef &Lines, const StringsAndChecksumsRef &State) { |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 800 | auto Result = YAMLLinesSubsection::fromCodeViewSubsection( |
| 801 | State.strings(), State.checksums(), Lines); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 802 | if (!Result) |
| 803 | return Result.takeError(); |
| 804 | Subsection.Subsection = *Result; |
| 805 | return Error::success(); |
| 806 | } |
| 807 | |
| 808 | Error SubsectionConversionVisitor::visitFileChecksums( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 809 | DebugChecksumsSubsectionRef &Checksums, |
| 810 | const StringsAndChecksumsRef &State) { |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 811 | auto Result = YAMLChecksumsSubsection::fromCodeViewSubsection(State.strings(), |
| 812 | Checksums); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 813 | if (!Result) |
| 814 | return Result.takeError(); |
| 815 | Subsection.Subsection = *Result; |
| 816 | return Error::success(); |
| 817 | } |
| 818 | |
| 819 | Error SubsectionConversionVisitor::visitInlineeLines( |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 820 | DebugInlineeLinesSubsectionRef &Inlinees, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 821 | const StringsAndChecksumsRef &State) { |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 822 | auto Result = YAMLInlineeLinesSubsection::fromCodeViewSubsection( |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 823 | State.strings(), State.checksums(), Inlinees); |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 824 | if (!Result) |
| 825 | return Result.takeError(); |
| 826 | Subsection.Subsection = *Result; |
| 827 | return Error::success(); |
| 828 | } |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 829 | |
| 830 | Error SubsectionConversionVisitor::visitCrossModuleExports( |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 831 | DebugCrossModuleExportsSubsectionRef &Exports, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 832 | const StringsAndChecksumsRef &State) { |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 833 | auto Result = |
| 834 | YAMLCrossModuleExportsSubsection::fromCodeViewSubsection(Exports); |
| 835 | if (!Result) |
| 836 | return Result.takeError(); |
| 837 | Subsection.Subsection = *Result; |
| 838 | return Error::success(); |
| 839 | } |
| 840 | |
| 841 | Error SubsectionConversionVisitor::visitCrossModuleImports( |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 842 | DebugCrossModuleImportsSubsectionRef &Imports, |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 843 | const StringsAndChecksumsRef &State) { |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 844 | auto Result = YAMLCrossModuleImportsSubsection::fromCodeViewSubsection( |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 845 | State.strings(), Imports); |
Zachary Turner | 349c18f | 2017-06-05 21:40:33 +0000 | [diff] [blame] | 846 | if (!Result) |
| 847 | return Result.takeError(); |
| 848 | Subsection.Subsection = *Result; |
| 849 | return Error::success(); |
| 850 | } |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 851 | |
| 852 | Error SubsectionConversionVisitor::visitStringTable( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 853 | DebugStringTableSubsectionRef &Strings, |
| 854 | const StringsAndChecksumsRef &State) { |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 855 | auto Result = YAMLStringTableSubsection::fromCodeViewSubsection(Strings); |
| 856 | if (!Result) |
| 857 | return Result.takeError(); |
| 858 | Subsection.Subsection = *Result; |
| 859 | return Error::success(); |
| 860 | } |
| 861 | |
| 862 | Error SubsectionConversionVisitor::visitSymbols( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 863 | DebugSymbolsSubsectionRef &Symbols, const StringsAndChecksumsRef &State) { |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 864 | auto Result = YAMLSymbolsSubsection::fromCodeViewSubsection(Symbols); |
| 865 | if (!Result) |
| 866 | return Result.takeError(); |
| 867 | Subsection.Subsection = *Result; |
| 868 | return Error::success(); |
| 869 | } |
| 870 | |
| 871 | Error SubsectionConversionVisitor::visitFrameData( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 872 | DebugFrameDataSubsectionRef &Frames, const StringsAndChecksumsRef &State) { |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 873 | auto Result = |
| 874 | YAMLFrameDataSubsection::fromCodeViewSubsection(State.strings(), Frames); |
| 875 | if (!Result) |
| 876 | return Result.takeError(); |
| 877 | Subsection.Subsection = *Result; |
| 878 | return Error::success(); |
| 879 | } |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 880 | |
| 881 | Error SubsectionConversionVisitor::visitCOFFSymbolRVAs( |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 882 | DebugSymbolRVASubsectionRef &RVAs, const StringsAndChecksumsRef &State) { |
Zachary Turner | 3226fe9 | 2017-06-09 20:46:52 +0000 | [diff] [blame] | 883 | auto Result = YAMLCoffSymbolRVASubsection::fromCodeViewSubsection(RVAs); |
| 884 | if (!Result) |
| 885 | return Result.takeError(); |
| 886 | Subsection.Subsection = *Result; |
| 887 | return Error::success(); |
| 888 | } |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 889 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 890 | Expected<YAMLDebugSubsection> |
| 891 | YAMLDebugSubsection::fromCodeViewSubection(const StringsAndChecksumsRef &SC, |
| 892 | const DebugSubsectionRecord &SS) { |
Zachary Turner | 1bf7762 | 2017-06-08 23:49:01 +0000 | [diff] [blame] | 893 | SubsectionConversionVisitor V; |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 894 | if (auto EC = visitDebugSubsection(SS, V, SC)) |
Zachary Turner | 92dcdda | 2017-06-02 19:49:14 +0000 | [diff] [blame] | 895 | return std::move(EC); |
| 896 | |
| 897 | return V.Subsection; |
Zachary Turner | 1b88f4f | 2017-05-31 04:17:13 +0000 | [diff] [blame] | 898 | } |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 899 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 900 | std::vector<YAMLDebugSubsection> |
| 901 | llvm::CodeViewYAML::fromDebugS(ArrayRef<uint8_t> Data, |
| 902 | const StringsAndChecksumsRef &SC) { |
| 903 | BinaryStreamReader Reader(Data, support::little); |
| 904 | uint32_t Magic; |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 905 | |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 906 | ExitOnError Err("Invalid .debug$S section!"); |
| 907 | Err(Reader.readInteger(Magic)); |
| 908 | assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$S section!"); |
| 909 | |
| 910 | DebugSubsectionArray Subsections; |
| 911 | Err(Reader.readArray(Subsections, Reader.bytesRemaining())); |
| 912 | |
| 913 | std::vector<YAMLDebugSubsection> Result; |
| 914 | |
| 915 | for (const auto &SS : Subsections) { |
| 916 | auto YamlSS = Err(YAMLDebugSubsection::fromCodeViewSubection(SC, SS)); |
| 917 | Result.push_back(YamlSS); |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 918 | } |
Zachary Turner | a8cfc29 | 2017-06-14 15:59:27 +0000 | [diff] [blame] | 919 | return Result; |
| 920 | } |
| 921 | |
| 922 | void llvm::CodeViewYAML::initializeStringsAndChecksums( |
| 923 | ArrayRef<YAMLDebugSubsection> Sections, codeview::StringsAndChecksums &SC) { |
| 924 | // String Table and Checksums subsections don't use the allocator. |
| 925 | BumpPtrAllocator Allocator; |
| 926 | |
| 927 | // It's possible for checksums and strings to even appear in different debug$S |
| 928 | // sections, so we have to make this a stateful function that can build up |
| 929 | // the strings and checksums field over multiple iterations. |
| 930 | |
| 931 | // File Checksums require the string table, but may become before it, so we |
| 932 | // have to scan for strings first, then scan for checksums again from the |
| 933 | // beginning. |
| 934 | if (!SC.hasStrings()) { |
| 935 | for (const auto &SS : Sections) { |
| 936 | if (SS.Subsection->Kind != DebugSubsectionKind::StringTable) |
| 937 | continue; |
| 938 | |
| 939 | auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC); |
| 940 | SC.setStrings( |
| 941 | std::static_pointer_cast<DebugStringTableSubsection>(Result)); |
| 942 | break; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | if (SC.hasStrings() && !SC.hasChecksums()) { |
| 947 | for (const auto &SS : Sections) { |
| 948 | if (SS.Subsection->Kind != DebugSubsectionKind::FileChecksums) |
| 949 | continue; |
| 950 | |
| 951 | auto Result = SS.Subsection->toCodeViewSubsection(Allocator, SC); |
| 952 | SC.setChecksums( |
| 953 | std::static_pointer_cast<DebugChecksumsSubsection>(Result)); |
| 954 | break; |
| 955 | } |
| 956 | } |
Zachary Turner | deb3913 | 2017-06-09 00:28:08 +0000 | [diff] [blame] | 957 | } |