LLVM  7.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"
28 #include "llvm/Support/Allocator.h"
31 #include "llvm/Support/Endian.h"
32 #include "llvm/Support/Error.h"
36 #include <algorithm>
37 #include <cassert>
38 #include <cstdint>
39 #include <vector>
40 
41 using namespace llvm;
42 using namespace llvm::codeview;
43 using namespace llvm::CodeViewYAML;
44 using namespace llvm::CodeViewYAML::detail;
45 using namespace llvm::yaml;
46 
50 
53 
65 
71 
74 
75 namespace llvm {
76 namespace CodeViewYAML {
77 namespace detail {
78 
81 
82  explicit LeafRecordBase(TypeLeafKind K) : Kind(K) {}
83  virtual ~LeafRecordBase() = default;
84 
85  virtual void map(yaml::IO &io) = 0;
86  virtual CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const = 0;
87  virtual Error fromCodeViewRecord(CVType Type) = 0;
88 };
89 
90 template <typename T> struct LeafRecordImpl : public LeafRecordBase {
92  : LeafRecordBase(K), Record(static_cast<TypeRecordKind>(K)) {}
93 
94  void map(yaml::IO &io) override;
95 
97  return TypeDeserializer::deserializeAs<T>(Type, Record);
98  }
99 
101  TS.writeLeafType(Record);
102  return CVType(Kind, TS.records().back());
103  }
104 
105  mutable T Record;
106 };
107 
108 template <> struct LeafRecordImpl<FieldListRecord> : public LeafRecordBase {
110 
111  void map(yaml::IO &io) override;
112  CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override;
113  Error fromCodeViewRecord(CVType Type) override;
114 
115  std::vector<MemberRecord> Members;
116 };
117 
120 
121  explicit MemberRecordBase(TypeLeafKind K) : Kind(K) {}
122  virtual ~MemberRecordBase() = default;
123 
124  virtual void map(yaml::IO &io) = 0;
125  virtual void writeTo(ContinuationRecordBuilder &CRB) = 0;
126 };
127 
128 template <typename T> struct MemberRecordImpl : public MemberRecordBase {
130  : MemberRecordBase(K), Record(static_cast<TypeRecordKind>(K)) {}
131 
132  void map(yaml::IO &io) override;
133 
134  void writeTo(ContinuationRecordBuilder &CRB) override {
135  CRB.writeMemberType(Record);
136  }
137 
138  mutable T Record;
139 };
140 
141 } // end namespace detail
142 } // end namespace CodeViewYAML
143 } // end namespace llvm
144 
145 void ScalarTraits<GUID>::output(const GUID &G, void *, llvm::raw_ostream &OS) {
146  OS << G;
147 }
148 
150  if (Scalar.size() != 38)
151  return "GUID strings are 38 characters long";
152  if (Scalar[0] != '{' || Scalar[37] != '}')
153  return "GUID is not enclosed in {}";
154  if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' ||
155  Scalar[24] != '-')
156  return "GUID sections are not properly delineated with dashes";
157 
158  uint8_t *OutBuffer = S.Guid;
159  for (auto Iter = Scalar.begin(); Iter != Scalar.end();) {
160  if (*Iter == '-' || *Iter == '{' || *Iter == '}') {
161  ++Iter;
162  continue;
163  }
164  uint8_t Value = (llvm::hexDigitValue(*Iter++) << 4);
165  Value |= llvm::hexDigitValue(*Iter++);
166  *OutBuffer++ = Value;
167  }
168 
169  return "";
170 }
171 
172 void ScalarTraits<TypeIndex>::output(const TypeIndex &S, void *,
173  raw_ostream &OS) {
174  OS << S.getIndex();
175 }
176 
178  TypeIndex &S) {
179  uint32_t I;
180  StringRef Result = ScalarTraits<uint32_t>::input(Scalar, Ctx, I);
181  S.setIndex(I);
182  return Result;
183 }
184 
185 void ScalarTraits<APSInt>::output(const APSInt &S, void *, raw_ostream &OS) {
186  S.print(OS, S.isSigned());
187 }
188 
189 StringRef ScalarTraits<APSInt>::input(StringRef Scalar, void *Ctx, APSInt &S) {
190  S = APSInt(Scalar);
191  return "";
192 }
193 
195  TypeLeafKind &Value) {
196 #define CV_TYPE(name, val) io.enumCase(Value, #name, name);
197 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
198 #undef CV_TYPE
199 }
200 
203  IO.enumCase(Value, "Unknown", PointerToMemberRepresentation::Unknown);
204  IO.enumCase(Value, "SingleInheritanceData",
206  IO.enumCase(Value, "MultipleInheritanceData",
208  IO.enumCase(Value, "VirtualInheritanceData",
210  IO.enumCase(Value, "GeneralData", PointerToMemberRepresentation::GeneralData);
211  IO.enumCase(Value, "SingleInheritanceFunction",
213  IO.enumCase(Value, "MultipleInheritanceFunction",
215  IO.enumCase(Value, "VirtualInheritanceFunction",
217  IO.enumCase(Value, "GeneralFunction",
219 }
220 
222  IO &IO, VFTableSlotKind &Kind) {
223  IO.enumCase(Kind, "Near16", VFTableSlotKind::Near16);
224  IO.enumCase(Kind, "Far16", VFTableSlotKind::Far16);
225  IO.enumCase(Kind, "This", VFTableSlotKind::This);
226  IO.enumCase(Kind, "Outer", VFTableSlotKind::Outer);
227  IO.enumCase(Kind, "Meta", VFTableSlotKind::Meta);
228  IO.enumCase(Kind, "Near", VFTableSlotKind::Near);
229  IO.enumCase(Kind, "Far", VFTableSlotKind::Far);
230 }
231 
233  IO &IO, CallingConvention &Value) {
234  IO.enumCase(Value, "NearC", CallingConvention::NearC);
235  IO.enumCase(Value, "FarC", CallingConvention::FarC);
236  IO.enumCase(Value, "NearPascal", CallingConvention::NearPascal);
237  IO.enumCase(Value, "FarPascal", CallingConvention::FarPascal);
238  IO.enumCase(Value, "NearFast", CallingConvention::NearFast);
239  IO.enumCase(Value, "FarFast", CallingConvention::FarFast);
240  IO.enumCase(Value, "NearStdCall", CallingConvention::NearStdCall);
241  IO.enumCase(Value, "FarStdCall", CallingConvention::FarStdCall);
242  IO.enumCase(Value, "NearSysCall", CallingConvention::NearSysCall);
243  IO.enumCase(Value, "FarSysCall", CallingConvention::FarSysCall);
244  IO.enumCase(Value, "ThisCall", CallingConvention::ThisCall);
245  IO.enumCase(Value, "MipsCall", CallingConvention::MipsCall);
246  IO.enumCase(Value, "Generic", CallingConvention::Generic);
247  IO.enumCase(Value, "AlphaCall", CallingConvention::AlphaCall);
248  IO.enumCase(Value, "PpcCall", CallingConvention::PpcCall);
249  IO.enumCase(Value, "SHCall", CallingConvention::SHCall);
250  IO.enumCase(Value, "ArmCall", CallingConvention::ArmCall);
251  IO.enumCase(Value, "AM33Call", CallingConvention::AM33Call);
252  IO.enumCase(Value, "TriCall", CallingConvention::TriCall);
253  IO.enumCase(Value, "SH5Call", CallingConvention::SH5Call);
254  IO.enumCase(Value, "M32RCall", CallingConvention::M32RCall);
255  IO.enumCase(Value, "ClrCall", CallingConvention::ClrCall);
256  IO.enumCase(Value, "Inline", CallingConvention::Inline);
257  IO.enumCase(Value, "NearVector", CallingConvention::NearVector);
258 }
259 
261  PointerKind &Kind) {
262  IO.enumCase(Kind, "Near16", PointerKind::Near16);
263  IO.enumCase(Kind, "Far16", PointerKind::Far16);
264  IO.enumCase(Kind, "Huge16", PointerKind::Huge16);
265  IO.enumCase(Kind, "BasedOnSegment", PointerKind::BasedOnSegment);
266  IO.enumCase(Kind, "BasedOnValue", PointerKind::BasedOnValue);
267  IO.enumCase(Kind, "BasedOnSegmentValue", PointerKind::BasedOnSegmentValue);
268  IO.enumCase(Kind, "BasedOnAddress", PointerKind::BasedOnAddress);
269  IO.enumCase(Kind, "BasedOnSegmentAddress",
271  IO.enumCase(Kind, "BasedOnType", PointerKind::BasedOnType);
272  IO.enumCase(Kind, "BasedOnSelf", PointerKind::BasedOnSelf);
273  IO.enumCase(Kind, "Near32", PointerKind::Near32);
274  IO.enumCase(Kind, "Far32", PointerKind::Far32);
275  IO.enumCase(Kind, "Near64", PointerKind::Near64);
276 }
277 
279  PointerMode &Mode) {
280  IO.enumCase(Mode, "Pointer", PointerMode::Pointer);
281  IO.enumCase(Mode, "LValueReference", PointerMode::LValueReference);
282  IO.enumCase(Mode, "PointerToDataMember", PointerMode::PointerToDataMember);
283  IO.enumCase(Mode, "PointerToMemberFunction",
285  IO.enumCase(Mode, "RValueReference", PointerMode::RValueReference);
286 }
287 
289  IO.enumCase(Value, "None", HfaKind::None);
290  IO.enumCase(Value, "Float", HfaKind::Float);
291  IO.enumCase(Value, "Double", HfaKind::Double);
292  IO.enumCase(Value, "Other", HfaKind::Other);
293 }
294 
296  MemberAccess &Access) {
297  IO.enumCase(Access, "None", MemberAccess::None);
298  IO.enumCase(Access, "Private", MemberAccess::Private);
299  IO.enumCase(Access, "Protected", MemberAccess::Protected);
300  IO.enumCase(Access, "Public", MemberAccess::Public);
301 }
302 
304  MethodKind &Kind) {
305  IO.enumCase(Kind, "Vanilla", MethodKind::Vanilla);
306  IO.enumCase(Kind, "Virtual", MethodKind::Virtual);
307  IO.enumCase(Kind, "Static", MethodKind::Static);
308  IO.enumCase(Kind, "Friend", MethodKind::Friend);
309  IO.enumCase(Kind, "IntroducingVirtual", MethodKind::IntroducingVirtual);
310  IO.enumCase(Kind, "PureVirtual", MethodKind::PureVirtual);
311  IO.enumCase(Kind, "PureIntroducingVirtual",
313 }
314 
316  IO &IO, WindowsRTClassKind &Value) {
317  IO.enumCase(Value, "None", WindowsRTClassKind::None);
318  IO.enumCase(Value, "Ref", WindowsRTClassKind::RefClass);
319  IO.enumCase(Value, "Value", WindowsRTClassKind::ValueClass);
320  IO.enumCase(Value, "Interface", WindowsRTClassKind::Interface);
321 }
322 
324  IO.enumCase(Value, "Near", LabelType::Near);
325  IO.enumCase(Value, "Far", LabelType::Far);
326 }
327 
329  PointerOptions &Options) {
330  IO.bitSetCase(Options, "None", PointerOptions::None);
331  IO.bitSetCase(Options, "Flat32", PointerOptions::Flat32);
332  IO.bitSetCase(Options, "Volatile", PointerOptions::Volatile);
333  IO.bitSetCase(Options, "Const", PointerOptions::Const);
334  IO.bitSetCase(Options, "Unaligned", PointerOptions::Unaligned);
335  IO.bitSetCase(Options, "Restrict", PointerOptions::Restrict);
336  IO.bitSetCase(Options, "WinRTSmartPointer",
338 }
339 
341  ModifierOptions &Options) {
342  IO.bitSetCase(Options, "None", ModifierOptions::None);
343  IO.bitSetCase(Options, "Const", ModifierOptions::Const);
344  IO.bitSetCase(Options, "Volatile", ModifierOptions::Volatile);
345  IO.bitSetCase(Options, "Unaligned", ModifierOptions::Unaligned);
346 }
347 
349  FunctionOptions &Options) {
350  IO.bitSetCase(Options, "None", FunctionOptions::None);
351  IO.bitSetCase(Options, "CxxReturnUdt", FunctionOptions::CxxReturnUdt);
352  IO.bitSetCase(Options, "Constructor", FunctionOptions::Constructor);
353  IO.bitSetCase(Options, "ConstructorWithVirtualBases",
355 }
356 
358  IO.bitSetCase(Options, "None", ClassOptions::None);
359  IO.bitSetCase(Options, "HasConstructorOrDestructor",
361  IO.bitSetCase(Options, "HasOverloadedOperator",
363  IO.bitSetCase(Options, "Nested", ClassOptions::Nested);
364  IO.bitSetCase(Options, "ContainsNestedClass",
366  IO.bitSetCase(Options, "HasOverloadedAssignmentOperator",
368  IO.bitSetCase(Options, "HasConversionOperator",
370  IO.bitSetCase(Options, "ForwardReference", ClassOptions::ForwardReference);
371  IO.bitSetCase(Options, "Scoped", ClassOptions::Scoped);
372  IO.bitSetCase(Options, "HasUniqueName", ClassOptions::HasUniqueName);
373  IO.bitSetCase(Options, "Sealed", ClassOptions::Sealed);
374  IO.bitSetCase(Options, "Intrinsic", ClassOptions::Intrinsic);
375 }
376 
378  IO.bitSetCase(Options, "None", MethodOptions::None);
379  IO.bitSetCase(Options, "Pseudo", MethodOptions::Pseudo);
380  IO.bitSetCase(Options, "NoInherit", MethodOptions::NoInherit);
381  IO.bitSetCase(Options, "NoConstruct", MethodOptions::NoConstruct);
382  IO.bitSetCase(Options, "CompilerGenerated", MethodOptions::CompilerGenerated);
383  IO.bitSetCase(Options, "Sealed", MethodOptions::Sealed);
384 }
385 
387  IO.mapRequired("ContainingType", MPI.ContainingType);
388  IO.mapRequired("Representation", MPI.Representation);
389 }
390 
391 namespace llvm {
392 namespace CodeViewYAML {
393 namespace detail {
394 
395 template <> void LeafRecordImpl<ModifierRecord>::map(IO &IO) {
396  IO.mapRequired("ModifiedType", Record.ModifiedType);
397  IO.mapRequired("Modifiers", Record.Modifiers);
398 }
399 
400 template <> void LeafRecordImpl<ProcedureRecord>::map(IO &IO) {
401  IO.mapRequired("ReturnType", Record.ReturnType);
402  IO.mapRequired("CallConv", Record.CallConv);
403  IO.mapRequired("Options", Record.Options);
404  IO.mapRequired("ParameterCount", Record.ParameterCount);
405  IO.mapRequired("ArgumentList", Record.ArgumentList);
406 }
407 
409  IO.mapRequired("ReturnType", Record.ReturnType);
410  IO.mapRequired("ClassType", Record.ClassType);
411  IO.mapRequired("ThisType", Record.ThisType);
412  IO.mapRequired("CallConv", Record.CallConv);
413  IO.mapRequired("Options", Record.Options);
414  IO.mapRequired("ParameterCount", Record.ParameterCount);
415  IO.mapRequired("ArgumentList", Record.ArgumentList);
416  IO.mapRequired("ThisPointerAdjustment", Record.ThisPointerAdjustment);
417 }
418 
419 template <> void LeafRecordImpl<LabelRecord>::map(IO &IO) {
420  IO.mapRequired("Mode", Record.Mode);
421 }
422 
423 template <> void LeafRecordImpl<MemberFuncIdRecord>::map(IO &IO) {
424  IO.mapRequired("ClassType", Record.ClassType);
425  IO.mapRequired("FunctionType", Record.FunctionType);
426  IO.mapRequired("Name", Record.Name);
427 }
428 
429 template <> void LeafRecordImpl<ArgListRecord>::map(IO &IO) {
430  IO.mapRequired("ArgIndices", Record.ArgIndices);
431 }
432 
433 template <> void LeafRecordImpl<StringListRecord>::map(IO &IO) {
434  IO.mapRequired("StringIndices", Record.StringIndices);
435 }
436 
437 template <> void LeafRecordImpl<PointerRecord>::map(IO &IO) {
438  IO.mapRequired("ReferentType", Record.ReferentType);
439  IO.mapRequired("Attrs", Record.Attrs);
440  IO.mapOptional("MemberInfo", Record.MemberInfo);
441 }
442 
443 template <> void LeafRecordImpl<ArrayRecord>::map(IO &IO) {
444  IO.mapRequired("ElementType", Record.ElementType);
445  IO.mapRequired("IndexType", Record.IndexType);
446  IO.mapRequired("Size", Record.Size);
447  IO.mapRequired("Name", Record.Name);
448 }
449 
451  IO.mapRequired("FieldList", Members);
452 }
453 
454 } // end namespace detail
455 } // end namespace CodeViewYAML
456 } // end namespace llvm
457 
458 namespace {
459 
460 class MemberRecordConversionVisitor : public TypeVisitorCallbacks {
461 public:
462  explicit MemberRecordConversionVisitor(std::vector<MemberRecord> &Records)
463  : Records(Records) {}
464 
465 #define TYPE_RECORD(EnumName, EnumVal, Name)
466 #define MEMBER_RECORD(EnumName, EnumVal, Name) \
467  Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override { \
468  return visitKnownMemberImpl(Record); \
469  }
470 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
471 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
472 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
473 private:
474  template <typename T> Error visitKnownMemberImpl(T &Record) {
475  TypeLeafKind K = static_cast<TypeLeafKind>(Record.getKind());
476  auto Impl = std::make_shared<MemberRecordImpl<T>>(K);
477  Impl->Record = Record;
478  Records.push_back(MemberRecord{Impl});
479  return Error::success();
480  }
481 
482  std::vector<MemberRecord> &Records;
483 };
484 
485 } // end anonymous namespace
486 
488  MemberRecordConversionVisitor V(Members);
489  return visitMemberRecordStream(Type.content(), V);
490 }
491 
493  AppendingTypeTableBuilder &TS) const {
496  for (const auto &Member : Members) {
497  Member.Member->writeTo(CRB);
498  }
499  TS.insertRecord(CRB);
500  return CVType(Kind, TS.records().back());
501 }
502 
504  io.mapRequired("Type", Record.Type);
505  io.mapRequired("Attrs", Record.Attrs.Attrs);
506  io.mapRequired("VFTableOffset", Record.VFTableOffset);
507  io.mapRequired("Name", Record.Name);
508 }
509 
510 namespace llvm {
511 namespace CodeViewYAML {
512 namespace detail {
513 
514 template <> void LeafRecordImpl<ClassRecord>::map(IO &IO) {
515  IO.mapRequired("MemberCount", Record.MemberCount);
516  IO.mapRequired("Options", Record.Options);
517  IO.mapRequired("FieldList", Record.FieldList);
518  IO.mapRequired("Name", Record.Name);
519  IO.mapRequired("UniqueName", Record.UniqueName);
520  IO.mapRequired("DerivationList", Record.DerivationList);
521  IO.mapRequired("VTableShape", Record.VTableShape);
522  IO.mapRequired("Size", Record.Size);
523 }
524 
525 template <> void LeafRecordImpl<UnionRecord>::map(IO &IO) {
526  IO.mapRequired("MemberCount", Record.MemberCount);
527  IO.mapRequired("Options", Record.Options);
528  IO.mapRequired("FieldList", Record.FieldList);
529  IO.mapRequired("Name", Record.Name);
530  IO.mapRequired("UniqueName", Record.UniqueName);
531  IO.mapRequired("Size", Record.Size);
532 }
533 
534 template <> void LeafRecordImpl<EnumRecord>::map(IO &IO) {
535  IO.mapRequired("NumEnumerators", Record.MemberCount);
536  IO.mapRequired("Options", Record.Options);
537  IO.mapRequired("FieldList", Record.FieldList);
538  IO.mapRequired("Name", Record.Name);
539  IO.mapRequired("UniqueName", Record.UniqueName);
540  IO.mapRequired("UnderlyingType", Record.UnderlyingType);
541 }
542 
543 template <> void LeafRecordImpl<BitFieldRecord>::map(IO &IO) {
544  IO.mapRequired("Type", Record.Type);
545  IO.mapRequired("BitSize", Record.BitSize);
546  IO.mapRequired("BitOffset", Record.BitOffset);
547 }
548 
549 template <> void LeafRecordImpl<VFTableShapeRecord>::map(IO &IO) {
550  IO.mapRequired("Slots", Record.Slots);
551 }
552 
553 template <> void LeafRecordImpl<TypeServer2Record>::map(IO &IO) {
554  IO.mapRequired("Guid", Record.Guid);
555  IO.mapRequired("Age", Record.Age);
556  IO.mapRequired("Name", Record.Name);
557 }
558 
559 template <> void LeafRecordImpl<StringIdRecord>::map(IO &IO) {
560  IO.mapRequired("Id", Record.Id);
561  IO.mapRequired("String", Record.String);
562 }
563 
564 template <> void LeafRecordImpl<FuncIdRecord>::map(IO &IO) {
565  IO.mapRequired("ParentScope", Record.ParentScope);
566  IO.mapRequired("FunctionType", Record.FunctionType);
567  IO.mapRequired("Name", Record.Name);
568 }
569 
571  IO.mapRequired("UDT", Record.UDT);
572  IO.mapRequired("SourceFile", Record.SourceFile);
573  IO.mapRequired("LineNumber", Record.LineNumber);
574 }
575 
577  IO.mapRequired("UDT", Record.UDT);
578  IO.mapRequired("SourceFile", Record.SourceFile);
579  IO.mapRequired("LineNumber", Record.LineNumber);
580  IO.mapRequired("Module", Record.Module);
581 }
582 
583 template <> void LeafRecordImpl<BuildInfoRecord>::map(IO &IO) {
584  IO.mapRequired("ArgIndices", Record.ArgIndices);
585 }
586 
587 template <> void LeafRecordImpl<VFTableRecord>::map(IO &IO) {
588  IO.mapRequired("CompleteClass", Record.CompleteClass);
589  IO.mapRequired("OverriddenVFTable", Record.OverriddenVFTable);
590  IO.mapRequired("VFPtrOffset", Record.VFPtrOffset);
591  IO.mapRequired("MethodNames", Record.MethodNames);
592 }
593 
595  IO.mapRequired("Methods", Record.Methods);
596 }
597 
598 template <> void MemberRecordImpl<OneMethodRecord>::map(IO &IO) {
600 }
601 
603  IO.mapRequired("NumOverloads", Record.NumOverloads);
604  IO.mapRequired("MethodList", Record.MethodList);
605  IO.mapRequired("Name", Record.Name);
606 }
607 
608 template <> void MemberRecordImpl<NestedTypeRecord>::map(IO &IO) {
609  IO.mapRequired("Type", Record.Type);
610  IO.mapRequired("Name", Record.Name);
611 }
612 
613 template <> void MemberRecordImpl<DataMemberRecord>::map(IO &IO) {
614  IO.mapRequired("Attrs", Record.Attrs.Attrs);
615  IO.mapRequired("Type", Record.Type);
616  IO.mapRequired("FieldOffset", Record.FieldOffset);
617  IO.mapRequired("Name", Record.Name);
618 }
619 
621  IO.mapRequired("Attrs", Record.Attrs.Attrs);
622  IO.mapRequired("Type", Record.Type);
623  IO.mapRequired("Name", Record.Name);
624 }
625 
626 template <> void MemberRecordImpl<EnumeratorRecord>::map(IO &IO) {
627  IO.mapRequired("Attrs", Record.Attrs.Attrs);
628  IO.mapRequired("Value", Record.Value);
629  IO.mapRequired("Name", Record.Name);
630 }
631 
632 template <> void MemberRecordImpl<VFPtrRecord>::map(IO &IO) {
633  IO.mapRequired("Type", Record.Type);
634 }
635 
636 template <> void MemberRecordImpl<BaseClassRecord>::map(IO &IO) {
637  IO.mapRequired("Attrs", Record.Attrs.Attrs);
638  IO.mapRequired("Type", Record.Type);
639  IO.mapRequired("Offset", Record.Offset);
640 }
641 
643  IO.mapRequired("Attrs", Record.Attrs.Attrs);
644  IO.mapRequired("BaseType", Record.BaseType);
645  IO.mapRequired("VBPtrType", Record.VBPtrType);
646  IO.mapRequired("VBPtrOffset", Record.VBPtrOffset);
647  IO.mapRequired("VTableIndex", Record.VTableIndex);
648 }
649 
651  IO.mapRequired("ContinuationIndex", Record.ContinuationIndex);
652 }
653 
654 } // end namespace detail
655 } // end namespace CodeViewYAML
656 } // end namespace llvm
657 
658 template <typename T>
660  LeafRecord Result;
661 
662  auto Impl = std::make_shared<LeafRecordImpl<T>>(Type.kind());
663  if (auto EC = Impl->fromCodeViewRecord(Type))
664  return std::move(EC);
665  Result.Leaf = Impl;
666  return Result;
667 }
668 
669 Expected<LeafRecord> LeafRecord::fromCodeViewRecord(CVType Type) {
670 #define TYPE_RECORD(EnumName, EnumVal, ClassName) \
671  case EnumName: \
672  return fromCodeViewRecordImpl<ClassName##Record>(Type);
673 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
674  TYPE_RECORD(EnumName, EnumVal, ClassName)
675 #define MEMBER_RECORD(EnumName, EnumVal, ClassName)
676 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
677  switch (Type.kind()) {
678 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
679  default:
680  llvm_unreachable("Unknown leaf kind!");
681  }
682  return make_error<CodeViewError>(cv_error_code::corrupt_record);
683 }
684 
685 CVType
686 LeafRecord::toCodeViewRecord(AppendingTypeTableBuilder &Serializer) const {
687  return Leaf->toCodeViewRecord(Serializer);
688 }
689 
690 namespace llvm {
691 namespace yaml {
692 
693 template <> struct MappingTraits<LeafRecordBase> {
694  static void mapping(IO &io, LeafRecordBase &Record) { Record.map(io); }
695 };
696 
697 template <> struct MappingTraits<MemberRecordBase> {
698  static void mapping(IO &io, MemberRecordBase &Record) { Record.map(io); }
699 };
700 
701 } // end namespace yaml
702 } // end namespace llvm
703 
704 template <typename ConcreteType>
705 static void mapLeafRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
706  LeafRecord &Obj) {
707  if (!IO.outputting())
708  Obj.Leaf = std::make_shared<LeafRecordImpl<ConcreteType>>(Kind);
709 
710  if (Kind == LF_FIELDLIST)
711  Obj.Leaf->map(IO);
712  else
713  IO.mapRequired(Class, *Obj.Leaf);
714 }
715 
718  if (IO.outputting())
719  Kind = Obj.Leaf->Kind;
720  IO.mapRequired("Kind", Kind);
721 
722 #define TYPE_RECORD(EnumName, EnumVal, ClassName) \
723  case EnumName: \
724  mapLeafRecordImpl<ClassName##Record>(IO, #ClassName, Kind, Obj); \
725  break;
726 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
727  TYPE_RECORD(EnumName, EnumVal, ClassName)
728 #define MEMBER_RECORD(EnumName, EnumVal, ClassName)
729 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
730  switch (Kind) {
731 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
732  default: { llvm_unreachable("Unknown leaf kind!"); }
733  }
734 }
735 
736 template <typename ConcreteType>
737 static void mapMemberRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind,
738  MemberRecord &Obj) {
739  if (!IO.outputting())
740  Obj.Member = std::make_shared<MemberRecordImpl<ConcreteType>>(Kind);
741 
742  IO.mapRequired(Class, *Obj.Member);
743 }
744 
747  if (IO.outputting())
748  Kind = Obj.Member->Kind;
749  IO.mapRequired("Kind", Kind);
750 
751 #define MEMBER_RECORD(EnumName, EnumVal, ClassName) \
752  case EnumName: \
753  mapMemberRecordImpl<ClassName##Record>(IO, #ClassName, Kind, Obj); \
754  break;
755 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \
756  MEMBER_RECORD(EnumName, EnumVal, ClassName)
757 #define TYPE_RECORD(EnumName, EnumVal, ClassName)
758 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName)
759  switch (Kind) {
760 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
761  default: { llvm_unreachable("Unknown member kind!"); }
762  }
763 }
764 
765 std::vector<LeafRecord>
767  ExitOnError Err("Invalid .debug$T section!");
768  BinaryStreamReader Reader(DebugT, support::little);
769  CVTypeArray Types;
770  uint32_t Magic;
771 
772  Err(Reader.readInteger(Magic));
773  assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$T section!");
774 
775  std::vector<LeafRecord> Result;
776  Err(Reader.readArray(Types, Reader.bytesRemaining()));
777  for (const auto &T : Types) {
778  auto CVT = Err(LeafRecord::fromCodeViewRecord(T));
779  Result.push_back(CVT);
780  }
781  return Result;
782 }
783 
785  BumpPtrAllocator &Alloc) {
786  AppendingTypeTableBuilder TS(Alloc);
787  uint32_t Size = sizeof(uint32_t);
788  for (const auto &Leaf : Leafs) {
789  CVType T = Leaf.Leaf->toCodeViewRecord(TS);
790  Size += T.length();
791  assert(T.length() % 4 == 0 && "Improper type record alignment!");
792  }
793  uint8_t *ResultBuffer = Alloc.Allocate<uint8_t>(Size);
794  MutableArrayRef<uint8_t> Output(ResultBuffer, Size);
795  BinaryStreamWriter Writer(Output, support::little);
796  ExitOnError Err("Error writing type record to .debug$T section");
798  for (const auto &R : TS.records()) {
799  Err(Writer.writeBytes(R));
800  }
801  assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!");
802  return Output;
803 }
PointerKind
Equivalent to CV_ptrtype_e.
Definition: CodeView.h:326
void bitSetCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:660
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
void mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:700
Kind kind() const
Definition: CVRecord.h:37
SI Whole Quad Mode
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
ArrayRef< ArrayRef< uint8_t > > records() const
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:1687
CVRecord< TypeLeafKind > CVType
Definition: TypeRecord.h:36
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)
Definition: YAMLTraits.h:1704
ArrayRef< uint8_t > toDebugT(ArrayRef< LeafRecord >, BumpPtrAllocator &Alloc)
void setIndex(uint32_t I)
Definition: TypeIndex.h:112
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:634
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:143
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:217
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:1304
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
#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:111
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:1692
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:99
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:143
static void mapping(IO &io, MemberRecordBase &Record)
void print(raw_ostream &OS, bool isSigned) const
Definition: APInt.cpp:2143
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:1722
#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type)
Definition: YAMLTraits.h:1713
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
Definition: StringExtras.h:59
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)
#define I(x, y, z)
Definition: MD5.cpp:58
CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override
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:116
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:1695
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
void writeTo(ContinuationRecordBuilder &CRB) override
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:690
iterator end() const
Definition: StringRef.h:108
std::shared_ptr< detail::LeafRecordBase > Leaf
void begin(ContinuationRecordKind RecordKind)
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