LLVM  6.0.0svn
CodeViewYAMLTypes.cpp
Go to the documentation of this file.
1 //===- CodeViewYAMLTypes.cpp - CodeView YAMLIO types implementation -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines classes for handling the YAML representation of CodeView
11 // Debug Info.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/APSInt.h"
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/BinaryFormat/COFF.h"
27 #include "llvm/Support/Allocator.h"
30 #include "llvm/Support/Endian.h"
31 #include "llvm/Support/Error.h"
35 #include <algorithm>
36 #include <cassert>
37 #include <cstdint>
38 #include <vector>
39 
40 using namespace llvm;
41 using namespace llvm::codeview;
42 using namespace llvm::CodeViewYAML;
43 using namespace llvm::CodeViewYAML::detail;
44 using namespace llvm::yaml;
45 
49 
52 
64 
70 
73 
74 namespace llvm {
75 namespace CodeViewYAML {
76 namespace detail {
77 
80 
81  explicit LeafRecordBase(TypeLeafKind K) : Kind(K) {}
82  virtual ~LeafRecordBase() = default;
83 
84  virtual void map(yaml::IO &io) = 0;
85  virtual CVType toCodeViewRecord(TypeTableBuilder &TTB) const = 0;
86  virtual Error fromCodeViewRecord(CVType Type) = 0;
87 };
88 
89 template <typename T> struct LeafRecordImpl : public LeafRecordBase {
91  : LeafRecordBase(K), Record(static_cast<TypeRecordKind>(K)) {}
92 
93  void map(yaml::IO &io) override;
94 
96  return TypeDeserializer::deserializeAs<T>(Type, Record);
97  }
98 
99  CVType toCodeViewRecord(TypeTableBuilder &TTB) const override {
100  TTB.writeKnownType(Record);
101  return CVType(Kind, TTB.records().back());
102  }
103 
104  mutable T Record;
105 };
106 
107 template <> struct LeafRecordImpl<FieldListRecord> : public LeafRecordBase {
109 
110  void map(yaml::IO &io) override;
111  CVType toCodeViewRecord(TypeTableBuilder &TTB) const override;
112  Error fromCodeViewRecord(CVType Type) override;
113 
114  std::vector<MemberRecord> Members;
115 };
116 
119 
120  explicit MemberRecordBase(TypeLeafKind K) : Kind(K) {}
121  virtual ~MemberRecordBase() = default;
122 
123  virtual void map(yaml::IO &io) = 0;
124  virtual void writeTo(FieldListRecordBuilder &FLRB) = 0;
125 };
126 
127 template <typename T> struct MemberRecordImpl : public MemberRecordBase {
129  : MemberRecordBase(K), Record(static_cast<TypeRecordKind>(K)) {}
130 
131  void map(yaml::IO &io) override;
132 
133  void writeTo(FieldListRecordBuilder &FLRB) override {
134  FLRB.writeMemberType(Record);
135  }
136 
137  mutable T Record;
138 };
139 
140 } // end namespace detail
141 } // end namespace CodeViewYAML
142 } // end namespace llvm
143 
144 void ScalarTraits<GUID>::output(const GUID &G, void *, llvm::raw_ostream &OS) {
145  OS << G;
146 }
147 
149  if (Scalar.size() != 38)
150  return "GUID strings are 38 characters long";
151  if (Scalar[0] != '{' || Scalar[37] != '}')
152  return "GUID is not enclosed in {}";
153  if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' ||
154  Scalar[24] != '-')
155  return "GUID sections are not properly delineated with dashes";
156 
157  uint8_t *OutBuffer = S.Guid;
158  for (auto Iter = Scalar.begin(); Iter != Scalar.end();) {
159  if (*Iter == '-' || *Iter == '{' || *Iter == '}') {
160  ++Iter;
161  continue;
162  }
163  uint8_t Value = (llvm::hexDigitValue(*Iter++) << 4);
164  Value |= llvm::hexDigitValue(*Iter++);
165  *OutBuffer++ = Value;
166  }
167 
168  return "";
169 }
170 
171 void ScalarTraits<TypeIndex>::output(const TypeIndex &S, void *,
172  raw_ostream &OS) {
173  OS << S.getIndex();
174 }
175 
177  TypeIndex &S) {
178  uint32_t I;
179  StringRef Result = ScalarTraits<uint32_t>::input(Scalar, Ctx, I);
180  S.setIndex(I);
181  return Result;
182 }
183 
184 void ScalarTraits<APSInt>::output(const APSInt &S, void *, raw_ostream &OS) {
185  S.print(OS, S.isSigned());
186 }
187 
188 StringRef ScalarTraits<APSInt>::input(StringRef Scalar, void *Ctx, APSInt &S) {
189  S = APSInt(Scalar);
190  return "";
191 }
192 
194  TypeLeafKind &Value) {
195 #define CV_TYPE(name, val) io.enumCase(Value, #name, name);
196 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
197 #undef CV_TYPE
198 }
199 
202  IO.enumCase(Value, "Unknown", PointerToMemberRepresentation::Unknown);
203  IO.enumCase(Value, "SingleInheritanceData",
205  IO.enumCase(Value, "MultipleInheritanceData",
207  IO.enumCase(Value, "VirtualInheritanceData",
209  IO.enumCase(Value, "GeneralData", PointerToMemberRepresentation::GeneralData);
210  IO.enumCase(Value, "SingleInheritanceFunction",
212  IO.enumCase(Value, "MultipleInheritanceFunction",
214  IO.enumCase(Value, "VirtualInheritanceFunction",
216  IO.enumCase(Value, "GeneralFunction",
218 }
219 
221  IO &IO, VFTableSlotKind &Kind) {
222  IO.enumCase(Kind, "Near16", VFTableSlotKind::Near16);
223  IO.enumCase(Kind, "Far16", VFTableSlotKind::Far16);
224  IO.enumCase(Kind, "This", VFTableSlotKind::This);
225  IO.enumCase(Kind, "Outer", VFTableSlotKind::Outer);
226  IO.enumCase(Kind, "Meta", VFTableSlotKind::Meta);
227  IO.enumCase(Kind, "Near", VFTableSlotKind::Near);
228  IO.enumCase(Kind, "Far", VFTableSlotKind::Far);
229 }
230 
232  IO &IO, CallingConvention &Value) {
233  IO.enumCase(Value, "NearC", CallingConvention::NearC);
234  IO.enumCase(Value, "FarC", CallingConvention::FarC);
235  IO.enumCase(Value, "NearPascal", CallingConvention::NearPascal);
236  IO.enumCase(Value, "FarPascal", CallingConvention::FarPascal);
237  IO.enumCase(Value, "NearFast", CallingConvention::NearFast);
238  IO.enumCase(Value, "FarFast", CallingConvention::FarFast);
239  IO.enumCase(Value, "NearStdCall", CallingConvention::NearStdCall);
240  IO.enumCase(Value, "FarStdCall", CallingConvention::FarStdCall);
241  IO.enumCase(Value, "NearSysCall", CallingConvention::NearSysCall);
242  IO.enumCase(Value, "FarSysCall", CallingConvention::FarSysCall);
243  IO.enumCase(Value, "ThisCall", CallingConvention::ThisCall);
244  IO.enumCase(Value, "MipsCall", CallingConvention::MipsCall);
245  IO.enumCase(Value, "Generic", CallingConvention::Generic);
246  IO.enumCase(Value, "AlphaCall", CallingConvention::AlphaCall);
247  IO.enumCase(Value, "PpcCall", CallingConvention::PpcCall);
248  IO.enumCase(Value, "SHCall", CallingConvention::SHCall);
249  IO.enumCase(Value, "ArmCall", CallingConvention::ArmCall);
250  IO.enumCase(Value, "AM33Call", CallingConvention::AM33Call);
251  IO.enumCase(Value, "TriCall", CallingConvention::TriCall);
252  IO.enumCase(Value, "SH5Call", CallingConvention::SH5Call);
253  IO.enumCase(Value, "M32RCall", CallingConvention::M32RCall);
254  IO.enumCase(Value, "ClrCall", CallingConvention::ClrCall);
255  IO.enumCase(Value, "Inline", CallingConvention::Inline);
256  IO.enumCase(Value, "NearVector", CallingConvention::NearVector);
257 }
258 
260  PointerKind &Kind) {
261  IO.enumCase(Kind, "Near16", PointerKind::Near16);
262  IO.enumCase(Kind, "Far16", PointerKind::Far16);
263  IO.enumCase(Kind, "Huge16", PointerKind::Huge16);
264  IO.enumCase(Kind, "BasedOnSegment", PointerKind::BasedOnSegment);
265  IO.enumCase(Kind, "BasedOnValue", PointerKind::BasedOnValue);
266  IO.enumCase(Kind, "BasedOnSegmentValue", PointerKind::BasedOnSegmentValue);
267  IO.enumCase(Kind, "BasedOnAddress", PointerKind::BasedOnAddress);
268  IO.enumCase(Kind, "BasedOnSegmentAddress",
270  IO.enumCase(Kind, "BasedOnType", PointerKind::BasedOnType);
271  IO.enumCase(Kind, "BasedOnSelf", PointerKind::BasedOnSelf);
272  IO.enumCase(Kind, "Near32", PointerKind::Near32);
273  IO.enumCase(Kind, "Far32", PointerKind::Far32);
274  IO.enumCase(Kind, "Near64", PointerKind::Near64);
275 }
276 
278  PointerMode &Mode) {
279  IO.enumCase(Mode, "Pointer", PointerMode::Pointer);
280  IO.enumCase(Mode, "LValueReference", PointerMode::LValueReference);
281  IO.enumCase(Mode, "PointerToDataMember", PointerMode::PointerToDataMember);
282  IO.enumCase(Mode, "PointerToMemberFunction",
284  IO.enumCase(Mode, "RValueReference", PointerMode::RValueReference);
285 }
286 
288  IO.enumCase(Value, "None", HfaKind::None);
289  IO.enumCase(Value, "Float", HfaKind::Float);
290  IO.enumCase(Value, "Double", HfaKind::Double);
291  IO.enumCase(Value, "Other", HfaKind::Other);
292 }
293 
295  MemberAccess &Access) {
296  IO.enumCase(Access, "None", MemberAccess::None);
297  IO.enumCase(Access, "Private", MemberAccess::Private);
298  IO.enumCase(Access, "Protected", MemberAccess::Protected);
299  IO.enumCase(Access, "Public", MemberAccess::Public);
300 }
301 
303  MethodKind &Kind) {
304  IO.enumCase(Kind, "Vanilla", MethodKind::Vanilla);
305  IO.enumCase(Kind, "Virtual", MethodKind::Virtual);
306  IO.enumCase(Kind, "Static", MethodKind::Static);
307  IO.enumCase(Kind, "Friend", MethodKind::Friend);
308  IO.enumCase(Kind, "IntroducingVirtual", MethodKind::IntroducingVirtual);
309  IO.enumCase(Kind, "PureVirtual", MethodKind::PureVirtual);
310  IO.enumCase(Kind, "PureIntroducingVirtual",
312 }
313 
315  IO &IO, WindowsRTClassKind &Value) {
316  IO.enumCase(Value, "None", WindowsRTClassKind::None);
317  IO.enumCase(Value, "Ref", WindowsRTClassKind::RefClass);
318  IO.enumCase(Value, "Value", WindowsRTClassKind::ValueClass);
319  IO.enumCase(Value, "Interface", WindowsRTClassKind::Interface);
320 }
321 
323  IO.enumCase(Value, "Near", LabelType::Near);
324  IO.enumCase(Value, "Far", LabelType::Far);
325 }
326 
328  PointerOptions &Options) {
329  IO.bitSetCase(Options, "None", PointerOptions::None);
330  IO.bitSetCase(Options, "Flat32", PointerOptions::Flat32);
331  IO.bitSetCase(Options, "Volatile", PointerOptions::Volatile);
332  IO.bitSetCase(Options, "Const", PointerOptions::Const);
333  IO.bitSetCase(Options, "Unaligned", PointerOptions::Unaligned);
334  IO.bitSetCase(Options, "Restrict", PointerOptions::Restrict);
335  IO.bitSetCase(Options, "WinRTSmartPointer",
337 }
338 
340  ModifierOptions &Options) {
341  IO.bitSetCase(Options, "None", ModifierOptions::None);
342  IO.bitSetCase(Options, "Const", ModifierOptions::Const);
343  IO.bitSetCase(Options, "Volatile", ModifierOptions::Volatile);
344  IO.bitSetCase(Options, "Unaligned", ModifierOptions::Unaligned);
345 }
346 
348  FunctionOptions &Options) {
349  IO.bitSetCase(Options, "None", FunctionOptions::None);
350  IO.bitSetCase(Options, "CxxReturnUdt", FunctionOptions::CxxReturnUdt);
351  IO.bitSetCase(Options, "Constructor", FunctionOptions::Constructor);
352  IO.bitSetCase(Options, "ConstructorWithVirtualBases",
354 }
355 
357  IO.bitSetCase(Options, "None", ClassOptions::None);
358  IO.bitSetCase(Options, "HasConstructorOrDestructor",
360  IO.bitSetCase(Options, "HasOverloadedOperator",
362  IO.bitSetCase(Options, "Nested", ClassOptions::Nested);
363  IO.bitSetCase(Options, "ContainsNestedClass",
365  IO.bitSetCase(Options, "HasOverloadedAssignmentOperator",
367  IO.bitSetCase(Options, "HasConversionOperator",
369  IO.bitSetCase(Options, "ForwardReference", ClassOptions::ForwardReference);
370  IO.bitSetCase(Options, "Scoped", ClassOptions::Scoped);
371  IO.bitSetCase(Options, "HasUniqueName", ClassOptions::HasUniqueName);
372  IO.bitSetCase(Options, "Sealed", ClassOptions::Sealed);
373  IO.bitSetCase(Options, "Intrinsic", ClassOptions::Intrinsic);
374 }
375 
377  IO.bitSetCase(Options, "None", MethodOptions::None);
378  IO.bitSetCase(Options, "Pseudo", MethodOptions::Pseudo);
379  IO.bitSetCase(Options, "NoInherit", MethodOptions::NoInherit);
380  IO.bitSetCase(Options, "NoConstruct", MethodOptions::NoConstruct);
381  IO.bitSetCase(Options, "CompilerGenerated", MethodOptions::CompilerGenerated);
382  IO.bitSetCase(Options, "Sealed", MethodOptions::Sealed);
383 }
384 
386  IO.mapRequired("ContainingType", MPI.ContainingType);
387  IO.mapRequired("Representation", MPI.Representation);
388 }
389 
390 namespace llvm {
391 namespace CodeViewYAML {
392 namespace detail {
393 
394 template <> void LeafRecordImpl<ModifierRecord>::map(IO &IO) {
395  IO.mapRequired("ModifiedType", Record.ModifiedType);
396  IO.mapRequired("Modifiers", Record.Modifiers);
397 }
398 
399 template <> void LeafRecordImpl<ProcedureRecord>::map(IO &IO) {
400  IO.mapRequired("ReturnType", Record.ReturnType);
401  IO.mapRequired("CallConv", Record.CallConv);
402  IO.mapRequired("Options", Record.Options);
403  IO.mapRequired("ParameterCount", Record.ParameterCount);
404  IO.mapRequired("ArgumentList", Record.ArgumentList);
405 }
406 
408  IO.mapRequired("ReturnType", Record.ReturnType);
409  IO.mapRequired("ClassType", Record.ClassType);
410  IO.mapRequired("ThisType", Record.ThisType);
411  IO.mapRequired("CallConv", Record.CallConv);
412  IO.mapRequired("Options", Record.Options);
413  IO.mapRequired("ParameterCount", Record.ParameterCount);
414  IO.mapRequired("ArgumentList", Record.ArgumentList);
415  IO.mapRequired("ThisPointerAdjustment", Record.ThisPointerAdjustment);
416 }
417 
418 template <> void LeafRecordImpl<LabelRecord>::map(IO &IO) {
419  IO.mapRequired("Mode", Record.Mode);
420 }
421 
422 template <> void LeafRecordImpl<MemberFuncIdRecord>::map(IO &IO) {
423  IO.mapRequired("ClassType", Record.ClassType);
424  IO.mapRequired("FunctionType", Record.FunctionType);
425  IO.mapRequired("Name", Record.Name);
426 }
427 
428 template <> void LeafRecordImpl<ArgListRecord>::map(IO &IO) {
429  IO.mapRequired("ArgIndices", Record.ArgIndices);
430 }
431 
432 template <> void LeafRecordImpl<StringListRecord>::map(IO &IO) {
433  IO.mapRequired("StringIndices", Record.StringIndices);
434 }
435 
436 template <> void LeafRecordImpl<PointerRecord>::map(IO &IO) {
437  IO.mapRequired("ReferentType", Record.ReferentType);
438  IO.mapRequired("Attrs", Record.Attrs);
439  IO.mapOptional("MemberInfo", Record.MemberInfo);
440 }
441 
442 template <> void LeafRecordImpl<ArrayRecord>::map(IO &IO) {
443  IO.mapRequired("ElementType", Record.ElementType);
444  IO.mapRequired("IndexType", Record.IndexType);
445  IO.mapRequired("Size", Record.Size);
446  IO.mapRequired("Name", Record.Name);
447 }
448 
450  IO.mapRequired("FieldList", Members);
451 }
452 
453 } // end namespace detail
454 } // end namespace CodeViewYAML
455 } // end namespace llvm
456 
457 namespace {
458 
459 class MemberRecordConversionVisitor : public TypeVisitorCallbacks {
460 public:
461  explicit MemberRecordConversionVisitor(std::vector<MemberRecord> &Records)
462  : Records(Records) {}
463 
464 #define TYPE_RECORD(EnumName, EnumVal, Name)
465 #define MEMBER_RECORD(EnumName, EnumVal, Name) \
466  Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override { \
467  return visitKnownMemberImpl(Record); \
468  }
469 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
470 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
471 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
472 private:
473  template <typename T> Error visitKnownMemberImpl(T &Record) {
474  TypeLeafKind K = static_cast<TypeLeafKind>(Record.getKind());
475  auto Impl = std::make_shared<MemberRecordImpl<T>>(K);
476  Impl->Record = Record;
477  Records.push_back(MemberRecord{Impl});
478  return Error::success();
479  }
480 
481  std::vector<MemberRecord> &Records;
482 };
483 
484 } // end anonymous namespace
485 
487  MemberRecordConversionVisitor V(Members);
488  return visitMemberRecordStream(Type.content(), V);
489 }
490 
491 CVType
493  FieldListRecordBuilder FLRB(TTB);
494  FLRB.begin();
495  for (const auto &Member : Members) {
496  Member.Member->writeTo(FLRB);
497  }
498  FLRB.end(true);
499  return CVType(Kind, TTB.records().back());
500 }
501 
503  io.mapRequired("Type", Record.Type);
504  io.mapRequired("Attrs", Record.Attrs.Attrs);
505  io.mapRequired("VFTableOffset", Record.VFTableOffset);
506  io.mapRequired("Name", Record.Name);
507 }
508 
509 namespace llvm {
510 namespace CodeViewYAML {
511 namespace detail {
512 
513 template <> void LeafRecordImpl<ClassRecord>::map(IO &IO) {
514  IO.mapRequired("MemberCount", Record.MemberCount);
515  IO.mapRequired("Options", Record.Options);
516  IO.mapRequired("FieldList", Record.FieldList);
517  IO.mapRequired("Name", Record.Name);
518  IO.mapRequired("UniqueName", Record.UniqueName);
519  IO.mapRequired("DerivationList", Record.DerivationList);
520  IO.mapRequired("VTableShape", Record.VTableShape);
521  IO.mapRequired("Size", Record.Size);
522 }
523 
524 template <> void LeafRecordImpl<UnionRecord>::map(IO &IO) {
525  IO.mapRequired("MemberCount", Record.MemberCount);
526  IO.mapRequired("Options", Record.Options);
527  IO.mapRequired("FieldList", Record.FieldList);
528  IO.mapRequired("Name", Record.Name);
529  IO.mapRequired("UniqueName", Record.UniqueName);
530  IO.mapRequired("Size", Record.Size);
531 }
532 
533 template <> void LeafRecordImpl<EnumRecord>::map(IO &IO) {
534  IO.mapRequired("NumEnumerators", Record.MemberCount);
535  IO.mapRequired("Options", Record.Options);
536  IO.mapRequired("FieldList", Record.FieldList);
537  IO.mapRequired("Name", Record.Name);
538  IO.mapRequired("UniqueName", Record.UniqueName);
539  IO.mapRequired("UnderlyingType", Record.UnderlyingType);
540 }
541 
542 template <> void LeafRecordImpl<BitFieldRecord>::map(IO &IO) {
543  IO.mapRequired("Type", Record.Type);
544  IO.mapRequired("BitSize", Record.BitSize);
545  IO.mapRequired("BitOffset", Record.BitOffset);
546 }
547 
548 template <> void LeafRecordImpl<VFTableShapeRecord>::map(IO &IO) {
549  IO.mapRequired("Slots", Record.Slots);
550 }
551 
552 template <> void LeafRecordImpl<TypeServer2Record>::map(IO &IO) {
553  IO.mapRequired("Guid", Record.Guid);
554  IO.mapRequired("Age", Record.Age);
555  IO.mapRequired("Name", Record.Name);
556 }
557 
558 template <> void LeafRecordImpl<StringIdRecord>::map(IO &IO) {
559  IO.mapRequired("Id", Record.Id);
560  IO.mapRequired("String", Record.String);
561 }
562 
563 template <> void LeafRecordImpl<FuncIdRecord>::map(IO &IO) {
564  IO.mapRequired("ParentScope", Record.ParentScope);
565  IO.mapRequired("FunctionType", Record.FunctionType);
566  IO.mapRequired("Name", Record.Name);
567 }
568 
570  IO.mapRequired("UDT", Record.UDT);
571  IO.mapRequired("SourceFile", Record.SourceFile);
572  IO.mapRequired("LineNumber", Record.LineNumber);
573 }
574 
576  IO.mapRequired("UDT", Record.UDT);
577  IO.mapRequired("SourceFile", Record.SourceFile);
578  IO.mapRequired("LineNumber", Record.LineNumber);
579  IO.mapRequired("Module", Record.Module);
580 }
581 
582 template <> void LeafRecordImpl<BuildInfoRecord>::map(IO &IO) {
583  IO.mapRequired("ArgIndices", Record.ArgIndices);
584 }
585 
586 template <> void LeafRecordImpl<VFTableRecord>::map(IO &IO) {
587  IO.mapRequired("CompleteClass", Record.CompleteClass);
588  IO.mapRequired("OverriddenVFTable", Record.OverriddenVFTable);
589  IO.mapRequired("VFPtrOffset", Record.VFPtrOffset);
590  IO.mapRequired("MethodNames", Record.MethodNames);
591 }
592 
594  IO.mapRequired("Methods", Record.Methods);
595 }
596 
597 template <> void MemberRecordImpl<OneMethodRecord>::map(IO &IO) {
599 }
600 
602  IO.mapRequired("NumOverloads", Record.NumOverloads);
603  IO.mapRequired("MethodList", Record.MethodList);
604  IO.mapRequired("Name", Record.Name);
605 }
606 
607 template <> void MemberRecordImpl<NestedTypeRecord>::map(IO &IO) {
608  IO.mapRequired("Type", Record.Type);
609  IO.mapRequired("Name", Record.Name);
610 }
611 
612 template <> void MemberRecordImpl<DataMemberRecord>::map(IO &IO) {
613  IO.mapRequired("Attrs", Record.Attrs.Attrs);
614  IO.mapRequired("Type", Record.Type);
615  IO.mapRequired("FieldOffset", Record.FieldOffset);
616  IO.mapRequired("Name", Record.Name);
617 }
618 
620  IO.mapRequired("Attrs", Record.Attrs.Attrs);
621  IO.mapRequired("Type", Record.Type);
622  IO.mapRequired("Name", Record.Name);
623 }
624 
625 template <> void MemberRecordImpl<EnumeratorRecord>::map(IO &IO) {
626  IO.mapRequired("Attrs", Record.Attrs.Attrs);
627  IO.mapRequired("Value", Record.Value);
628  IO.mapRequired("Name", Record.Name);
629 }
630 
631 template <> void MemberRecordImpl<VFPtrRecord>::map(IO &IO) {
632  IO.mapRequired("Type", Record.Type);
633 }
634 
635 template <> void MemberRecordImpl<BaseClassRecord>::map(IO &IO) {
636  IO.mapRequired("Attrs", Record.Attrs.Attrs);
637  IO.mapRequired("Type", Record.Type);
638  IO.mapRequired("Offset", Record.Offset);
639 }
640 
642  IO.mapRequired("Attrs", Record.Attrs.Attrs);
643  IO.mapRequired("BaseType", Record.BaseType);
644  IO.mapRequired("VBPtrType", Record.VBPtrType);
645  IO.mapRequired("VBPtrOffset", Record.VBPtrOffset);
646  IO.mapRequired("VTableIndex", Record.VTableIndex);
647 }
648 
650  IO.mapRequired("ContinuationIndex", Record.ContinuationIndex);
651 }
652 
653 } // end namespace detail
654 } // end namespace CodeViewYAML
655 } // end namespace llvm
656 
657 template <typename T>
659  LeafRecord Result;
660 
661  auto Impl = std::make_shared<LeafRecordImpl<T>>(Type.kind());
662  if (auto EC = Impl->fromCodeViewRecord(Type))
663  return std::move(EC);
664  Result.Leaf = Impl;
665  return Result;
666 }
667 
668 Expected<LeafRecord> LeafRecord::fromCodeViewRecord(CVType Type) {
669 #define TYPE_RECORD(EnumName, EnumVal, ClassName) \
670  case EnumName: \
671  return fromCodeViewRecordImpl<ClassName##Record>(Type);
672 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
673  TYPE_RECORD(EnumName, EnumVal, ClassName)
674 #define MEMBER_RECORD(EnumName, EnumVal, ClassName)
675 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
676  switch (Type.kind()) {
677 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
678  default:
679  llvm_unreachable("Unknown leaf kind!");
680  }
681  return make_error<CodeViewError>(cv_error_code::corrupt_record);
682 }
683 
684 CVType LeafRecord::toCodeViewRecord(BumpPtrAllocator &Alloc) const {
685  TypeTableBuilder TTB(Alloc);
686  return Leaf->toCodeViewRecord(TTB);
687 }
688 
689 CVType LeafRecord::toCodeViewRecord(TypeTableBuilder &TTB) const {
690  return Leaf->toCodeViewRecord(TTB);
691 }
692 
693 namespace llvm {
694 namespace yaml {
695 
696 template <> struct MappingTraits<LeafRecordBase> {
697  static void mapping(IO &io, LeafRecordBase &Record) { Record.map(io); }
698 };
699 
700 template <> struct MappingTraits<MemberRecordBase> {
701  static void mapping(IO &io, MemberRecordBase &Record) { Record.map(io); }
702 };
703 
704 } // end namespace yaml
705 } // end namespace llvm
706 
707 template <typename ConcreteType>
708 static void mapLeafRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
709  LeafRecord &Obj) {
710  if (!IO.outputting())
711  Obj.Leaf = std::make_shared<LeafRecordImpl<ConcreteType>>(Kind);
712 
713  if (Kind == LF_FIELDLIST)
714  Obj.Leaf->map(IO);
715  else
716  IO.mapRequired(Class, *Obj.Leaf);
717 }
718 
721  if (IO.outputting())
722  Kind = Obj.Leaf->Kind;
723  IO.mapRequired("Kind", Kind);
724 
725 #define TYPE_RECORD(EnumName, EnumVal, ClassName) \
726  case EnumName: \
727  mapLeafRecordImpl<ClassName##Record>(IO, #ClassName, Kind, Obj); \
728  break;
729 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
730  TYPE_RECORD(EnumName, EnumVal, ClassName)
731 #define MEMBER_RECORD(EnumName, EnumVal, ClassName)
732 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
733  switch (Kind) {
734 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
735  default: { llvm_unreachable("Unknown leaf kind!"); }
736  }
737 }
738 
739 template <typename ConcreteType>
740 static void mapMemberRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
741  MemberRecord &Obj) {
742  if (!IO.outputting())
743  Obj.Member = std::make_shared<MemberRecordImpl<ConcreteType>>(Kind);
744 
745  IO.mapRequired(Class, *Obj.Member);
746 }
747 
750  if (IO.outputting())
751  Kind = Obj.Member->Kind;
752  IO.mapRequired("Kind", Kind);
753 
754 #define MEMBER_RECORD(EnumName, EnumVal, ClassName) \
755  case EnumName: \
756  mapMemberRecordImpl<ClassName##Record>(IO, #ClassName, Kind, Obj); \
757  break;
758 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
759  MEMBER_RECORD(EnumName, EnumVal, ClassName)
760 #define TYPE_RECORD(EnumName, EnumVal, ClassName)
761 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
762  switch (Kind) {
763 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
764  default: { llvm_unreachable("Unknown member kind!"); }
765  }
766 }
767 
768 std::vector<LeafRecord>
770  ExitOnError Err("Invalid .debug$T section!");
771  BinaryStreamReader Reader(DebugT, support::little);
772  CVTypeArray Types;
773  uint32_t Magic;
774 
775  Err(Reader.readInteger(Magic));
776  assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$T section!");
777 
778  std::vector<LeafRecord> Result;
779  Err(Reader.readArray(Types, Reader.bytesRemaining()));
780  for (const auto &T : Types) {
781  auto CVT = Err(LeafRecord::fromCodeViewRecord(T));
782  Result.push_back(CVT);
783  }
784  return Result;
785 }
786 
788  BumpPtrAllocator &Alloc) {
789  TypeTableBuilder TTB(Alloc, false);
790  uint32_t Size = sizeof(uint32_t);
791  for (const auto &Leaf : Leafs) {
792  CVType T = Leaf.toCodeViewRecord(TTB);
793  Size += T.length();
794  assert(T.length() % 4 == 0 && "Improper type record alignment!");
795  }
796  uint8_t *ResultBuffer = Alloc.Allocate<uint8_t>(Size);
797  MutableArrayRef<uint8_t> Output(ResultBuffer, Size);
798  BinaryStreamWriter Writer(Output, support::little);
799  ExitOnError Err("Error writing type record to .debug$T section");
801  for (const auto &R : TTB.records()) {
802  Err(Writer.writeBytes(R));
803  }
804  assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!");
805  return Output;
806 }
PointerKind
Equivalent to CV_ptrtype_e.
Definition: CodeView.h:326
void bitSetCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:616
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
TypeIndex writeKnownType(T &Record)
void mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:656
Kind kind() const
Definition: CVRecord.h:37
SI Whole Quad Mode
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream&#39;s offset.
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:34
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
Helper for check-and-exit error handling.
Definition: Error.h:1108
Error visitMemberRecordStream(ArrayRef< uint8_t > FieldList, TypeVisitorCallbacks &Callbacks)
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence...
Definition: YAMLTraits.h:1643
void writeTo(FieldListRecordBuilder &FLRB) override
CVRecord< TypeLeafKind > CVType
Definition: TypeRecord.h:36
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
ArrayRef< ArrayRef< uint8_t > > records() const
#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)
Definition: YAMLTraits.h:1660
ArrayRef< uint8_t > toDebugT(ArrayRef< LeafRecord >, BumpPtrAllocator &Alloc)
void setIndex(uint32_t I)
Definition: TypeIndex.h:111
virtual void map(yaml::IO &io)=0
ArrayRef< uint8_t > content() const
Definition: CVRecord.h:44
This represents the &#39;GUID&#39; type from windows.h.
Definition: GUID.h:22
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
ModifierOptions
Equivalent to CV_modifier_t.
Definition: CodeView.h:297
LabelType
Equivalent to CV_LABEL_TYPE_e.
Definition: CodeView.h:290
Error fromCodeViewRecord(CVType Type) override
A 32-bit type reference.
Definition: TypeIndex.h:96
uint32_t length() const
Definition: CVRecord.h:36
uint8_t Guid[16]
Definition: GUID.h:23
MethodKind
Part of member attribute flags. (CV_methodprop_e)
Definition: CodeView.h:266
std::vector< LeafRecord > fromDebugT(ArrayRef< uint8_t > DebugT)
TypeRecordKind
Distinguishes individual records in .debug$T section or PDB type stream.
Definition: CodeView.h:27
static void mapping(IO &io, LeafRecordBase &Record)
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:590
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
bool isSigned() const
Definition: APSInt.h:59
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:212
static Expected< LeafRecord > fromCodeViewRecordImpl(CVType Type)
Provides write only access to a subclass of WritableBinaryStream.
Error writeInteger(T Value)
Write the the integer Value to the underlying stream in the specified endianness. ...
The Output class is used to generate a yaml document from in-memory structs and vectors.
Definition: YAMLTraits.h:1260
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static void mapMemberRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind, MemberRecord &Obj)
uint32_t getIndex() const
Definition: TypeIndex.h:110
uint32_t bytesRemaining() const
static const char *const Magic
Definition: Archive.cpp:42
PointerOptions
Equivalent to misc lfPointerAttr bitfields.
Definition: CodeView.h:352
static ErrorSuccess success()
Create a success value.
Definition: Error.h:313
#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML flow sequen...
Definition: YAMLTraits.h:1648
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:98
const DataFlowGraph & G
Definition: RDFGraph.cpp:211
This class should be specialized by type that requires custom conversion to/from a yaml scalar...
Definition: YAMLTraits.h:137
static void mapping(IO &io, MemberRecordBase &Record)
void print(raw_ostream &OS, bool isSigned) const
Definition: APInt.cpp:2133
PointerMode
Equivalent to CV_ptrmode_e.
Definition: CodeView.h:343
std::shared_ptr< detail::MemberRecordBase > Member
#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote)
Definition: YAMLTraits.h:1678
#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type)
Definition: YAMLTraits.h:1669
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
Definition: StringExtras.h:54
MethodOptions
Equivalent to CV_fldattr_t bitfield.
Definition: CodeView.h:277
iterator begin() const
Definition: StringRef.h:106
static void mapLeafRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind, LeafRecord &Obj)
CVType toCodeViewRecord(TypeTableBuilder &TTB) const override
#define I(x, y, z)
Definition: MD5.cpp:58
uint32_t bytesRemaining() const
PointerToMemberRepresentation
Equivalent to CV_pmtype_e.
Definition: CodeView.h:364
virtual bool outputting()=0
This class should be specialized by any integer type that is a union of bit values and the YAML repre...
Definition: YAMLTraits.h:115
const unsigned Kind
MemberAccess
Source-level access specifier. (CV_access_e)
Definition: CodeView.h:258
#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type)
Definition: YAMLTraits.h:1651
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
Definition: CodeView.h:173
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:646
iterator end() const
Definition: StringRef.h:108
std::shared_ptr< detail::LeafRecordBase > Leaf
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...
PointerToMemberRepresentation Representation
Definition: TypeRecord.h:116