[AMDGPU] prevent shrinking udiv/urem if either operand is in (SignedMax,UnsignedMax...
[llvm-project.git] / llvm / lib / ObjectYAML / CodeViewYAMLSymbols.cpp
blobb15919f68725fab5daafe6f2da7cf005a5392fe6
1 //===- CodeViewYAMLSymbols.cpp - CodeView YAMLIO Symbol implementation ----===//
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 // This file defines classes for handling the YAML representation of CodeView
10 // Debug Info.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ObjectYAML/CodeViewYAMLSymbols.h"
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/DebugInfo/CodeView/CodeView.h"
18 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
19 #include "llvm/DebugInfo/CodeView/EnumTables.h"
20 #include "llvm/DebugInfo/CodeView/RecordSerialization.h"
21 #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
22 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
23 #include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
24 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
25 #include "llvm/ObjectYAML/YAML.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/Error.h"
28 #include "llvm/Support/ScopedPrinter.h"
29 #include "llvm/Support/YAMLTraits.h"
30 #include <algorithm>
31 #include <cstdint>
32 #include <cstring>
33 #include <optional>
34 #include <string>
35 #include <vector>
37 using namespace llvm;
38 using namespace llvm::codeview;
39 using namespace llvm::CodeViewYAML;
40 using namespace llvm::CodeViewYAML::detail;
41 using namespace llvm::yaml;
43 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TypeIndex)
44 LLVM_YAML_IS_SEQUENCE_VECTOR(LocalVariableAddrGap)
46 // We only need to declare these, the definitions are in CodeViewYAMLTypes.cpp
47 LLVM_YAML_DECLARE_SCALAR_TRAITS(APSInt, QuotingType::None)
48 LLVM_YAML_DECLARE_SCALAR_TRAITS(TypeIndex, QuotingType::None)
50 LLVM_YAML_DECLARE_ENUM_TRAITS(SymbolKind)
51 LLVM_YAML_DECLARE_ENUM_TRAITS(FrameCookieKind)
53 LLVM_YAML_DECLARE_BITSET_TRAITS(CompileSym2Flags)
54 LLVM_YAML_DECLARE_BITSET_TRAITS(CompileSym3Flags)
55 LLVM_YAML_DECLARE_BITSET_TRAITS(ExportFlags)
56 LLVM_YAML_DECLARE_BITSET_TRAITS(PublicSymFlags)
57 LLVM_YAML_DECLARE_BITSET_TRAITS(LocalSymFlags)
58 LLVM_YAML_DECLARE_BITSET_TRAITS(ProcSymFlags)
59 LLVM_YAML_DECLARE_BITSET_TRAITS(FrameProcedureOptions)
60 LLVM_YAML_DECLARE_ENUM_TRAITS(CPUType)
61 LLVM_YAML_DECLARE_ENUM_TRAITS(RegisterId)
62 LLVM_YAML_DECLARE_ENUM_TRAITS(TrampolineType)
63 LLVM_YAML_DECLARE_ENUM_TRAITS(ThunkOrdinal)
64 LLVM_YAML_DECLARE_ENUM_TRAITS(JumpTableEntrySize)
66 LLVM_YAML_STRONG_TYPEDEF(StringRef, TypeName)
68 LLVM_YAML_DECLARE_SCALAR_TRAITS(TypeName, QuotingType::Single)
70 StringRef ScalarTraits<TypeName>::input(StringRef S, void *V, TypeName &T) {
71 return ScalarTraits<StringRef>::input(S, V, T.value);
74 void ScalarTraits<TypeName>::output(const TypeName &T, void *V,
75 raw_ostream &R) {
76 ScalarTraits<StringRef>::output(T.value, V, R);
79 void ScalarEnumerationTraits<SymbolKind>::enumeration(IO &io,
80 SymbolKind &Value) {
81 auto SymbolNames = getSymbolTypeNames();
82 for (const auto &E : SymbolNames)
83 io.enumCase(Value, E.Name.str().c_str(), E.Value);
86 void ScalarBitSetTraits<CompileSym2Flags>::bitset(IO &io,
87 CompileSym2Flags &Flags) {
88 auto FlagNames = getCompileSym2FlagNames();
89 for (const auto &E : FlagNames) {
90 io.bitSetCase(Flags, E.Name.str().c_str(),
91 static_cast<CompileSym2Flags>(E.Value));
95 void ScalarBitSetTraits<CompileSym3Flags>::bitset(IO &io,
96 CompileSym3Flags &Flags) {
97 auto FlagNames = getCompileSym3FlagNames();
98 for (const auto &E : FlagNames) {
99 io.bitSetCase(Flags, E.Name.str().c_str(),
100 static_cast<CompileSym3Flags>(E.Value));
104 void ScalarBitSetTraits<ExportFlags>::bitset(IO &io, ExportFlags &Flags) {
105 auto FlagNames = getExportSymFlagNames();
106 for (const auto &E : FlagNames) {
107 io.bitSetCase(Flags, E.Name.str().c_str(),
108 static_cast<ExportFlags>(E.Value));
112 void ScalarBitSetTraits<PublicSymFlags>::bitset(IO &io, PublicSymFlags &Flags) {
113 auto FlagNames = getPublicSymFlagNames();
114 for (const auto &E : FlagNames) {
115 io.bitSetCase(Flags, E.Name.str().c_str(),
116 static_cast<PublicSymFlags>(E.Value));
120 void ScalarBitSetTraits<LocalSymFlags>::bitset(IO &io, LocalSymFlags &Flags) {
121 auto FlagNames = getLocalFlagNames();
122 for (const auto &E : FlagNames) {
123 io.bitSetCase(Flags, E.Name.str().c_str(),
124 static_cast<LocalSymFlags>(E.Value));
128 void ScalarBitSetTraits<ProcSymFlags>::bitset(IO &io, ProcSymFlags &Flags) {
129 auto FlagNames = getProcSymFlagNames();
130 for (const auto &E : FlagNames) {
131 io.bitSetCase(Flags, E.Name.str().c_str(),
132 static_cast<ProcSymFlags>(E.Value));
136 void ScalarBitSetTraits<FrameProcedureOptions>::bitset(
137 IO &io, FrameProcedureOptions &Flags) {
138 auto FlagNames = getFrameProcSymFlagNames();
139 for (const auto &E : FlagNames) {
140 io.bitSetCase(Flags, E.Name.str().c_str(),
141 static_cast<FrameProcedureOptions>(E.Value));
145 void ScalarEnumerationTraits<CPUType>::enumeration(IO &io, CPUType &Cpu) {
146 auto CpuNames = getCPUTypeNames();
147 for (const auto &E : CpuNames) {
148 io.enumCase(Cpu, E.Name.str().c_str(), static_cast<CPUType>(E.Value));
152 void ScalarEnumerationTraits<RegisterId>::enumeration(IO &io, RegisterId &Reg) {
153 const auto *Header = static_cast<COFF::header *>(io.getContext());
154 assert(Header && "The IO context is not initialized");
156 std::optional<CPUType> CpuType;
157 ArrayRef<EnumEntry<uint16_t>> RegNames;
159 switch (Header->Machine) {
160 case COFF::IMAGE_FILE_MACHINE_I386:
161 CpuType = CPUType::Pentium3;
162 break;
163 case COFF::IMAGE_FILE_MACHINE_AMD64:
164 CpuType = CPUType::X64;
165 break;
166 case COFF::IMAGE_FILE_MACHINE_ARMNT:
167 CpuType = CPUType::ARMNT;
168 break;
169 case COFF::IMAGE_FILE_MACHINE_ARM64:
170 case COFF::IMAGE_FILE_MACHINE_ARM64EC:
171 case COFF::IMAGE_FILE_MACHINE_ARM64X:
172 CpuType = CPUType::ARM64;
173 break;
176 if (CpuType)
177 RegNames = getRegisterNames(*CpuType);
179 for (const auto &E : RegNames) {
180 io.enumCase(Reg, E.Name.str().c_str(), static_cast<RegisterId>(E.Value));
182 io.enumFallback<Hex16>(Reg);
185 void ScalarEnumerationTraits<TrampolineType>::enumeration(
186 IO &io, TrampolineType &Tramp) {
187 auto TrampNames = getTrampolineNames();
188 for (const auto &E : TrampNames) {
189 io.enumCase(Tramp, E.Name.str().c_str(),
190 static_cast<TrampolineType>(E.Value));
194 void ScalarEnumerationTraits<ThunkOrdinal>::enumeration(IO &io,
195 ThunkOrdinal &Ord) {
196 auto ThunkNames = getThunkOrdinalNames();
197 for (const auto &E : ThunkNames) {
198 io.enumCase(Ord, E.Name.str().c_str(), static_cast<ThunkOrdinal>(E.Value));
202 void ScalarEnumerationTraits<FrameCookieKind>::enumeration(
203 IO &io, FrameCookieKind &FC) {
204 auto ThunkNames = getFrameCookieKindNames();
205 for (const auto &E : ThunkNames) {
206 io.enumCase(FC, E.Name.str().c_str(),
207 static_cast<FrameCookieKind>(E.Value));
211 void ScalarEnumerationTraits<JumpTableEntrySize>::enumeration(
212 IO &io, JumpTableEntrySize &FC) {
213 auto ThunkNames = getJumpTableEntrySizeNames();
214 for (const auto &E : ThunkNames) {
215 io.enumCase(FC, E.Name.str().c_str(),
216 static_cast<JumpTableEntrySize>(E.Value));
220 namespace llvm {
221 namespace yaml {
222 template <> struct MappingTraits<LocalVariableAddrRange> {
223 static void mapping(IO &io, LocalVariableAddrRange &Range) {
224 io.mapRequired("OffsetStart", Range.OffsetStart);
225 io.mapRequired("ISectStart", Range.ISectStart);
226 io.mapRequired("Range", Range.Range);
229 template <> struct MappingTraits<LocalVariableAddrGap> {
230 static void mapping(IO &io, LocalVariableAddrGap &Gap) {
231 io.mapRequired("GapStartOffset", Gap.GapStartOffset);
232 io.mapRequired("Range", Gap.Range);
235 } // namespace yaml
236 } // namespace llvm
238 namespace llvm {
239 namespace CodeViewYAML {
240 namespace detail {
242 struct SymbolRecordBase {
243 codeview::SymbolKind Kind;
245 explicit SymbolRecordBase(codeview::SymbolKind K) : Kind(K) {}
246 virtual ~SymbolRecordBase() = default;
248 virtual void map(yaml::IO &io) = 0;
249 virtual codeview::CVSymbol
250 toCodeViewSymbol(BumpPtrAllocator &Allocator,
251 CodeViewContainer Container) const = 0;
252 virtual Error fromCodeViewSymbol(codeview::CVSymbol Type) = 0;
255 template <typename T> struct SymbolRecordImpl : public SymbolRecordBase {
256 explicit SymbolRecordImpl(codeview::SymbolKind K)
257 : SymbolRecordBase(K), Symbol(static_cast<SymbolRecordKind>(K)) {}
259 void map(yaml::IO &io) override;
261 codeview::CVSymbol
262 toCodeViewSymbol(BumpPtrAllocator &Allocator,
263 CodeViewContainer Container) const override {
264 return SymbolSerializer::writeOneSymbol(Symbol, Allocator, Container);
267 Error fromCodeViewSymbol(codeview::CVSymbol CVS) override {
268 return SymbolDeserializer::deserializeAs<T>(CVS, Symbol);
271 mutable T Symbol;
274 struct UnknownSymbolRecord : public SymbolRecordBase {
275 explicit UnknownSymbolRecord(codeview::SymbolKind K) : SymbolRecordBase(K) {}
277 void map(yaml::IO &io) override;
279 CVSymbol toCodeViewSymbol(BumpPtrAllocator &Allocator,
280 CodeViewContainer Container) const override {
281 RecordPrefix Prefix;
282 uint32_t TotalLen = sizeof(RecordPrefix) + Data.size();
283 Prefix.RecordKind = Kind;
284 Prefix.RecordLen = TotalLen - 2;
285 uint8_t *Buffer = Allocator.Allocate<uint8_t>(TotalLen);
286 ::memcpy(Buffer, &Prefix, sizeof(RecordPrefix));
287 ::memcpy(Buffer + sizeof(RecordPrefix), Data.data(), Data.size());
288 return CVSymbol(ArrayRef<uint8_t>(Buffer, TotalLen));
291 Error fromCodeViewSymbol(CVSymbol CVS) override {
292 this->Kind = CVS.kind();
293 Data = CVS.RecordData.drop_front(sizeof(RecordPrefix));
294 return Error::success();
297 std::vector<uint8_t> Data;
300 template <> void SymbolRecordImpl<ScopeEndSym>::map(IO &IO) {}
302 void UnknownSymbolRecord::map(yaml::IO &io) {
303 yaml::BinaryRef Binary;
304 if (io.outputting())
305 Binary = yaml::BinaryRef(Data);
306 io.mapRequired("Data", Binary);
307 if (!io.outputting()) {
308 std::string Str;
309 raw_string_ostream OS(Str);
310 Binary.writeAsBinary(OS);
311 Data.assign(Str.begin(), Str.end());
315 template <> void SymbolRecordImpl<Thunk32Sym>::map(IO &IO) {
316 IO.mapRequired("Parent", Symbol.Parent);
317 IO.mapRequired("End", Symbol.End);
318 IO.mapRequired("Next", Symbol.Next);
319 IO.mapRequired("Off", Symbol.Offset);
320 IO.mapRequired("Seg", Symbol.Segment);
321 IO.mapRequired("Len", Symbol.Length);
322 IO.mapRequired("Ordinal", Symbol.Thunk);
325 template <> void SymbolRecordImpl<TrampolineSym>::map(IO &IO) {
326 IO.mapRequired("Type", Symbol.Type);
327 IO.mapRequired("Size", Symbol.Size);
328 IO.mapRequired("ThunkOff", Symbol.ThunkOffset);
329 IO.mapRequired("TargetOff", Symbol.TargetOffset);
330 IO.mapRequired("ThunkSection", Symbol.ThunkSection);
331 IO.mapRequired("TargetSection", Symbol.TargetSection);
334 template <> void SymbolRecordImpl<SectionSym>::map(IO &IO) {
335 IO.mapRequired("SectionNumber", Symbol.SectionNumber);
336 IO.mapRequired("Alignment", Symbol.Alignment);
337 IO.mapRequired("Rva", Symbol.Rva);
338 IO.mapRequired("Length", Symbol.Length);
339 IO.mapRequired("Characteristics", Symbol.Characteristics);
340 IO.mapRequired("Name", Symbol.Name);
343 template <> void SymbolRecordImpl<CoffGroupSym>::map(IO &IO) {
344 IO.mapRequired("Size", Symbol.Size);
345 IO.mapRequired("Characteristics", Symbol.Characteristics);
346 IO.mapRequired("Offset", Symbol.Offset);
347 IO.mapRequired("Segment", Symbol.Segment);
348 IO.mapRequired("Name", Symbol.Name);
351 template <> void SymbolRecordImpl<ExportSym>::map(IO &IO) {
352 IO.mapRequired("Ordinal", Symbol.Ordinal);
353 IO.mapRequired("Flags", Symbol.Flags);
354 IO.mapRequired("Name", Symbol.Name);
357 template <> void SymbolRecordImpl<ProcSym>::map(IO &IO) {
358 IO.mapOptional("PtrParent", Symbol.Parent, 0U);
359 IO.mapOptional("PtrEnd", Symbol.End, 0U);
360 IO.mapOptional("PtrNext", Symbol.Next, 0U);
361 IO.mapRequired("CodeSize", Symbol.CodeSize);
362 IO.mapRequired("DbgStart", Symbol.DbgStart);
363 IO.mapRequired("DbgEnd", Symbol.DbgEnd);
364 IO.mapRequired("FunctionType", Symbol.FunctionType);
365 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
366 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
367 IO.mapRequired("Flags", Symbol.Flags);
368 IO.mapRequired("DisplayName", Symbol.Name);
371 template <> void SymbolRecordImpl<RegisterSym>::map(IO &IO) {
372 IO.mapRequired("Type", Symbol.Index);
373 IO.mapRequired("Seg", Symbol.Register);
374 IO.mapRequired("Name", Symbol.Name);
377 template <> void SymbolRecordImpl<PublicSym32>::map(IO &IO) {
378 IO.mapRequired("Flags", Symbol.Flags);
379 IO.mapOptional("Offset", Symbol.Offset, 0U);
380 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
381 IO.mapRequired("Name", Symbol.Name);
384 template <> void SymbolRecordImpl<ProcRefSym>::map(IO &IO) {
385 IO.mapRequired("SumName", Symbol.SumName);
386 IO.mapRequired("SymOffset", Symbol.SymOffset);
387 IO.mapRequired("Mod", Symbol.Module);
388 IO.mapRequired("Name", Symbol.Name);
391 template <> void SymbolRecordImpl<EnvBlockSym>::map(IO &IO) {
392 IO.mapRequired("Entries", Symbol.Fields);
395 template <> void SymbolRecordImpl<InlineSiteSym>::map(IO &IO) {
396 IO.mapOptional("PtrParent", Symbol.Parent, 0U);
397 IO.mapOptional("PtrEnd", Symbol.End, 0U);
398 IO.mapRequired("Inlinee", Symbol.Inlinee);
399 // TODO: The binary annotations
402 template <> void SymbolRecordImpl<LocalSym>::map(IO &IO) {
403 IO.mapRequired("Type", Symbol.Type);
404 IO.mapRequired("Flags", Symbol.Flags);
406 IO.mapRequired("VarName", Symbol.Name);
409 template <> void SymbolRecordImpl<DefRangeSym>::map(IO &IO) {
410 IO.mapRequired("Program", Symbol.Program);
411 IO.mapRequired("Range", Symbol.Range);
412 IO.mapRequired("Gaps", Symbol.Gaps);
415 template <> void SymbolRecordImpl<DefRangeSubfieldSym>::map(IO &IO) {
416 IO.mapRequired("Program", Symbol.Program);
417 IO.mapRequired("OffsetInParent", Symbol.OffsetInParent);
418 IO.mapRequired("Range", Symbol.Range);
419 IO.mapRequired("Gaps", Symbol.Gaps);
422 template <> void SymbolRecordImpl<DefRangeRegisterSym>::map(IO &IO) {
423 IO.mapRequired("Register", Symbol.Hdr.Register);
424 IO.mapRequired("MayHaveNoName", Symbol.Hdr.MayHaveNoName);
425 IO.mapRequired("Range", Symbol.Range);
426 IO.mapRequired("Gaps", Symbol.Gaps);
429 template <> void SymbolRecordImpl<DefRangeFramePointerRelSym>::map(IO &IO) {
430 IO.mapRequired("Offset", Symbol.Hdr.Offset);
431 IO.mapRequired("Range", Symbol.Range);
432 IO.mapRequired("Gaps", Symbol.Gaps);
435 template <> void SymbolRecordImpl<DefRangeSubfieldRegisterSym>::map(IO &IO) {
436 IO.mapRequired("Register", Symbol.Hdr.Register);
437 IO.mapRequired("MayHaveNoName", Symbol.Hdr.MayHaveNoName);
438 IO.mapRequired("OffsetInParent", Symbol.Hdr.OffsetInParent);
439 IO.mapRequired("Range", Symbol.Range);
440 IO.mapRequired("Gaps", Symbol.Gaps);
443 template <>
444 void SymbolRecordImpl<DefRangeFramePointerRelFullScopeSym>::map(IO &IO) {
445 IO.mapRequired("Register", Symbol.Offset);
448 template <> void SymbolRecordImpl<DefRangeRegisterRelSym>::map(IO &IO) {
449 IO.mapRequired("Register", Symbol.Hdr.Register);
450 IO.mapRequired("Flags", Symbol.Hdr.Flags);
451 IO.mapRequired("BasePointerOffset", Symbol.Hdr.BasePointerOffset);
452 IO.mapRequired("Range", Symbol.Range);
453 IO.mapRequired("Gaps", Symbol.Gaps);
456 template <> void SymbolRecordImpl<BlockSym>::map(IO &IO) {
457 IO.mapOptional("PtrParent", Symbol.Parent, 0U);
458 IO.mapOptional("PtrEnd", Symbol.End, 0U);
459 IO.mapRequired("CodeSize", Symbol.CodeSize);
460 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
461 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
462 IO.mapRequired("BlockName", Symbol.Name);
465 template <> void SymbolRecordImpl<LabelSym>::map(IO &IO) {
466 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
467 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
468 IO.mapRequired("Flags", Symbol.Flags);
469 IO.mapRequired("DisplayName", Symbol.Name);
472 template <> void SymbolRecordImpl<ObjNameSym>::map(IO &IO) {
473 IO.mapRequired("Signature", Symbol.Signature);
474 IO.mapRequired("ObjectName", Symbol.Name);
477 template <> void SymbolRecordImpl<Compile2Sym>::map(IO &IO) {
478 IO.mapRequired("Flags", Symbol.Flags);
479 IO.mapRequired("Machine", Symbol.Machine);
480 IO.mapRequired("FrontendMajor", Symbol.VersionFrontendMajor);
481 IO.mapRequired("FrontendMinor", Symbol.VersionFrontendMinor);
482 IO.mapRequired("FrontendBuild", Symbol.VersionFrontendBuild);
483 IO.mapRequired("BackendMajor", Symbol.VersionBackendMajor);
484 IO.mapRequired("BackendMinor", Symbol.VersionBackendMinor);
485 IO.mapRequired("BackendBuild", Symbol.VersionBackendBuild);
486 IO.mapRequired("Version", Symbol.Version);
489 template <> void SymbolRecordImpl<Compile3Sym>::map(IO &IO) {
490 IO.mapRequired("Flags", Symbol.Flags);
491 IO.mapRequired("Machine", Symbol.Machine);
492 IO.mapRequired("FrontendMajor", Symbol.VersionFrontendMajor);
493 IO.mapRequired("FrontendMinor", Symbol.VersionFrontendMinor);
494 IO.mapRequired("FrontendBuild", Symbol.VersionFrontendBuild);
495 IO.mapRequired("FrontendQFE", Symbol.VersionFrontendQFE);
496 IO.mapRequired("BackendMajor", Symbol.VersionBackendMajor);
497 IO.mapRequired("BackendMinor", Symbol.VersionBackendMinor);
498 IO.mapRequired("BackendBuild", Symbol.VersionBackendBuild);
499 IO.mapRequired("BackendQFE", Symbol.VersionBackendQFE);
500 IO.mapRequired("Version", Symbol.Version);
503 template <> void SymbolRecordImpl<FrameProcSym>::map(IO &IO) {
504 IO.mapRequired("TotalFrameBytes", Symbol.TotalFrameBytes);
505 IO.mapRequired("PaddingFrameBytes", Symbol.PaddingFrameBytes);
506 IO.mapRequired("OffsetToPadding", Symbol.OffsetToPadding);
507 IO.mapRequired("BytesOfCalleeSavedRegisters",
508 Symbol.BytesOfCalleeSavedRegisters);
509 IO.mapRequired("OffsetOfExceptionHandler", Symbol.OffsetOfExceptionHandler);
510 IO.mapRequired("SectionIdOfExceptionHandler",
511 Symbol.SectionIdOfExceptionHandler);
512 IO.mapRequired("Flags", Symbol.Flags);
515 template <> void SymbolRecordImpl<CallSiteInfoSym>::map(IO &IO) {
516 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
517 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
518 IO.mapRequired("Type", Symbol.Type);
521 template <> void SymbolRecordImpl<FileStaticSym>::map(IO &IO) {
522 IO.mapRequired("Index", Symbol.Index);
523 IO.mapRequired("ModFilenameOffset", Symbol.ModFilenameOffset);
524 IO.mapRequired("Flags", Symbol.Flags);
525 IO.mapRequired("Name", Symbol.Name);
528 template <> void SymbolRecordImpl<HeapAllocationSiteSym>::map(IO &IO) {
529 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
530 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
531 IO.mapRequired("CallInstructionSize", Symbol.CallInstructionSize);
532 IO.mapRequired("Type", Symbol.Type);
535 template <> void SymbolRecordImpl<FrameCookieSym>::map(IO &IO) {
536 IO.mapRequired("Register", Symbol.Register);
537 IO.mapRequired("CookieKind", Symbol.CookieKind);
538 IO.mapRequired("Flags", Symbol.Flags);
541 template <> void SymbolRecordImpl<CallerSym>::map(IO &IO) {
542 IO.mapRequired("FuncID", Symbol.Indices);
545 template <> void SymbolRecordImpl<UDTSym>::map(IO &IO) {
546 IO.mapRequired("Type", Symbol.Type);
547 IO.mapRequired("UDTName", Symbol.Name);
550 template <> void SymbolRecordImpl<BuildInfoSym>::map(IO &IO) {
551 IO.mapRequired("BuildId", Symbol.BuildId);
554 template <> void SymbolRecordImpl<BPRelativeSym>::map(IO &IO) {
555 IO.mapRequired("Offset", Symbol.Offset);
556 IO.mapRequired("Type", Symbol.Type);
557 IO.mapRequired("VarName", Symbol.Name);
560 template <> void SymbolRecordImpl<RegRelativeSym>::map(IO &IO) {
561 IO.mapRequired("Offset", Symbol.Offset);
562 IO.mapRequired("Type", Symbol.Type);
563 IO.mapRequired("Register", Symbol.Register);
564 IO.mapRequired("VarName", Symbol.Name);
567 template <> void SymbolRecordImpl<ConstantSym>::map(IO &IO) {
568 IO.mapRequired("Type", Symbol.Type);
569 IO.mapRequired("Value", Symbol.Value);
570 IO.mapRequired("Name", Symbol.Name);
573 template <> void SymbolRecordImpl<DataSym>::map(IO &IO) {
574 IO.mapRequired("Type", Symbol.Type);
575 IO.mapOptional("Offset", Symbol.DataOffset, 0U);
576 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
577 IO.mapRequired("DisplayName", Symbol.Name);
580 template <> void SymbolRecordImpl<ThreadLocalDataSym>::map(IO &IO) {
581 IO.mapRequired("Type", Symbol.Type);
582 IO.mapOptional("Offset", Symbol.DataOffset, 0U);
583 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
584 IO.mapRequired("DisplayName", Symbol.Name);
587 template <> void SymbolRecordImpl<UsingNamespaceSym>::map(IO &IO) {
588 IO.mapRequired("Namespace", Symbol.Name);
591 template <> void SymbolRecordImpl<AnnotationSym>::map(IO &IO) {
592 IO.mapOptional("Offset", Symbol.CodeOffset, 0U);
593 IO.mapOptional("Segment", Symbol.Segment, uint16_t(0));
594 IO.mapRequired("Strings", Symbol.Strings);
597 template <> void SymbolRecordImpl<JumpTableSym>::map(IO &IO) {
598 IO.mapRequired("BaseOffset", Symbol.BaseOffset);
599 IO.mapRequired("BaseSegment", Symbol.BaseSegment);
600 IO.mapRequired("SwitchType", Symbol.SwitchType);
601 IO.mapRequired("BranchOffset", Symbol.BranchOffset);
602 IO.mapRequired("TableOffset", Symbol.TableOffset);
603 IO.mapRequired("BranchSegment", Symbol.BranchSegment);
604 IO.mapRequired("TableSegment", Symbol.TableSegment);
605 IO.mapRequired("EntriesCount", Symbol.EntriesCount);
608 } // end namespace detail
609 } // end namespace CodeViewYAML
610 } // end namespace llvm
612 CVSymbol CodeViewYAML::SymbolRecord::toCodeViewSymbol(
613 BumpPtrAllocator &Allocator, CodeViewContainer Container) const {
614 return Symbol->toCodeViewSymbol(Allocator, Container);
617 namespace llvm {
618 namespace yaml {
620 template <> struct MappingTraits<SymbolRecordBase> {
621 static void mapping(IO &io, SymbolRecordBase &Record) { Record.map(io); }
624 } // end namespace yaml
625 } // end namespace llvm
627 template <typename SymbolType>
628 static inline Expected<CodeViewYAML::SymbolRecord>
629 fromCodeViewSymbolImpl(CVSymbol Symbol) {
630 CodeViewYAML::SymbolRecord Result;
632 auto Impl = std::make_shared<SymbolType>(Symbol.kind());
633 if (auto EC = Impl->fromCodeViewSymbol(Symbol))
634 return std::move(EC);
635 Result.Symbol = Impl;
636 return Result;
639 Expected<CodeViewYAML::SymbolRecord>
640 CodeViewYAML::SymbolRecord::fromCodeViewSymbol(CVSymbol Symbol) {
641 #define SYMBOL_RECORD(EnumName, EnumVal, ClassName) \
642 case EnumName: \
643 return fromCodeViewSymbolImpl<SymbolRecordImpl<ClassName>>(Symbol);
644 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
645 SYMBOL_RECORD(EnumName, EnumVal, ClassName)
646 switch (Symbol.kind()) {
647 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
648 default:
649 return fromCodeViewSymbolImpl<UnknownSymbolRecord>(Symbol);
651 return make_error<CodeViewError>(cv_error_code::corrupt_record);
654 template <typename ConcreteType>
655 static void mapSymbolRecordImpl(IO &IO, const char *Class, SymbolKind Kind,
656 CodeViewYAML::SymbolRecord &Obj) {
657 if (!IO.outputting())
658 Obj.Symbol = std::make_shared<ConcreteType>(Kind);
660 IO.mapRequired(Class, *Obj.Symbol);
663 void MappingTraits<CodeViewYAML::SymbolRecord>::mapping(
664 IO &IO, CodeViewYAML::SymbolRecord &Obj) {
665 SymbolKind Kind;
666 if (IO.outputting())
667 Kind = Obj.Symbol->Kind;
668 IO.mapRequired("Kind", Kind);
670 #define SYMBOL_RECORD(EnumName, EnumVal, ClassName) \
671 case EnumName: \
672 mapSymbolRecordImpl<SymbolRecordImpl<ClassName>>(IO, #ClassName, Kind, \
673 Obj); \
674 break;
675 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
676 SYMBOL_RECORD(EnumName, EnumVal, ClassName)
677 switch (Kind) {
678 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
679 default:
680 mapSymbolRecordImpl<UnknownSymbolRecord>(IO, "UnknownSym", Kind, Obj);