Index: include/llvm/DebugInfo/CodeView/CodeView.h =================================================================== --- include/llvm/DebugInfo/CodeView/CodeView.h +++ include/llvm/DebugInfo/CodeView/CodeView.h @@ -22,8 +22,8 @@ namespace llvm { namespace codeview { -/// Distinguishes individual records in .debug$T section or PDB type stream. The -/// documentation and headers talk about this as the "leaf" type. +/// Distinguishes individual records in .debug$T or .debug$P section or PDB type +/// stream. The documentation and headers talk about this as the "leaf" type. enum class TypeRecordKind : uint16_t { #define TYPE_RECORD(lf_ename, value, name) name = value, #include "CodeViewTypes.def" Index: include/llvm/DebugInfo/CodeView/TypeRecord.h =================================================================== --- include/llvm/DebugInfo/CodeView/TypeRecord.h +++ include/llvm/DebugInfo/CodeView/TypeRecord.h @@ -1,902 +1,929 @@ -//===- TypeRecord.h ---------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_DEBUGINFO_CODEVIEW_TYPERECORD_H -#define LLVM_DEBUGINFO_CODEVIEW_TYPERECORD_H - -#include "llvm/ADT/APSInt.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/ADT/iterator_range.h" -#include "llvm/DebugInfo/CodeView/CVRecord.h" -#include "llvm/DebugInfo/CodeView/CodeView.h" -#include "llvm/DebugInfo/CodeView/GUID.h" -#include "llvm/DebugInfo/CodeView/TypeIndex.h" -#include "llvm/Support/BinaryStreamArray.h" -#include "llvm/Support/Endian.h" -#include -#include -#include - -namespace llvm { -namespace codeview { - -using support::little32_t; -using support::ulittle16_t; -using support::ulittle32_t; - -using CVType = CVRecord; -using RemappedType = RemappedRecord; - -struct CVMemberRecord { - TypeLeafKind Kind; - ArrayRef Data; -}; -using CVTypeArray = VarStreamArray; -using CVTypeRange = iterator_range; - -/// Equvalent to CV_fldattr_t in cvinfo.h. -struct MemberAttributes { - uint16_t Attrs = 0; - - enum { - MethodKindShift = 2, - }; - - MemberAttributes() = default; - - explicit MemberAttributes(MemberAccess Access) - : Attrs(static_cast(Access)) {} - - MemberAttributes(MemberAccess Access, MethodKind Kind, MethodOptions Flags) { - Attrs = static_cast(Access); - Attrs |= (static_cast(Kind) << MethodKindShift); - Attrs |= static_cast(Flags); - } - - /// Get the access specifier. Valid for any kind of member. - MemberAccess getAccess() const { - return MemberAccess(unsigned(Attrs) & unsigned(MethodOptions::AccessMask)); - } - - /// Indicates if a method is defined with friend, virtual, static, etc. - MethodKind getMethodKind() const { - return MethodKind( - (unsigned(Attrs) & unsigned(MethodOptions::MethodKindMask)) >> - MethodKindShift); - } - - /// Get the flags that are not included in access control or method - /// properties. - MethodOptions getFlags() const { - return MethodOptions( - unsigned(Attrs) & - ~unsigned(MethodOptions::AccessMask | MethodOptions::MethodKindMask)); - } - - /// Is this method virtual. - bool isVirtual() const { - auto MP = getMethodKind(); - return MP != MethodKind::Vanilla && MP != MethodKind::Friend && - MP != MethodKind::Static; - } - - /// Does this member introduce a new virtual method. - bool isIntroducedVirtual() const { - auto MP = getMethodKind(); - return MP == MethodKind::IntroducingVirtual || - MP == MethodKind::PureIntroducingVirtual; - } -}; - -// Does not correspond to any tag, this is the tail of an LF_POINTER record -// if it represents a member pointer. -class MemberPointerInfo { -public: - MemberPointerInfo() = default; - - MemberPointerInfo(TypeIndex ContainingType, - PointerToMemberRepresentation Representation) - : ContainingType(ContainingType), Representation(Representation) {} - - TypeIndex getContainingType() const { return ContainingType; } - PointerToMemberRepresentation getRepresentation() const { - return Representation; - } - - TypeIndex ContainingType; - PointerToMemberRepresentation Representation; -}; - -class TypeRecord { -protected: - TypeRecord() = default; - explicit TypeRecord(TypeRecordKind Kind) : Kind(Kind) {} - -public: - TypeRecordKind getKind() const { return Kind; } - - TypeRecordKind Kind; -}; - -// LF_MODIFIER -class ModifierRecord : public TypeRecord { -public: - ModifierRecord() = default; - explicit ModifierRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - ModifierRecord(TypeIndex ModifiedType, ModifierOptions Modifiers) - : TypeRecord(TypeRecordKind::Modifier), ModifiedType(ModifiedType), - Modifiers(Modifiers) {} - - TypeIndex getModifiedType() const { return ModifiedType; } - ModifierOptions getModifiers() const { return Modifiers; } - - TypeIndex ModifiedType; - ModifierOptions Modifiers; -}; - -// LF_PROCEDURE -class ProcedureRecord : public TypeRecord { -public: - ProcedureRecord() = default; - explicit ProcedureRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - ProcedureRecord(TypeIndex ReturnType, CallingConvention CallConv, - FunctionOptions Options, uint16_t ParameterCount, - TypeIndex ArgumentList) - : TypeRecord(TypeRecordKind::Procedure), ReturnType(ReturnType), - CallConv(CallConv), Options(Options), ParameterCount(ParameterCount), - ArgumentList(ArgumentList) {} - - TypeIndex getReturnType() const { return ReturnType; } - CallingConvention getCallConv() const { return CallConv; } - FunctionOptions getOptions() const { return Options; } - uint16_t getParameterCount() const { return ParameterCount; } - TypeIndex getArgumentList() const { return ArgumentList; } - - TypeIndex ReturnType; - CallingConvention CallConv; - FunctionOptions Options; - uint16_t ParameterCount; - TypeIndex ArgumentList; -}; - -// LF_MFUNCTION -class MemberFunctionRecord : public TypeRecord { -public: - MemberFunctionRecord() = default; - explicit MemberFunctionRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - - MemberFunctionRecord(TypeIndex ReturnType, TypeIndex ClassType, - TypeIndex ThisType, CallingConvention CallConv, - FunctionOptions Options, uint16_t ParameterCount, - TypeIndex ArgumentList, int32_t ThisPointerAdjustment) - : TypeRecord(TypeRecordKind::MemberFunction), ReturnType(ReturnType), - ClassType(ClassType), ThisType(ThisType), CallConv(CallConv), - Options(Options), ParameterCount(ParameterCount), - ArgumentList(ArgumentList), - ThisPointerAdjustment(ThisPointerAdjustment) {} - - TypeIndex getReturnType() const { return ReturnType; } - TypeIndex getClassType() const { return ClassType; } - TypeIndex getThisType() const { return ThisType; } - CallingConvention getCallConv() const { return CallConv; } - FunctionOptions getOptions() const { return Options; } - uint16_t getParameterCount() const { return ParameterCount; } - TypeIndex getArgumentList() const { return ArgumentList; } - int32_t getThisPointerAdjustment() const { return ThisPointerAdjustment; } - - TypeIndex ReturnType; - TypeIndex ClassType; - TypeIndex ThisType; - CallingConvention CallConv; - FunctionOptions Options; - uint16_t ParameterCount; - TypeIndex ArgumentList; - int32_t ThisPointerAdjustment; -}; - -// LF_LABEL -class LabelRecord : public TypeRecord { -public: - LabelRecord() = default; - explicit LabelRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - - LabelRecord(LabelType Mode) : TypeRecord(TypeRecordKind::Label), Mode(Mode) {} - - LabelType Mode; -}; - -// LF_MFUNC_ID -class MemberFuncIdRecord : public TypeRecord { -public: - MemberFuncIdRecord() = default; - explicit MemberFuncIdRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - MemberFuncIdRecord(TypeIndex ClassType, TypeIndex FunctionType, - StringRef Name) - : TypeRecord(TypeRecordKind::MemberFuncId), ClassType(ClassType), - FunctionType(FunctionType), Name(Name) {} - - TypeIndex getClassType() const { return ClassType; } - TypeIndex getFunctionType() const { return FunctionType; } - StringRef getName() const { return Name; } - - TypeIndex ClassType; - TypeIndex FunctionType; - StringRef Name; -}; - -// LF_ARGLIST -class ArgListRecord : public TypeRecord { -public: - ArgListRecord() = default; - explicit ArgListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - - ArgListRecord(TypeRecordKind Kind, ArrayRef Indices) - : TypeRecord(Kind), ArgIndices(Indices) {} - - ArrayRef getIndices() const { return ArgIndices; } - - std::vector ArgIndices; -}; - -// LF_SUBSTR_LIST -class StringListRecord : public TypeRecord { -public: - StringListRecord() = default; - explicit StringListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - - StringListRecord(TypeRecordKind Kind, ArrayRef Indices) - : TypeRecord(Kind), StringIndices(Indices) {} - - ArrayRef getIndices() const { return StringIndices; } - - std::vector StringIndices; -}; - -// LF_POINTER -class PointerRecord : public TypeRecord { -public: - static const uint32_t PointerKindShift = 0; - static const uint32_t PointerKindMask = 0x1F; - - static const uint32_t PointerModeShift = 5; - static const uint32_t PointerModeMask = 0x07; - - static const uint32_t PointerOptionMask = 0xFF; - - static const uint32_t PointerSizeShift = 13; - static const uint32_t PointerSizeMask = 0xFF; - - PointerRecord() = default; - explicit PointerRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - - PointerRecord(TypeIndex ReferentType, uint32_t Attrs) - : TypeRecord(TypeRecordKind::Pointer), ReferentType(ReferentType), - Attrs(Attrs) {} - - PointerRecord(TypeIndex ReferentType, PointerKind PK, PointerMode PM, - PointerOptions PO, uint8_t Size) - : TypeRecord(TypeRecordKind::Pointer), ReferentType(ReferentType), - Attrs(calcAttrs(PK, PM, PO, Size)) {} - - PointerRecord(TypeIndex ReferentType, PointerKind PK, PointerMode PM, - PointerOptions PO, uint8_t Size, const MemberPointerInfo &MPI) - : TypeRecord(TypeRecordKind::Pointer), ReferentType(ReferentType), - Attrs(calcAttrs(PK, PM, PO, Size)), MemberInfo(MPI) {} - - TypeIndex getReferentType() const { return ReferentType; } - - PointerKind getPointerKind() const { - return static_cast((Attrs >> PointerKindShift) & - PointerKindMask); - } - - PointerMode getMode() const { - return static_cast((Attrs >> PointerModeShift) & - PointerModeMask); - } - - PointerOptions getOptions() const { - return static_cast(Attrs); - } - - uint8_t getSize() const { - return (Attrs >> PointerSizeShift) & PointerSizeMask; - } - - MemberPointerInfo getMemberInfo() const { return *MemberInfo; } - - bool isPointerToMember() const { - return getMode() == PointerMode::PointerToDataMember || - getMode() == PointerMode::PointerToMemberFunction; - } - - bool isFlat() const { return !!(Attrs & uint32_t(PointerOptions::Flat32)); } - bool isConst() const { return !!(Attrs & uint32_t(PointerOptions::Const)); } - - bool isVolatile() const { - return !!(Attrs & uint32_t(PointerOptions::Volatile)); - } - - bool isUnaligned() const { - return !!(Attrs & uint32_t(PointerOptions::Unaligned)); - } - - bool isRestrict() const { - return !!(Attrs & uint32_t(PointerOptions::Restrict)); - } - - TypeIndex ReferentType; - uint32_t Attrs; - Optional MemberInfo; - - void setAttrs(PointerKind PK, PointerMode PM, PointerOptions PO, - uint8_t Size) { - Attrs = calcAttrs(PK, PM, PO, Size); - } - -private: - static uint32_t calcAttrs(PointerKind PK, PointerMode PM, PointerOptions PO, - uint8_t Size) { - uint32_t A = 0; - A |= static_cast(PK); - A |= static_cast(PO); - A |= (static_cast(PM) << PointerModeShift); - A |= (static_cast(Size) << PointerSizeShift); - return A; - } -}; - -// LF_NESTTYPE -class NestedTypeRecord : public TypeRecord { -public: - NestedTypeRecord() = default; - explicit NestedTypeRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - NestedTypeRecord(TypeIndex Type, StringRef Name) - : TypeRecord(TypeRecordKind::NestedType), Type(Type), Name(Name) {} - - TypeIndex getNestedType() const { return Type; } - StringRef getName() const { return Name; } - - TypeIndex Type; - StringRef Name; -}; - -// LF_FIELDLIST -class FieldListRecord : public TypeRecord { -public: - FieldListRecord() = default; - explicit FieldListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - explicit FieldListRecord(ArrayRef Data) - : TypeRecord(TypeRecordKind::FieldList), Data(Data) {} - - ArrayRef Data; -}; - -// LF_ARRAY -class ArrayRecord : public TypeRecord { -public: - ArrayRecord() = default; - explicit ArrayRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - ArrayRecord(TypeIndex ElementType, TypeIndex IndexType, uint64_t Size, - StringRef Name) - : TypeRecord(TypeRecordKind::Array), ElementType(ElementType), - IndexType(IndexType), Size(Size), Name(Name) {} - - TypeIndex getElementType() const { return ElementType; } - TypeIndex getIndexType() const { return IndexType; } - uint64_t getSize() const { return Size; } - StringRef getName() const { return Name; } - - TypeIndex ElementType; - TypeIndex IndexType; - uint64_t Size; - StringRef Name; -}; - -class TagRecord : public TypeRecord { -protected: - TagRecord() = default; - explicit TagRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - TagRecord(TypeRecordKind Kind, uint16_t MemberCount, ClassOptions Options, - TypeIndex FieldList, StringRef Name, StringRef UniqueName) - : TypeRecord(Kind), MemberCount(MemberCount), Options(Options), - FieldList(FieldList), Name(Name), UniqueName(UniqueName) {} - -public: - static const int HfaKindShift = 11; - static const int HfaKindMask = 0x1800; - static const int WinRTKindShift = 14; - static const int WinRTKindMask = 0xC000; - - bool hasUniqueName() const { - return (Options & ClassOptions::HasUniqueName) != ClassOptions::None; - } - - bool isNested() const { - return (Options & ClassOptions::Nested) != ClassOptions::None; - } - - bool isForwardRef() const { - return (Options & ClassOptions::ForwardReference) != ClassOptions::None; - } - - uint16_t getMemberCount() const { return MemberCount; } - ClassOptions getOptions() const { return Options; } - TypeIndex getFieldList() const { return FieldList; } - StringRef getName() const { return Name; } - StringRef getUniqueName() const { return UniqueName; } - - uint16_t MemberCount; - ClassOptions Options; - TypeIndex FieldList; - StringRef Name; - StringRef UniqueName; -}; - -// LF_CLASS, LF_STRUCTURE, LF_INTERFACE -class ClassRecord : public TagRecord { -public: - ClassRecord() = default; - explicit ClassRecord(TypeRecordKind Kind) : TagRecord(Kind) {} - ClassRecord(TypeRecordKind Kind, uint16_t MemberCount, ClassOptions Options, - TypeIndex FieldList, TypeIndex DerivationList, - TypeIndex VTableShape, uint64_t Size, StringRef Name, - StringRef UniqueName) - : TagRecord(Kind, MemberCount, Options, FieldList, Name, UniqueName), - DerivationList(DerivationList), VTableShape(VTableShape), Size(Size) {} - - HfaKind getHfa() const { - uint16_t Value = static_cast(Options); - Value = (Value & HfaKindMask) >> HfaKindShift; - return static_cast(Value); - } - - WindowsRTClassKind getWinRTKind() const { - uint16_t Value = static_cast(Options); - Value = (Value & WinRTKindMask) >> WinRTKindShift; - return static_cast(Value); - } - - TypeIndex getDerivationList() const { return DerivationList; } - TypeIndex getVTableShape() const { return VTableShape; } - uint64_t getSize() const { return Size; } - - TypeIndex DerivationList; - TypeIndex VTableShape; - uint64_t Size; -}; - -// LF_UNION -struct UnionRecord : public TagRecord { - UnionRecord() = default; - explicit UnionRecord(TypeRecordKind Kind) : TagRecord(Kind) {} - UnionRecord(uint16_t MemberCount, ClassOptions Options, TypeIndex FieldList, - uint64_t Size, StringRef Name, StringRef UniqueName) - : TagRecord(TypeRecordKind::Union, MemberCount, Options, FieldList, Name, - UniqueName), - Size(Size) {} - - HfaKind getHfa() const { - uint16_t Value = static_cast(Options); - Value = (Value & HfaKindMask) >> HfaKindShift; - return static_cast(Value); - } - - uint64_t getSize() const { return Size; } - - uint64_t Size; -}; - -// LF_ENUM -class EnumRecord : public TagRecord { -public: - EnumRecord() = default; - explicit EnumRecord(TypeRecordKind Kind) : TagRecord(Kind) {} - EnumRecord(uint16_t MemberCount, ClassOptions Options, TypeIndex FieldList, - StringRef Name, StringRef UniqueName, TypeIndex UnderlyingType) - : TagRecord(TypeRecordKind::Enum, MemberCount, Options, FieldList, Name, - UniqueName), - UnderlyingType(UnderlyingType) {} - - TypeIndex getUnderlyingType() const { return UnderlyingType; } - - TypeIndex UnderlyingType; -}; - -// LF_BITFIELD -class BitFieldRecord : public TypeRecord { -public: - BitFieldRecord() = default; - explicit BitFieldRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - BitFieldRecord(TypeIndex Type, uint8_t BitSize, uint8_t BitOffset) - : TypeRecord(TypeRecordKind::BitField), Type(Type), BitSize(BitSize), - BitOffset(BitOffset) {} - - TypeIndex getType() const { return Type; } - uint8_t getBitOffset() const { return BitOffset; } - uint8_t getBitSize() const { return BitSize; } - - TypeIndex Type; - uint8_t BitSize; - uint8_t BitOffset; -}; - -// LF_VTSHAPE -class VFTableShapeRecord : public TypeRecord { -public: - VFTableShapeRecord() = default; - explicit VFTableShapeRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - explicit VFTableShapeRecord(ArrayRef Slots) - : TypeRecord(TypeRecordKind::VFTableShape), SlotsRef(Slots) {} - explicit VFTableShapeRecord(std::vector Slots) - : TypeRecord(TypeRecordKind::VFTableShape), Slots(std::move(Slots)) {} - - ArrayRef getSlots() const { - if (!SlotsRef.empty()) - return SlotsRef; - return Slots; - } - - uint32_t getEntryCount() const { return getSlots().size(); } - - ArrayRef SlotsRef; - std::vector Slots; -}; - -// LF_TYPESERVER2 -class TypeServer2Record : public TypeRecord { -public: - TypeServer2Record() = default; - explicit TypeServer2Record(TypeRecordKind Kind) : TypeRecord(Kind) {} - TypeServer2Record(StringRef GuidStr, uint32_t Age, StringRef Name) - : TypeRecord(TypeRecordKind::TypeServer2), Age(Age), Name(Name) { - assert(GuidStr.size() == 16 && "guid isn't 16 bytes"); - ::memcpy(Guid.Guid, GuidStr.data(), 16); - } - - const GUID &getGuid() const { return Guid; } - uint32_t getAge() const { return Age; } - StringRef getName() const { return Name; } - - GUID Guid; - uint32_t Age; - StringRef Name; -}; - -// LF_STRING_ID -class StringIdRecord : public TypeRecord { -public: - StringIdRecord() = default; - explicit StringIdRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - StringIdRecord(TypeIndex Id, StringRef String) - : TypeRecord(TypeRecordKind::StringId), Id(Id), String(String) {} - - TypeIndex getId() const { return Id; } - StringRef getString() const { return String; } - - TypeIndex Id; - StringRef String; -}; - -// LF_FUNC_ID -class FuncIdRecord : public TypeRecord { -public: - FuncIdRecord() = default; - explicit FuncIdRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - FuncIdRecord(TypeIndex ParentScope, TypeIndex FunctionType, StringRef Name) - : TypeRecord(TypeRecordKind::FuncId), ParentScope(ParentScope), - FunctionType(FunctionType), Name(Name) {} - - TypeIndex getParentScope() const { return ParentScope; } - TypeIndex getFunctionType() const { return FunctionType; } - StringRef getName() const { return Name; } - - TypeIndex ParentScope; - TypeIndex FunctionType; - StringRef Name; -}; - -// LF_UDT_SRC_LINE -class UdtSourceLineRecord : public TypeRecord { -public: - UdtSourceLineRecord() = default; - explicit UdtSourceLineRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - UdtSourceLineRecord(TypeIndex UDT, TypeIndex SourceFile, uint32_t LineNumber) - : TypeRecord(TypeRecordKind::UdtSourceLine), UDT(UDT), - SourceFile(SourceFile), LineNumber(LineNumber) {} - - TypeIndex getUDT() const { return UDT; } - TypeIndex getSourceFile() const { return SourceFile; } - uint32_t getLineNumber() const { return LineNumber; } - - TypeIndex UDT; - TypeIndex SourceFile; - uint32_t LineNumber; -}; - -// LF_UDT_MOD_SRC_LINE -class UdtModSourceLineRecord : public TypeRecord { -public: - UdtModSourceLineRecord() = default; - explicit UdtModSourceLineRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - UdtModSourceLineRecord(TypeIndex UDT, TypeIndex SourceFile, - uint32_t LineNumber, uint16_t Module) - : TypeRecord(TypeRecordKind::UdtSourceLine), UDT(UDT), - SourceFile(SourceFile), LineNumber(LineNumber), Module(Module) {} - - TypeIndex getUDT() const { return UDT; } - TypeIndex getSourceFile() const { return SourceFile; } - uint32_t getLineNumber() const { return LineNumber; } - uint16_t getModule() const { return Module; } - - TypeIndex UDT; - TypeIndex SourceFile; - uint32_t LineNumber; - uint16_t Module; -}; - -// LF_BUILDINFO -class BuildInfoRecord : public TypeRecord { -public: - BuildInfoRecord() = default; - explicit BuildInfoRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - BuildInfoRecord(ArrayRef ArgIndices) - : TypeRecord(TypeRecordKind::BuildInfo), - ArgIndices(ArgIndices.begin(), ArgIndices.end()) {} - - ArrayRef getArgs() const { return ArgIndices; } - - SmallVector ArgIndices; -}; - -// LF_VFTABLE -class VFTableRecord : public TypeRecord { -public: - VFTableRecord() = default; - explicit VFTableRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - VFTableRecord(TypeIndex CompleteClass, TypeIndex OverriddenVFTable, - uint32_t VFPtrOffset, StringRef Name, - ArrayRef Methods) - : TypeRecord(TypeRecordKind::VFTable), CompleteClass(CompleteClass), - OverriddenVFTable(OverriddenVFTable), VFPtrOffset(VFPtrOffset) { - MethodNames.push_back(Name); - MethodNames.insert(MethodNames.end(), Methods.begin(), Methods.end()); - } - - TypeIndex getCompleteClass() const { return CompleteClass; } - TypeIndex getOverriddenVTable() const { return OverriddenVFTable; } - uint32_t getVFPtrOffset() const { return VFPtrOffset; } - StringRef getName() const { return makeArrayRef(MethodNames).front(); } - - ArrayRef getMethodNames() const { - return makeArrayRef(MethodNames).drop_front(); - } - - TypeIndex CompleteClass; - TypeIndex OverriddenVFTable; - uint32_t VFPtrOffset; - std::vector MethodNames; -}; - -// LF_ONEMETHOD -class OneMethodRecord : public TypeRecord { -public: - OneMethodRecord() = default; - explicit OneMethodRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - OneMethodRecord(TypeIndex Type, MemberAttributes Attrs, int32_t VFTableOffset, - StringRef Name) - : TypeRecord(TypeRecordKind::OneMethod), Type(Type), Attrs(Attrs), - VFTableOffset(VFTableOffset), Name(Name) {} - OneMethodRecord(TypeIndex Type, MemberAccess Access, MethodKind MK, - MethodOptions Options, int32_t VFTableOffset, StringRef Name) - : TypeRecord(TypeRecordKind::OneMethod), Type(Type), - Attrs(Access, MK, Options), VFTableOffset(VFTableOffset), Name(Name) {} - - TypeIndex getType() const { return Type; } - MethodKind getMethodKind() const { return Attrs.getMethodKind(); } - MethodOptions getOptions() const { return Attrs.getFlags(); } - MemberAccess getAccess() const { return Attrs.getAccess(); } - int32_t getVFTableOffset() const { return VFTableOffset; } - StringRef getName() const { return Name; } - - bool isIntroducingVirtual() const { - return getMethodKind() == MethodKind::IntroducingVirtual || - getMethodKind() == MethodKind::PureIntroducingVirtual; - } - - TypeIndex Type; - MemberAttributes Attrs; - int32_t VFTableOffset; - StringRef Name; -}; - -// LF_METHODLIST -class MethodOverloadListRecord : public TypeRecord { -public: - MethodOverloadListRecord() = default; - explicit MethodOverloadListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - MethodOverloadListRecord(ArrayRef Methods) - : TypeRecord(TypeRecordKind::MethodOverloadList), Methods(Methods) {} - - ArrayRef getMethods() const { return Methods; } - - std::vector Methods; -}; - -/// For method overload sets. LF_METHOD -class OverloadedMethodRecord : public TypeRecord { -public: - OverloadedMethodRecord() = default; - explicit OverloadedMethodRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - OverloadedMethodRecord(uint16_t NumOverloads, TypeIndex MethodList, - StringRef Name) - : TypeRecord(TypeRecordKind::OverloadedMethod), - NumOverloads(NumOverloads), MethodList(MethodList), Name(Name) {} - - uint16_t getNumOverloads() const { return NumOverloads; } - TypeIndex getMethodList() const { return MethodList; } - StringRef getName() const { return Name; } - - uint16_t NumOverloads; - TypeIndex MethodList; - StringRef Name; -}; - -// LF_MEMBER -class DataMemberRecord : public TypeRecord { -public: - DataMemberRecord() = default; - explicit DataMemberRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - DataMemberRecord(MemberAttributes Attrs, TypeIndex Type, uint64_t Offset, - StringRef Name) - : TypeRecord(TypeRecordKind::DataMember), Attrs(Attrs), Type(Type), - FieldOffset(Offset), Name(Name) {} - DataMemberRecord(MemberAccess Access, TypeIndex Type, uint64_t Offset, - StringRef Name) - : TypeRecord(TypeRecordKind::DataMember), Attrs(Access), Type(Type), - FieldOffset(Offset), Name(Name) {} - - MemberAccess getAccess() const { return Attrs.getAccess(); } - TypeIndex getType() const { return Type; } - uint64_t getFieldOffset() const { return FieldOffset; } - StringRef getName() const { return Name; } - - MemberAttributes Attrs; - TypeIndex Type; - uint64_t FieldOffset; - StringRef Name; -}; - -// LF_STMEMBER -class StaticDataMemberRecord : public TypeRecord { -public: - StaticDataMemberRecord() = default; - explicit StaticDataMemberRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - StaticDataMemberRecord(MemberAttributes Attrs, TypeIndex Type, StringRef Name) - : TypeRecord(TypeRecordKind::StaticDataMember), Attrs(Attrs), Type(Type), - Name(Name) {} - StaticDataMemberRecord(MemberAccess Access, TypeIndex Type, StringRef Name) - : TypeRecord(TypeRecordKind::StaticDataMember), Attrs(Access), Type(Type), - Name(Name) {} - - MemberAccess getAccess() const { return Attrs.getAccess(); } - TypeIndex getType() const { return Type; } - StringRef getName() const { return Name; } - - MemberAttributes Attrs; - TypeIndex Type; - StringRef Name; -}; - -// LF_ENUMERATE -class EnumeratorRecord : public TypeRecord { -public: - EnumeratorRecord() = default; - explicit EnumeratorRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - EnumeratorRecord(MemberAttributes Attrs, APSInt Value, StringRef Name) - : TypeRecord(TypeRecordKind::Enumerator), Attrs(Attrs), - Value(std::move(Value)), Name(Name) {} - EnumeratorRecord(MemberAccess Access, APSInt Value, StringRef Name) - : TypeRecord(TypeRecordKind::Enumerator), Attrs(Access), - Value(std::move(Value)), Name(Name) {} - - MemberAccess getAccess() const { return Attrs.getAccess(); } - APSInt getValue() const { return Value; } - StringRef getName() const { return Name; } - - MemberAttributes Attrs; - APSInt Value; - StringRef Name; -}; - -// LF_VFUNCTAB -class VFPtrRecord : public TypeRecord { -public: - VFPtrRecord() = default; - explicit VFPtrRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - VFPtrRecord(TypeIndex Type) - : TypeRecord(TypeRecordKind::VFPtr), Type(Type) {} - - TypeIndex getType() const { return Type; } - - TypeIndex Type; -}; - -// LF_BCLASS, LF_BINTERFACE -class BaseClassRecord : public TypeRecord { -public: - BaseClassRecord() = default; - explicit BaseClassRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - BaseClassRecord(MemberAttributes Attrs, TypeIndex Type, uint64_t Offset) - : TypeRecord(TypeRecordKind::BaseClass), Attrs(Attrs), Type(Type), - Offset(Offset) {} - BaseClassRecord(MemberAccess Access, TypeIndex Type, uint64_t Offset) - : TypeRecord(TypeRecordKind::BaseClass), Attrs(Access), Type(Type), - Offset(Offset) {} - - MemberAccess getAccess() const { return Attrs.getAccess(); } - TypeIndex getBaseType() const { return Type; } - uint64_t getBaseOffset() const { return Offset; } - - MemberAttributes Attrs; - TypeIndex Type; - uint64_t Offset; -}; - -// LF_VBCLASS, LF_IVBCLASS -class VirtualBaseClassRecord : public TypeRecord { -public: - VirtualBaseClassRecord() = default; - explicit VirtualBaseClassRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - VirtualBaseClassRecord(TypeRecordKind Kind, MemberAttributes Attrs, - TypeIndex BaseType, TypeIndex VBPtrType, - uint64_t Offset, uint64_t Index) - : TypeRecord(Kind), Attrs(Attrs), BaseType(BaseType), - VBPtrType(VBPtrType), VBPtrOffset(Offset), VTableIndex(Index) {} - VirtualBaseClassRecord(TypeRecordKind Kind, MemberAccess Access, - TypeIndex BaseType, TypeIndex VBPtrType, - uint64_t Offset, uint64_t Index) - : TypeRecord(Kind), Attrs(Access), BaseType(BaseType), - VBPtrType(VBPtrType), VBPtrOffset(Offset), VTableIndex(Index) {} - - MemberAccess getAccess() const { return Attrs.getAccess(); } - TypeIndex getBaseType() const { return BaseType; } - TypeIndex getVBPtrType() const { return VBPtrType; } - uint64_t getVBPtrOffset() const { return VBPtrOffset; } - uint64_t getVTableIndex() const { return VTableIndex; } - - MemberAttributes Attrs; - TypeIndex BaseType; - TypeIndex VBPtrType; - uint64_t VBPtrOffset; - uint64_t VTableIndex; -}; - -/// LF_INDEX - Used to chain two large LF_FIELDLIST or LF_METHODLIST records -/// together. The first will end in an LF_INDEX record that points to the next. -class ListContinuationRecord : public TypeRecord { -public: - ListContinuationRecord() = default; - explicit ListContinuationRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} - ListContinuationRecord(TypeIndex ContinuationIndex) - : TypeRecord(TypeRecordKind::ListContinuation), - ContinuationIndex(ContinuationIndex) {} - - TypeIndex getContinuationIndex() const { return ContinuationIndex; } - - TypeIndex ContinuationIndex; -}; - -} // end namespace codeview -} // end namespace llvm - -#endif // LLVM_DEBUGINFO_CODEVIEW_TYPERECORD_H +//===- TypeRecord.h ---------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_DEBUGINFO_CODEVIEW_TYPERECORD_H +#define LLVM_DEBUGINFO_CODEVIEW_TYPERECORD_H + +#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/DebugInfo/CodeView/CVRecord.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/GUID.h" +#include "llvm/DebugInfo/CodeView/TypeIndex.h" +#include "llvm/Support/BinaryStreamArray.h" +#include "llvm/Support/Endian.h" +#include +#include +#include + +namespace llvm { +namespace codeview { + +using support::little32_t; +using support::ulittle16_t; +using support::ulittle32_t; + +using CVType = CVRecord; +using RemappedType = RemappedRecord; + +struct CVMemberRecord { + TypeLeafKind Kind; + ArrayRef Data; +}; +using CVTypeArray = VarStreamArray; +using CVTypeRange = iterator_range; + +/// Equvalent to CV_fldattr_t in cvinfo.h. +struct MemberAttributes { + uint16_t Attrs = 0; + + enum { + MethodKindShift = 2, + }; + + MemberAttributes() = default; + + explicit MemberAttributes(MemberAccess Access) + : Attrs(static_cast(Access)) {} + + MemberAttributes(MemberAccess Access, MethodKind Kind, MethodOptions Flags) { + Attrs = static_cast(Access); + Attrs |= (static_cast(Kind) << MethodKindShift); + Attrs |= static_cast(Flags); + } + + /// Get the access specifier. Valid for any kind of member. + MemberAccess getAccess() const { + return MemberAccess(unsigned(Attrs) & unsigned(MethodOptions::AccessMask)); + } + + /// Indicates if a method is defined with friend, virtual, static, etc. + MethodKind getMethodKind() const { + return MethodKind( + (unsigned(Attrs) & unsigned(MethodOptions::MethodKindMask)) >> + MethodKindShift); + } + + /// Get the flags that are not included in access control or method + /// properties. + MethodOptions getFlags() const { + return MethodOptions( + unsigned(Attrs) & + ~unsigned(MethodOptions::AccessMask | MethodOptions::MethodKindMask)); + } + + /// Is this method virtual. + bool isVirtual() const { + auto MP = getMethodKind(); + return MP != MethodKind::Vanilla && MP != MethodKind::Friend && + MP != MethodKind::Static; + } + + /// Does this member introduce a new virtual method. + bool isIntroducedVirtual() const { + auto MP = getMethodKind(); + return MP == MethodKind::IntroducingVirtual || + MP == MethodKind::PureIntroducingVirtual; + } +}; + +// Does not correspond to any tag, this is the tail of an LF_POINTER record +// if it represents a member pointer. +class MemberPointerInfo { +public: + MemberPointerInfo() = default; + + MemberPointerInfo(TypeIndex ContainingType, + PointerToMemberRepresentation Representation) + : ContainingType(ContainingType), Representation(Representation) {} + + TypeIndex getContainingType() const { return ContainingType; } + PointerToMemberRepresentation getRepresentation() const { + return Representation; + } + + TypeIndex ContainingType; + PointerToMemberRepresentation Representation; +}; + +class TypeRecord { +protected: + TypeRecord() = default; + explicit TypeRecord(TypeRecordKind Kind) : Kind(Kind) {} + +public: + TypeRecordKind getKind() const { return Kind; } + + TypeRecordKind Kind; +}; + +// LF_MODIFIER +class ModifierRecord : public TypeRecord { +public: + ModifierRecord() = default; + explicit ModifierRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + ModifierRecord(TypeIndex ModifiedType, ModifierOptions Modifiers) + : TypeRecord(TypeRecordKind::Modifier), ModifiedType(ModifiedType), + Modifiers(Modifiers) {} + + TypeIndex getModifiedType() const { return ModifiedType; } + ModifierOptions getModifiers() const { return Modifiers; } + + TypeIndex ModifiedType; + ModifierOptions Modifiers; +}; + +// LF_PROCEDURE +class ProcedureRecord : public TypeRecord { +public: + ProcedureRecord() = default; + explicit ProcedureRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + ProcedureRecord(TypeIndex ReturnType, CallingConvention CallConv, + FunctionOptions Options, uint16_t ParameterCount, + TypeIndex ArgumentList) + : TypeRecord(TypeRecordKind::Procedure), ReturnType(ReturnType), + CallConv(CallConv), Options(Options), ParameterCount(ParameterCount), + ArgumentList(ArgumentList) {} + + TypeIndex getReturnType() const { return ReturnType; } + CallingConvention getCallConv() const { return CallConv; } + FunctionOptions getOptions() const { return Options; } + uint16_t getParameterCount() const { return ParameterCount; } + TypeIndex getArgumentList() const { return ArgumentList; } + + TypeIndex ReturnType; + CallingConvention CallConv; + FunctionOptions Options; + uint16_t ParameterCount; + TypeIndex ArgumentList; +}; + +// LF_MFUNCTION +class MemberFunctionRecord : public TypeRecord { +public: + MemberFunctionRecord() = default; + explicit MemberFunctionRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + + MemberFunctionRecord(TypeIndex ReturnType, TypeIndex ClassType, + TypeIndex ThisType, CallingConvention CallConv, + FunctionOptions Options, uint16_t ParameterCount, + TypeIndex ArgumentList, int32_t ThisPointerAdjustment) + : TypeRecord(TypeRecordKind::MemberFunction), ReturnType(ReturnType), + ClassType(ClassType), ThisType(ThisType), CallConv(CallConv), + Options(Options), ParameterCount(ParameterCount), + ArgumentList(ArgumentList), + ThisPointerAdjustment(ThisPointerAdjustment) {} + + TypeIndex getReturnType() const { return ReturnType; } + TypeIndex getClassType() const { return ClassType; } + TypeIndex getThisType() const { return ThisType; } + CallingConvention getCallConv() const { return CallConv; } + FunctionOptions getOptions() const { return Options; } + uint16_t getParameterCount() const { return ParameterCount; } + TypeIndex getArgumentList() const { return ArgumentList; } + int32_t getThisPointerAdjustment() const { return ThisPointerAdjustment; } + + TypeIndex ReturnType; + TypeIndex ClassType; + TypeIndex ThisType; + CallingConvention CallConv; + FunctionOptions Options; + uint16_t ParameterCount; + TypeIndex ArgumentList; + int32_t ThisPointerAdjustment; +}; + +// LF_LABEL +class LabelRecord : public TypeRecord { +public: + LabelRecord() = default; + explicit LabelRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + + LabelRecord(LabelType Mode) : TypeRecord(TypeRecordKind::Label), Mode(Mode) {} + + LabelType Mode; +}; + +// LF_MFUNC_ID +class MemberFuncIdRecord : public TypeRecord { +public: + MemberFuncIdRecord() = default; + explicit MemberFuncIdRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + MemberFuncIdRecord(TypeIndex ClassType, TypeIndex FunctionType, + StringRef Name) + : TypeRecord(TypeRecordKind::MemberFuncId), ClassType(ClassType), + FunctionType(FunctionType), Name(Name) {} + + TypeIndex getClassType() const { return ClassType; } + TypeIndex getFunctionType() const { return FunctionType; } + StringRef getName() const { return Name; } + + TypeIndex ClassType; + TypeIndex FunctionType; + StringRef Name; +}; + +// LF_ARGLIST +class ArgListRecord : public TypeRecord { +public: + ArgListRecord() = default; + explicit ArgListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + + ArgListRecord(TypeRecordKind Kind, ArrayRef Indices) + : TypeRecord(Kind), ArgIndices(Indices) {} + + ArrayRef getIndices() const { return ArgIndices; } + + std::vector ArgIndices; +}; + +// LF_SUBSTR_LIST +class StringListRecord : public TypeRecord { +public: + StringListRecord() = default; + explicit StringListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + + StringListRecord(TypeRecordKind Kind, ArrayRef Indices) + : TypeRecord(Kind), StringIndices(Indices) {} + + ArrayRef getIndices() const { return StringIndices; } + + std::vector StringIndices; +}; + +// LF_POINTER +class PointerRecord : public TypeRecord { +public: + static const uint32_t PointerKindShift = 0; + static const uint32_t PointerKindMask = 0x1F; + + static const uint32_t PointerModeShift = 5; + static const uint32_t PointerModeMask = 0x07; + + static const uint32_t PointerOptionMask = 0xFF; + + static const uint32_t PointerSizeShift = 13; + static const uint32_t PointerSizeMask = 0xFF; + + PointerRecord() = default; + explicit PointerRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + + PointerRecord(TypeIndex ReferentType, uint32_t Attrs) + : TypeRecord(TypeRecordKind::Pointer), ReferentType(ReferentType), + Attrs(Attrs) {} + + PointerRecord(TypeIndex ReferentType, PointerKind PK, PointerMode PM, + PointerOptions PO, uint8_t Size) + : TypeRecord(TypeRecordKind::Pointer), ReferentType(ReferentType), + Attrs(calcAttrs(PK, PM, PO, Size)) {} + + PointerRecord(TypeIndex ReferentType, PointerKind PK, PointerMode PM, + PointerOptions PO, uint8_t Size, const MemberPointerInfo &MPI) + : TypeRecord(TypeRecordKind::Pointer), ReferentType(ReferentType), + Attrs(calcAttrs(PK, PM, PO, Size)), MemberInfo(MPI) {} + + TypeIndex getReferentType() const { return ReferentType; } + + PointerKind getPointerKind() const { + return static_cast((Attrs >> PointerKindShift) & + PointerKindMask); + } + + PointerMode getMode() const { + return static_cast((Attrs >> PointerModeShift) & + PointerModeMask); + } + + PointerOptions getOptions() const { + return static_cast(Attrs); + } + + uint8_t getSize() const { + return (Attrs >> PointerSizeShift) & PointerSizeMask; + } + + MemberPointerInfo getMemberInfo() const { return *MemberInfo; } + + bool isPointerToMember() const { + return getMode() == PointerMode::PointerToDataMember || + getMode() == PointerMode::PointerToMemberFunction; + } + + bool isFlat() const { return !!(Attrs & uint32_t(PointerOptions::Flat32)); } + bool isConst() const { return !!(Attrs & uint32_t(PointerOptions::Const)); } + + bool isVolatile() const { + return !!(Attrs & uint32_t(PointerOptions::Volatile)); + } + + bool isUnaligned() const { + return !!(Attrs & uint32_t(PointerOptions::Unaligned)); + } + + bool isRestrict() const { + return !!(Attrs & uint32_t(PointerOptions::Restrict)); + } + + TypeIndex ReferentType; + uint32_t Attrs; + Optional MemberInfo; + + void setAttrs(PointerKind PK, PointerMode PM, PointerOptions PO, + uint8_t Size) { + Attrs = calcAttrs(PK, PM, PO, Size); + } + +private: + static uint32_t calcAttrs(PointerKind PK, PointerMode PM, PointerOptions PO, + uint8_t Size) { + uint32_t A = 0; + A |= static_cast(PK); + A |= static_cast(PO); + A |= (static_cast(PM) << PointerModeShift); + A |= (static_cast(Size) << PointerSizeShift); + return A; + } +}; + +// LF_NESTTYPE +class NestedTypeRecord : public TypeRecord { +public: + NestedTypeRecord() = default; + explicit NestedTypeRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + NestedTypeRecord(TypeIndex Type, StringRef Name) + : TypeRecord(TypeRecordKind::NestedType), Type(Type), Name(Name) {} + + TypeIndex getNestedType() const { return Type; } + StringRef getName() const { return Name; } + + TypeIndex Type; + StringRef Name; +}; + +// LF_FIELDLIST +class FieldListRecord : public TypeRecord { +public: + FieldListRecord() = default; + explicit FieldListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + explicit FieldListRecord(ArrayRef Data) + : TypeRecord(TypeRecordKind::FieldList), Data(Data) {} + + ArrayRef Data; +}; + +// LF_ARRAY +class ArrayRecord : public TypeRecord { +public: + ArrayRecord() = default; + explicit ArrayRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + ArrayRecord(TypeIndex ElementType, TypeIndex IndexType, uint64_t Size, + StringRef Name) + : TypeRecord(TypeRecordKind::Array), ElementType(ElementType), + IndexType(IndexType), Size(Size), Name(Name) {} + + TypeIndex getElementType() const { return ElementType; } + TypeIndex getIndexType() const { return IndexType; } + uint64_t getSize() const { return Size; } + StringRef getName() const { return Name; } + + TypeIndex ElementType; + TypeIndex IndexType; + uint64_t Size; + StringRef Name; +}; + +class TagRecord : public TypeRecord { +protected: + TagRecord() = default; + explicit TagRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + TagRecord(TypeRecordKind Kind, uint16_t MemberCount, ClassOptions Options, + TypeIndex FieldList, StringRef Name, StringRef UniqueName) + : TypeRecord(Kind), MemberCount(MemberCount), Options(Options), + FieldList(FieldList), Name(Name), UniqueName(UniqueName) {} + +public: + static const int HfaKindShift = 11; + static const int HfaKindMask = 0x1800; + static const int WinRTKindShift = 14; + static const int WinRTKindMask = 0xC000; + + bool hasUniqueName() const { + return (Options & ClassOptions::HasUniqueName) != ClassOptions::None; + } + + bool isNested() const { + return (Options & ClassOptions::Nested) != ClassOptions::None; + } + + bool isForwardRef() const { + return (Options & ClassOptions::ForwardReference) != ClassOptions::None; + } + + uint16_t getMemberCount() const { return MemberCount; } + ClassOptions getOptions() const { return Options; } + TypeIndex getFieldList() const { return FieldList; } + StringRef getName() const { return Name; } + StringRef getUniqueName() const { return UniqueName; } + + uint16_t MemberCount; + ClassOptions Options; + TypeIndex FieldList; + StringRef Name; + StringRef UniqueName; +}; + +// LF_CLASS, LF_STRUCTURE, LF_INTERFACE +class ClassRecord : public TagRecord { +public: + ClassRecord() = default; + explicit ClassRecord(TypeRecordKind Kind) : TagRecord(Kind) {} + ClassRecord(TypeRecordKind Kind, uint16_t MemberCount, ClassOptions Options, + TypeIndex FieldList, TypeIndex DerivationList, + TypeIndex VTableShape, uint64_t Size, StringRef Name, + StringRef UniqueName) + : TagRecord(Kind, MemberCount, Options, FieldList, Name, UniqueName), + DerivationList(DerivationList), VTableShape(VTableShape), Size(Size) {} + + HfaKind getHfa() const { + uint16_t Value = static_cast(Options); + Value = (Value & HfaKindMask) >> HfaKindShift; + return static_cast(Value); + } + + WindowsRTClassKind getWinRTKind() const { + uint16_t Value = static_cast(Options); + Value = (Value & WinRTKindMask) >> WinRTKindShift; + return static_cast(Value); + } + + TypeIndex getDerivationList() const { return DerivationList; } + TypeIndex getVTableShape() const { return VTableShape; } + uint64_t getSize() const { return Size; } + + TypeIndex DerivationList; + TypeIndex VTableShape; + uint64_t Size; +}; + +// LF_UNION +struct UnionRecord : public TagRecord { + UnionRecord() = default; + explicit UnionRecord(TypeRecordKind Kind) : TagRecord(Kind) {} + UnionRecord(uint16_t MemberCount, ClassOptions Options, TypeIndex FieldList, + uint64_t Size, StringRef Name, StringRef UniqueName) + : TagRecord(TypeRecordKind::Union, MemberCount, Options, FieldList, Name, + UniqueName), + Size(Size) {} + + HfaKind getHfa() const { + uint16_t Value = static_cast(Options); + Value = (Value & HfaKindMask) >> HfaKindShift; + return static_cast(Value); + } + + uint64_t getSize() const { return Size; } + + uint64_t Size; +}; + +// LF_ENUM +class EnumRecord : public TagRecord { +public: + EnumRecord() = default; + explicit EnumRecord(TypeRecordKind Kind) : TagRecord(Kind) {} + EnumRecord(uint16_t MemberCount, ClassOptions Options, TypeIndex FieldList, + StringRef Name, StringRef UniqueName, TypeIndex UnderlyingType) + : TagRecord(TypeRecordKind::Enum, MemberCount, Options, FieldList, Name, + UniqueName), + UnderlyingType(UnderlyingType) {} + + TypeIndex getUnderlyingType() const { return UnderlyingType; } + + TypeIndex UnderlyingType; +}; + +// LF_BITFIELD +class BitFieldRecord : public TypeRecord { +public: + BitFieldRecord() = default; + explicit BitFieldRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + BitFieldRecord(TypeIndex Type, uint8_t BitSize, uint8_t BitOffset) + : TypeRecord(TypeRecordKind::BitField), Type(Type), BitSize(BitSize), + BitOffset(BitOffset) {} + + TypeIndex getType() const { return Type; } + uint8_t getBitOffset() const { return BitOffset; } + uint8_t getBitSize() const { return BitSize; } + + TypeIndex Type; + uint8_t BitSize; + uint8_t BitOffset; +}; + +// LF_VTSHAPE +class VFTableShapeRecord : public TypeRecord { +public: + VFTableShapeRecord() = default; + explicit VFTableShapeRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + explicit VFTableShapeRecord(ArrayRef Slots) + : TypeRecord(TypeRecordKind::VFTableShape), SlotsRef(Slots) {} + explicit VFTableShapeRecord(std::vector Slots) + : TypeRecord(TypeRecordKind::VFTableShape), Slots(std::move(Slots)) {} + + ArrayRef getSlots() const { + if (!SlotsRef.empty()) + return SlotsRef; + return Slots; + } + + uint32_t getEntryCount() const { return getSlots().size(); } + + ArrayRef SlotsRef; + std::vector Slots; +}; + +// LF_TYPESERVER2 +class TypeServer2Record : public TypeRecord { +public: + TypeServer2Record() = default; + explicit TypeServer2Record(TypeRecordKind Kind) : TypeRecord(Kind) {} + TypeServer2Record(StringRef GuidStr, uint32_t Age, StringRef Name) + : TypeRecord(TypeRecordKind::TypeServer2), Age(Age), Name(Name) { + assert(GuidStr.size() == 16 && "guid isn't 16 bytes"); + ::memcpy(Guid.Guid, GuidStr.data(), 16); + } + + const GUID &getGuid() const { return Guid; } + uint32_t getAge() const { return Age; } + StringRef getName() const { return Name; } + + GUID Guid; + uint32_t Age; + StringRef Name; +}; + +// LF_STRING_ID +class StringIdRecord : public TypeRecord { +public: + StringIdRecord() = default; + explicit StringIdRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + StringIdRecord(TypeIndex Id, StringRef String) + : TypeRecord(TypeRecordKind::StringId), Id(Id), String(String) {} + + TypeIndex getId() const { return Id; } + StringRef getString() const { return String; } + + TypeIndex Id; + StringRef String; +}; + +// LF_FUNC_ID +class FuncIdRecord : public TypeRecord { +public: + FuncIdRecord() = default; + explicit FuncIdRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + FuncIdRecord(TypeIndex ParentScope, TypeIndex FunctionType, StringRef Name) + : TypeRecord(TypeRecordKind::FuncId), ParentScope(ParentScope), + FunctionType(FunctionType), Name(Name) {} + + TypeIndex getParentScope() const { return ParentScope; } + TypeIndex getFunctionType() const { return FunctionType; } + StringRef getName() const { return Name; } + + TypeIndex ParentScope; + TypeIndex FunctionType; + StringRef Name; +}; + +// LF_UDT_SRC_LINE +class UdtSourceLineRecord : public TypeRecord { +public: + UdtSourceLineRecord() = default; + explicit UdtSourceLineRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + UdtSourceLineRecord(TypeIndex UDT, TypeIndex SourceFile, uint32_t LineNumber) + : TypeRecord(TypeRecordKind::UdtSourceLine), UDT(UDT), + SourceFile(SourceFile), LineNumber(LineNumber) {} + + TypeIndex getUDT() const { return UDT; } + TypeIndex getSourceFile() const { return SourceFile; } + uint32_t getLineNumber() const { return LineNumber; } + + TypeIndex UDT; + TypeIndex SourceFile; + uint32_t LineNumber; +}; + +// LF_UDT_MOD_SRC_LINE +class UdtModSourceLineRecord : public TypeRecord { +public: + UdtModSourceLineRecord() = default; + explicit UdtModSourceLineRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + UdtModSourceLineRecord(TypeIndex UDT, TypeIndex SourceFile, + uint32_t LineNumber, uint16_t Module) + : TypeRecord(TypeRecordKind::UdtSourceLine), UDT(UDT), + SourceFile(SourceFile), LineNumber(LineNumber), Module(Module) {} + + TypeIndex getUDT() const { return UDT; } + TypeIndex getSourceFile() const { return SourceFile; } + uint32_t getLineNumber() const { return LineNumber; } + uint16_t getModule() const { return Module; } + + TypeIndex UDT; + TypeIndex SourceFile; + uint32_t LineNumber; + uint16_t Module; +}; + +// LF_BUILDINFO +class BuildInfoRecord : public TypeRecord { +public: + BuildInfoRecord() = default; + explicit BuildInfoRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + BuildInfoRecord(ArrayRef ArgIndices) + : TypeRecord(TypeRecordKind::BuildInfo), + ArgIndices(ArgIndices.begin(), ArgIndices.end()) {} + + ArrayRef getArgs() const { return ArgIndices; } + + SmallVector ArgIndices; +}; + +// LF_VFTABLE +class VFTableRecord : public TypeRecord { +public: + VFTableRecord() = default; + explicit VFTableRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + VFTableRecord(TypeIndex CompleteClass, TypeIndex OverriddenVFTable, + uint32_t VFPtrOffset, StringRef Name, + ArrayRef Methods) + : TypeRecord(TypeRecordKind::VFTable), CompleteClass(CompleteClass), + OverriddenVFTable(OverriddenVFTable), VFPtrOffset(VFPtrOffset) { + MethodNames.push_back(Name); + MethodNames.insert(MethodNames.end(), Methods.begin(), Methods.end()); + } + + TypeIndex getCompleteClass() const { return CompleteClass; } + TypeIndex getOverriddenVTable() const { return OverriddenVFTable; } + uint32_t getVFPtrOffset() const { return VFPtrOffset; } + StringRef getName() const { return makeArrayRef(MethodNames).front(); } + + ArrayRef getMethodNames() const { + return makeArrayRef(MethodNames).drop_front(); + } + + TypeIndex CompleteClass; + TypeIndex OverriddenVFTable; + uint32_t VFPtrOffset; + std::vector MethodNames; +}; + +// LF_ONEMETHOD +class OneMethodRecord : public TypeRecord { +public: + OneMethodRecord() = default; + explicit OneMethodRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + OneMethodRecord(TypeIndex Type, MemberAttributes Attrs, int32_t VFTableOffset, + StringRef Name) + : TypeRecord(TypeRecordKind::OneMethod), Type(Type), Attrs(Attrs), + VFTableOffset(VFTableOffset), Name(Name) {} + OneMethodRecord(TypeIndex Type, MemberAccess Access, MethodKind MK, + MethodOptions Options, int32_t VFTableOffset, StringRef Name) + : TypeRecord(TypeRecordKind::OneMethod), Type(Type), + Attrs(Access, MK, Options), VFTableOffset(VFTableOffset), Name(Name) {} + + TypeIndex getType() const { return Type; } + MethodKind getMethodKind() const { return Attrs.getMethodKind(); } + MethodOptions getOptions() const { return Attrs.getFlags(); } + MemberAccess getAccess() const { return Attrs.getAccess(); } + int32_t getVFTableOffset() const { return VFTableOffset; } + StringRef getName() const { return Name; } + + bool isIntroducingVirtual() const { + return getMethodKind() == MethodKind::IntroducingVirtual || + getMethodKind() == MethodKind::PureIntroducingVirtual; + } + + TypeIndex Type; + MemberAttributes Attrs; + int32_t VFTableOffset; + StringRef Name; +}; + +// LF_METHODLIST +class MethodOverloadListRecord : public TypeRecord { +public: + MethodOverloadListRecord() = default; + explicit MethodOverloadListRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + MethodOverloadListRecord(ArrayRef Methods) + : TypeRecord(TypeRecordKind::MethodOverloadList), Methods(Methods) {} + + ArrayRef getMethods() const { return Methods; } + + std::vector Methods; +}; + +/// For method overload sets. LF_METHOD +class OverloadedMethodRecord : public TypeRecord { +public: + OverloadedMethodRecord() = default; + explicit OverloadedMethodRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + OverloadedMethodRecord(uint16_t NumOverloads, TypeIndex MethodList, + StringRef Name) + : TypeRecord(TypeRecordKind::OverloadedMethod), + NumOverloads(NumOverloads), MethodList(MethodList), Name(Name) {} + + uint16_t getNumOverloads() const { return NumOverloads; } + TypeIndex getMethodList() const { return MethodList; } + StringRef getName() const { return Name; } + + uint16_t NumOverloads; + TypeIndex MethodList; + StringRef Name; +}; + +// LF_MEMBER +class DataMemberRecord : public TypeRecord { +public: + DataMemberRecord() = default; + explicit DataMemberRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + DataMemberRecord(MemberAttributes Attrs, TypeIndex Type, uint64_t Offset, + StringRef Name) + : TypeRecord(TypeRecordKind::DataMember), Attrs(Attrs), Type(Type), + FieldOffset(Offset), Name(Name) {} + DataMemberRecord(MemberAccess Access, TypeIndex Type, uint64_t Offset, + StringRef Name) + : TypeRecord(TypeRecordKind::DataMember), Attrs(Access), Type(Type), + FieldOffset(Offset), Name(Name) {} + + MemberAccess getAccess() const { return Attrs.getAccess(); } + TypeIndex getType() const { return Type; } + uint64_t getFieldOffset() const { return FieldOffset; } + StringRef getName() const { return Name; } + + MemberAttributes Attrs; + TypeIndex Type; + uint64_t FieldOffset; + StringRef Name; +}; + +// LF_STMEMBER +class StaticDataMemberRecord : public TypeRecord { +public: + StaticDataMemberRecord() = default; + explicit StaticDataMemberRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + StaticDataMemberRecord(MemberAttributes Attrs, TypeIndex Type, StringRef Name) + : TypeRecord(TypeRecordKind::StaticDataMember), Attrs(Attrs), Type(Type), + Name(Name) {} + StaticDataMemberRecord(MemberAccess Access, TypeIndex Type, StringRef Name) + : TypeRecord(TypeRecordKind::StaticDataMember), Attrs(Access), Type(Type), + Name(Name) {} + + MemberAccess getAccess() const { return Attrs.getAccess(); } + TypeIndex getType() const { return Type; } + StringRef getName() const { return Name; } + + MemberAttributes Attrs; + TypeIndex Type; + StringRef Name; +}; + +// LF_ENUMERATE +class EnumeratorRecord : public TypeRecord { +public: + EnumeratorRecord() = default; + explicit EnumeratorRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + EnumeratorRecord(MemberAttributes Attrs, APSInt Value, StringRef Name) + : TypeRecord(TypeRecordKind::Enumerator), Attrs(Attrs), + Value(std::move(Value)), Name(Name) {} + EnumeratorRecord(MemberAccess Access, APSInt Value, StringRef Name) + : TypeRecord(TypeRecordKind::Enumerator), Attrs(Access), + Value(std::move(Value)), Name(Name) {} + + MemberAccess getAccess() const { return Attrs.getAccess(); } + APSInt getValue() const { return Value; } + StringRef getName() const { return Name; } + + MemberAttributes Attrs; + APSInt Value; + StringRef Name; +}; + +// LF_VFUNCTAB +class VFPtrRecord : public TypeRecord { +public: + VFPtrRecord() = default; + explicit VFPtrRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + VFPtrRecord(TypeIndex Type) + : TypeRecord(TypeRecordKind::VFPtr), Type(Type) {} + + TypeIndex getType() const { return Type; } + + TypeIndex Type; +}; + +// LF_BCLASS, LF_BINTERFACE +class BaseClassRecord : public TypeRecord { +public: + BaseClassRecord() = default; + explicit BaseClassRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + BaseClassRecord(MemberAttributes Attrs, TypeIndex Type, uint64_t Offset) + : TypeRecord(TypeRecordKind::BaseClass), Attrs(Attrs), Type(Type), + Offset(Offset) {} + BaseClassRecord(MemberAccess Access, TypeIndex Type, uint64_t Offset) + : TypeRecord(TypeRecordKind::BaseClass), Attrs(Access), Type(Type), + Offset(Offset) {} + + MemberAccess getAccess() const { return Attrs.getAccess(); } + TypeIndex getBaseType() const { return Type; } + uint64_t getBaseOffset() const { return Offset; } + + MemberAttributes Attrs; + TypeIndex Type; + uint64_t Offset; +}; + +// LF_VBCLASS, LF_IVBCLASS +class VirtualBaseClassRecord : public TypeRecord { +public: + VirtualBaseClassRecord() = default; + explicit VirtualBaseClassRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + VirtualBaseClassRecord(TypeRecordKind Kind, MemberAttributes Attrs, + TypeIndex BaseType, TypeIndex VBPtrType, + uint64_t Offset, uint64_t Index) + : TypeRecord(Kind), Attrs(Attrs), BaseType(BaseType), + VBPtrType(VBPtrType), VBPtrOffset(Offset), VTableIndex(Index) {} + VirtualBaseClassRecord(TypeRecordKind Kind, MemberAccess Access, + TypeIndex BaseType, TypeIndex VBPtrType, + uint64_t Offset, uint64_t Index) + : TypeRecord(Kind), Attrs(Access), BaseType(BaseType), + VBPtrType(VBPtrType), VBPtrOffset(Offset), VTableIndex(Index) {} + + MemberAccess getAccess() const { return Attrs.getAccess(); } + TypeIndex getBaseType() const { return BaseType; } + TypeIndex getVBPtrType() const { return VBPtrType; } + uint64_t getVBPtrOffset() const { return VBPtrOffset; } + uint64_t getVTableIndex() const { return VTableIndex; } + + MemberAttributes Attrs; + TypeIndex BaseType; + TypeIndex VBPtrType; + uint64_t VBPtrOffset; + uint64_t VTableIndex; +}; + +/// LF_INDEX - Used to chain two large LF_FIELDLIST or LF_METHODLIST records +/// together. The first will end in an LF_INDEX record that points to the next. +class ListContinuationRecord : public TypeRecord { +public: + ListContinuationRecord() = default; + explicit ListContinuationRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + ListContinuationRecord(TypeIndex ContinuationIndex) + : TypeRecord(TypeRecordKind::ListContinuation), + ContinuationIndex(ContinuationIndex) {} + + TypeIndex getContinuationIndex() const { return ContinuationIndex; } + + TypeIndex ContinuationIndex; +}; + +// LF_PRECOMP +class PrecompRecord : public TypeRecord { +public: + PrecompRecord() = default; + explicit PrecompRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + + uint32_t getStartTypeIndex() const { return StartTypeIndex; } + uint32_t getTypesCount() const { return TypesCount; } + uint32_t getSignature() const { return Signature; } + StringRef getPrecompFilePath() const { return PrecompFilePath; } + + uint32_t StartTypeIndex; + uint32_t TypesCount; + uint32_t Signature; + StringRef PrecompFilePath; +}; + +// LF_ENDPRECOMP +class EndPrecompRecord : public TypeRecord { +public: + EndPrecompRecord() = default; + explicit EndPrecompRecord(TypeRecordKind Kind) : TypeRecord(Kind) {} + + uint32_t getSignature() const { return Signature; } + + uint32_t Signature; +}; +} // end namespace codeview +} // end namespace llvm + +#endif // LLVM_DEBUGINFO_CODEVIEW_TYPERECORD_H Index: include/llvm/ObjectYAML/COFFYAML.h =================================================================== --- include/llvm/ObjectYAML/COFFYAML.h +++ include/llvm/ObjectYAML/COFFYAML.h @@ -67,6 +67,7 @@ yaml::BinaryRef SectionData; std::vector DebugS; std::vector DebugT; + std::vector DebugP; Optional DebugH; std::vector Relocations; StringRef Name; Index: include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h =================================================================== --- include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h +++ include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h @@ -47,7 +47,7 @@ std::vector Hashes; }; -DebugHSection fromDebugH(ArrayRef DebugT); +DebugHSection fromDebugH(ArrayRef DebugH); ArrayRef toDebugH(const DebugHSection &DebugH, BumpPtrAllocator &Alloc); Index: include/llvm/ObjectYAML/CodeViewYAMLTypes.h =================================================================== --- include/llvm/ObjectYAML/CodeViewYAMLTypes.h +++ include/llvm/ObjectYAML/CodeViewYAMLTypes.h @@ -51,8 +51,10 @@ static Expected fromCodeViewRecord(codeview::CVType Type); }; -std::vector fromDebugT(ArrayRef DebugT); -ArrayRef toDebugT(ArrayRef, BumpPtrAllocator &Alloc); +std::vector fromDebugT(ArrayRef DebugTorP, + StringRef SectionName); +ArrayRef toDebugT(ArrayRef, BumpPtrAllocator &Alloc, + StringRef SectionName); } // end namespace CodeViewYAML Index: lib/CodeGen/AsmPrinter/CodeViewDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -239,7 +239,8 @@ } /// Emit the magic version number at the start of a CodeView type or symbol - /// section. Appears at the front of every .debug$S or .debug$T section. + /// section. Appears at the front of every .debug$S or .debug$T or .debug$P + /// section. void emitCodeViewMagicVersion(); void emitTypeInformation(); Index: lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -524,7 +524,7 @@ if (TypeTable.empty()) return; - // Start the .debug$T section with 0x4. + // Start the .debug$T or .debug$P section with 0x4. OS.SwitchSection(Asm->getObjFileLowering().getCOFFDebugTypesSection()); emitCodeViewMagicVersion(); Index: lib/DebugInfo/CodeView/RecordName.cpp =================================================================== --- lib/DebugInfo/CodeView/RecordName.cpp +++ lib/DebugInfo/CodeView/RecordName.cpp @@ -233,12 +233,22 @@ } Error TypeNameComputer::visitKnownRecord(CVType &CVR, LabelRecord &R) { - return Error::success(); -} - -std::string llvm::codeview::computeTypeName(TypeCollection &Types, - TypeIndex Index) { - TypeNameComputer Computer(Types); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, + PrecompRecord &Precomp) { + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, + EndPrecompRecord &EndPrecomp) { + return Error::success(); +} + +std::string llvm::codeview::computeTypeName(TypeCollection &Types, + TypeIndex Index) { + TypeNameComputer Computer(Types); CVType Record = Types.getType(Index); if (auto EC = visitTypeRecord(Record, Index, Computer)) { consumeError(std::move(EC)); Index: lib/DebugInfo/CodeView/TypeDumpVisitor.cpp =================================================================== --- lib/DebugInfo/CodeView/TypeDumpVisitor.cpp +++ lib/DebugInfo/CodeView/TypeDumpVisitor.cpp @@ -550,6 +550,21 @@ } Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, LabelRecord &LR) { - W->printEnum("Mode", uint16_t(LR.Mode), makeArrayRef(LabelTypeEnum)); - return Error::success(); -} + W->printEnum("Mode", uint16_t(LR.Mode), makeArrayRef(LabelTypeEnum)); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, + PrecompRecord &Precomp) { + W->printNumber("StartIndex", Precomp.getStartTypeIndex()); + W->printNumber("Count", Precomp.getTypesCount()); + W->printHex("Signature", Precomp.getSignature()); + W->printString("PrecompFile", Precomp.getPrecompFilePath()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, + EndPrecompRecord &EndPrecomp) { + W->printHex("Signature", EndPrecomp.getSignature()); + return Error::success(); +} Index: lib/DebugInfo/CodeView/TypeRecordMapping.cpp =================================================================== --- lib/DebugInfo/CodeView/TypeRecordMapping.cpp +++ lib/DebugInfo/CodeView/TypeRecordMapping.cpp @@ -477,6 +477,21 @@ uint16_t Padding = 0; error(IO.mapInteger(Padding)); error(IO.mapInteger(Record.ContinuationIndex)); - - return Error::success(); -} + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + PrecompRecord &Precomp) { + error(IO.mapInteger(Precomp.StartTypeIndex)); + error(IO.mapInteger(Precomp.TypesCount)); + error(IO.mapInteger(Precomp.Signature)); + error(IO.mapStringZ(Precomp.PrecompFilePath)); + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + EndPrecompRecord &EndPrecomp) { + error(IO.mapInteger(EndPrecomp.Signature)); + return Error::success(); +} Index: lib/ObjectYAML/COFFYAML.cpp =================================================================== --- lib/ObjectYAML/COFFYAML.cpp +++ lib/ObjectYAML/COFFYAML.cpp @@ -562,14 +562,16 @@ IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U); IO.mapOptional("Alignment", Sec.Alignment, 0U); - // If this is a .debug$S .debug$T, or .debug$H section parse the semantic - // representation of the symbols/types. If it is any other kind of section, - // just deal in raw bytes. + // If this is a .debug$S .debug$T .debug$P, or .debug$H section parse the + // semantic representation of the symbols/types. If it is any other kind + // of section, just deal in raw bytes. IO.mapOptional("SectionData", Sec.SectionData); if (Sec.Name == ".debug$S") IO.mapOptional("Subsections", Sec.DebugS); else if (Sec.Name == ".debug$T") IO.mapOptional("Types", Sec.DebugT); + else if (Sec.Name == ".debug$P") + IO.mapOptional("PrecompTypes", Sec.DebugP); else if (Sec.Name == ".debug$H") IO.mapOptional("GlobalHashes", Sec.DebugH); Index: lib/ObjectYAML/CodeViewYAMLTypes.cpp =================================================================== --- lib/ObjectYAML/CodeViewYAMLTypes.cpp +++ lib/ObjectYAML/CodeViewYAMLTypes.cpp @@ -1,803 +1,818 @@ -//===- CodeViewYAMLTypes.cpp - CodeView YAMLIO types implementation -------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines classes for handling the YAML representation of CodeView -// Debug Info. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ObjectYAML/CodeViewYAMLTypes.h" -#include "llvm/ADT/APSInt.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/BinaryFormat/COFF.h" -#include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h" -#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" -#include "llvm/DebugInfo/CodeView/CodeView.h" -#include "llvm/DebugInfo/CodeView/CodeViewError.h" -#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h" -#include "llvm/DebugInfo/CodeView/TypeDeserializer.h" -#include "llvm/DebugInfo/CodeView/TypeIndex.h" -#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" -#include "llvm/Support/Allocator.h" -#include "llvm/Support/BinaryStreamReader.h" -#include "llvm/Support/BinaryStreamWriter.h" -#include "llvm/Support/Endian.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/YAMLTraits.h" -#include "llvm/Support/raw_ostream.h" -#include -#include -#include -#include - -using namespace llvm; -using namespace llvm::codeview; -using namespace llvm::CodeViewYAML; -using namespace llvm::CodeViewYAML::detail; -using namespace llvm::yaml; - -LLVM_YAML_IS_SEQUENCE_VECTOR(OneMethodRecord) -LLVM_YAML_IS_SEQUENCE_VECTOR(VFTableSlotKind) -LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TypeIndex) - -LLVM_YAML_DECLARE_SCALAR_TRAITS(TypeIndex, QuotingType::None) -LLVM_YAML_DECLARE_SCALAR_TRAITS(APSInt, QuotingType::None) - -LLVM_YAML_DECLARE_ENUM_TRAITS(TypeLeafKind) -LLVM_YAML_DECLARE_ENUM_TRAITS(PointerToMemberRepresentation) -LLVM_YAML_DECLARE_ENUM_TRAITS(VFTableSlotKind) -LLVM_YAML_DECLARE_ENUM_TRAITS(CallingConvention) -LLVM_YAML_DECLARE_ENUM_TRAITS(PointerKind) -LLVM_YAML_DECLARE_ENUM_TRAITS(PointerMode) -LLVM_YAML_DECLARE_ENUM_TRAITS(HfaKind) -LLVM_YAML_DECLARE_ENUM_TRAITS(MemberAccess) -LLVM_YAML_DECLARE_ENUM_TRAITS(MethodKind) -LLVM_YAML_DECLARE_ENUM_TRAITS(WindowsRTClassKind) -LLVM_YAML_DECLARE_ENUM_TRAITS(LabelType) - -LLVM_YAML_DECLARE_BITSET_TRAITS(PointerOptions) -LLVM_YAML_DECLARE_BITSET_TRAITS(ModifierOptions) -LLVM_YAML_DECLARE_BITSET_TRAITS(FunctionOptions) -LLVM_YAML_DECLARE_BITSET_TRAITS(ClassOptions) -LLVM_YAML_DECLARE_BITSET_TRAITS(MethodOptions) - -LLVM_YAML_DECLARE_MAPPING_TRAITS(OneMethodRecord) -LLVM_YAML_DECLARE_MAPPING_TRAITS(MemberPointerInfo) - -namespace llvm { -namespace CodeViewYAML { -namespace detail { - -struct LeafRecordBase { - TypeLeafKind Kind; - - explicit LeafRecordBase(TypeLeafKind K) : Kind(K) {} - virtual ~LeafRecordBase() = default; - - virtual void map(yaml::IO &io) = 0; - virtual CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const = 0; - virtual Error fromCodeViewRecord(CVType Type) = 0; -}; - -template struct LeafRecordImpl : public LeafRecordBase { - explicit LeafRecordImpl(TypeLeafKind K) - : LeafRecordBase(K), Record(static_cast(K)) {} - - void map(yaml::IO &io) override; - - Error fromCodeViewRecord(CVType Type) override { - return TypeDeserializer::deserializeAs(Type, Record); - } - - CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override { - TS.writeLeafType(Record); - return CVType(Kind, TS.records().back()); - } - - mutable T Record; -}; - -template <> struct LeafRecordImpl : public LeafRecordBase { - explicit LeafRecordImpl(TypeLeafKind K) : LeafRecordBase(K) {} - - void map(yaml::IO &io) override; - CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override; - Error fromCodeViewRecord(CVType Type) override; - - std::vector Members; -}; - -struct MemberRecordBase { - TypeLeafKind Kind; - - explicit MemberRecordBase(TypeLeafKind K) : Kind(K) {} - virtual ~MemberRecordBase() = default; - - virtual void map(yaml::IO &io) = 0; - virtual void writeTo(ContinuationRecordBuilder &CRB) = 0; -}; - -template struct MemberRecordImpl : public MemberRecordBase { - explicit MemberRecordImpl(TypeLeafKind K) - : MemberRecordBase(K), Record(static_cast(K)) {} - - void map(yaml::IO &io) override; - - void writeTo(ContinuationRecordBuilder &CRB) override { - CRB.writeMemberType(Record); - } - - mutable T Record; -}; - -} // end namespace detail -} // end namespace CodeViewYAML -} // end namespace llvm - -void ScalarTraits::output(const GUID &G, void *, llvm::raw_ostream &OS) { - OS << G; -} - -StringRef ScalarTraits::input(StringRef Scalar, void *Ctx, GUID &S) { - if (Scalar.size() != 38) - return "GUID strings are 38 characters long"; - if (Scalar[0] != '{' || Scalar[37] != '}') - return "GUID is not enclosed in {}"; - if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' || - Scalar[24] != '-') - return "GUID sections are not properly delineated with dashes"; - - uint8_t *OutBuffer = S.Guid; - for (auto Iter = Scalar.begin(); Iter != Scalar.end();) { - if (*Iter == '-' || *Iter == '{' || *Iter == '}') { - ++Iter; - continue; - } - uint8_t Value = (llvm::hexDigitValue(*Iter++) << 4); - Value |= llvm::hexDigitValue(*Iter++); - *OutBuffer++ = Value; - } - - return ""; -} - -void ScalarTraits::output(const TypeIndex &S, void *, - raw_ostream &OS) { - OS << S.getIndex(); -} - -StringRef ScalarTraits::input(StringRef Scalar, void *Ctx, - TypeIndex &S) { - uint32_t I; - StringRef Result = ScalarTraits::input(Scalar, Ctx, I); - S.setIndex(I); - return Result; -} - -void ScalarTraits::output(const APSInt &S, void *, raw_ostream &OS) { - S.print(OS, S.isSigned()); -} - -StringRef ScalarTraits::input(StringRef Scalar, void *Ctx, APSInt &S) { - S = APSInt(Scalar); - return ""; -} - -void ScalarEnumerationTraits::enumeration(IO &io, - TypeLeafKind &Value) { -#define CV_TYPE(name, val) io.enumCase(Value, #name, name); -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" -#undef CV_TYPE -} - -void ScalarEnumerationTraits::enumeration( - IO &IO, PointerToMemberRepresentation &Value) { - IO.enumCase(Value, "Unknown", PointerToMemberRepresentation::Unknown); - IO.enumCase(Value, "SingleInheritanceData", - PointerToMemberRepresentation::SingleInheritanceData); - IO.enumCase(Value, "MultipleInheritanceData", - PointerToMemberRepresentation::MultipleInheritanceData); - IO.enumCase(Value, "VirtualInheritanceData", - PointerToMemberRepresentation::VirtualInheritanceData); - IO.enumCase(Value, "GeneralData", PointerToMemberRepresentation::GeneralData); - IO.enumCase(Value, "SingleInheritanceFunction", - PointerToMemberRepresentation::SingleInheritanceFunction); - IO.enumCase(Value, "MultipleInheritanceFunction", - PointerToMemberRepresentation::MultipleInheritanceFunction); - IO.enumCase(Value, "VirtualInheritanceFunction", - PointerToMemberRepresentation::VirtualInheritanceFunction); - IO.enumCase(Value, "GeneralFunction", - PointerToMemberRepresentation::GeneralFunction); -} - -void ScalarEnumerationTraits::enumeration( - IO &IO, VFTableSlotKind &Kind) { - IO.enumCase(Kind, "Near16", VFTableSlotKind::Near16); - IO.enumCase(Kind, "Far16", VFTableSlotKind::Far16); - IO.enumCase(Kind, "This", VFTableSlotKind::This); - IO.enumCase(Kind, "Outer", VFTableSlotKind::Outer); - IO.enumCase(Kind, "Meta", VFTableSlotKind::Meta); - IO.enumCase(Kind, "Near", VFTableSlotKind::Near); - IO.enumCase(Kind, "Far", VFTableSlotKind::Far); -} - -void ScalarEnumerationTraits::enumeration( - IO &IO, CallingConvention &Value) { - IO.enumCase(Value, "NearC", CallingConvention::NearC); - IO.enumCase(Value, "FarC", CallingConvention::FarC); - IO.enumCase(Value, "NearPascal", CallingConvention::NearPascal); - IO.enumCase(Value, "FarPascal", CallingConvention::FarPascal); - IO.enumCase(Value, "NearFast", CallingConvention::NearFast); - IO.enumCase(Value, "FarFast", CallingConvention::FarFast); - IO.enumCase(Value, "NearStdCall", CallingConvention::NearStdCall); - IO.enumCase(Value, "FarStdCall", CallingConvention::FarStdCall); - IO.enumCase(Value, "NearSysCall", CallingConvention::NearSysCall); - IO.enumCase(Value, "FarSysCall", CallingConvention::FarSysCall); - IO.enumCase(Value, "ThisCall", CallingConvention::ThisCall); - IO.enumCase(Value, "MipsCall", CallingConvention::MipsCall); - IO.enumCase(Value, "Generic", CallingConvention::Generic); - IO.enumCase(Value, "AlphaCall", CallingConvention::AlphaCall); - IO.enumCase(Value, "PpcCall", CallingConvention::PpcCall); - IO.enumCase(Value, "SHCall", CallingConvention::SHCall); - IO.enumCase(Value, "ArmCall", CallingConvention::ArmCall); - IO.enumCase(Value, "AM33Call", CallingConvention::AM33Call); - IO.enumCase(Value, "TriCall", CallingConvention::TriCall); - IO.enumCase(Value, "SH5Call", CallingConvention::SH5Call); - IO.enumCase(Value, "M32RCall", CallingConvention::M32RCall); - IO.enumCase(Value, "ClrCall", CallingConvention::ClrCall); - IO.enumCase(Value, "Inline", CallingConvention::Inline); - IO.enumCase(Value, "NearVector", CallingConvention::NearVector); -} - -void ScalarEnumerationTraits::enumeration(IO &IO, - PointerKind &Kind) { - IO.enumCase(Kind, "Near16", PointerKind::Near16); - IO.enumCase(Kind, "Far16", PointerKind::Far16); - IO.enumCase(Kind, "Huge16", PointerKind::Huge16); - IO.enumCase(Kind, "BasedOnSegment", PointerKind::BasedOnSegment); - IO.enumCase(Kind, "BasedOnValue", PointerKind::BasedOnValue); - IO.enumCase(Kind, "BasedOnSegmentValue", PointerKind::BasedOnSegmentValue); - IO.enumCase(Kind, "BasedOnAddress", PointerKind::BasedOnAddress); - IO.enumCase(Kind, "BasedOnSegmentAddress", - PointerKind::BasedOnSegmentAddress); - IO.enumCase(Kind, "BasedOnType", PointerKind::BasedOnType); - IO.enumCase(Kind, "BasedOnSelf", PointerKind::BasedOnSelf); - IO.enumCase(Kind, "Near32", PointerKind::Near32); - IO.enumCase(Kind, "Far32", PointerKind::Far32); - IO.enumCase(Kind, "Near64", PointerKind::Near64); -} - -void ScalarEnumerationTraits::enumeration(IO &IO, - PointerMode &Mode) { - IO.enumCase(Mode, "Pointer", PointerMode::Pointer); - IO.enumCase(Mode, "LValueReference", PointerMode::LValueReference); - IO.enumCase(Mode, "PointerToDataMember", PointerMode::PointerToDataMember); - IO.enumCase(Mode, "PointerToMemberFunction", - PointerMode::PointerToMemberFunction); - IO.enumCase(Mode, "RValueReference", PointerMode::RValueReference); -} - -void ScalarEnumerationTraits::enumeration(IO &IO, HfaKind &Value) { - IO.enumCase(Value, "None", HfaKind::None); - IO.enumCase(Value, "Float", HfaKind::Float); - IO.enumCase(Value, "Double", HfaKind::Double); - IO.enumCase(Value, "Other", HfaKind::Other); -} - -void ScalarEnumerationTraits::enumeration(IO &IO, - MemberAccess &Access) { - IO.enumCase(Access, "None", MemberAccess::None); - IO.enumCase(Access, "Private", MemberAccess::Private); - IO.enumCase(Access, "Protected", MemberAccess::Protected); - IO.enumCase(Access, "Public", MemberAccess::Public); -} - -void ScalarEnumerationTraits::enumeration(IO &IO, - MethodKind &Kind) { - IO.enumCase(Kind, "Vanilla", MethodKind::Vanilla); - IO.enumCase(Kind, "Virtual", MethodKind::Virtual); - IO.enumCase(Kind, "Static", MethodKind::Static); - IO.enumCase(Kind, "Friend", MethodKind::Friend); - IO.enumCase(Kind, "IntroducingVirtual", MethodKind::IntroducingVirtual); - IO.enumCase(Kind, "PureVirtual", MethodKind::PureVirtual); - IO.enumCase(Kind, "PureIntroducingVirtual", - MethodKind::PureIntroducingVirtual); -} - -void ScalarEnumerationTraits::enumeration( - IO &IO, WindowsRTClassKind &Value) { - IO.enumCase(Value, "None", WindowsRTClassKind::None); - IO.enumCase(Value, "Ref", WindowsRTClassKind::RefClass); - IO.enumCase(Value, "Value", WindowsRTClassKind::ValueClass); - IO.enumCase(Value, "Interface", WindowsRTClassKind::Interface); -} - -void ScalarEnumerationTraits::enumeration(IO &IO, LabelType &Value) { - IO.enumCase(Value, "Near", LabelType::Near); - IO.enumCase(Value, "Far", LabelType::Far); -} - -void ScalarBitSetTraits::bitset(IO &IO, - PointerOptions &Options) { - IO.bitSetCase(Options, "None", PointerOptions::None); - IO.bitSetCase(Options, "Flat32", PointerOptions::Flat32); - IO.bitSetCase(Options, "Volatile", PointerOptions::Volatile); - IO.bitSetCase(Options, "Const", PointerOptions::Const); - IO.bitSetCase(Options, "Unaligned", PointerOptions::Unaligned); - IO.bitSetCase(Options, "Restrict", PointerOptions::Restrict); - IO.bitSetCase(Options, "WinRTSmartPointer", - PointerOptions::WinRTSmartPointer); -} - -void ScalarBitSetTraits::bitset(IO &IO, - ModifierOptions &Options) { - IO.bitSetCase(Options, "None", ModifierOptions::None); - IO.bitSetCase(Options, "Const", ModifierOptions::Const); - IO.bitSetCase(Options, "Volatile", ModifierOptions::Volatile); - IO.bitSetCase(Options, "Unaligned", ModifierOptions::Unaligned); -} - -void ScalarBitSetTraits::bitset(IO &IO, - FunctionOptions &Options) { - IO.bitSetCase(Options, "None", FunctionOptions::None); - IO.bitSetCase(Options, "CxxReturnUdt", FunctionOptions::CxxReturnUdt); - IO.bitSetCase(Options, "Constructor", FunctionOptions::Constructor); - IO.bitSetCase(Options, "ConstructorWithVirtualBases", - FunctionOptions::ConstructorWithVirtualBases); -} - -void ScalarBitSetTraits::bitset(IO &IO, ClassOptions &Options) { - IO.bitSetCase(Options, "None", ClassOptions::None); - IO.bitSetCase(Options, "HasConstructorOrDestructor", - ClassOptions::HasConstructorOrDestructor); - IO.bitSetCase(Options, "HasOverloadedOperator", - ClassOptions::HasOverloadedOperator); - IO.bitSetCase(Options, "Nested", ClassOptions::Nested); - IO.bitSetCase(Options, "ContainsNestedClass", - ClassOptions::ContainsNestedClass); - IO.bitSetCase(Options, "HasOverloadedAssignmentOperator", - ClassOptions::HasOverloadedAssignmentOperator); - IO.bitSetCase(Options, "HasConversionOperator", - ClassOptions::HasConversionOperator); - IO.bitSetCase(Options, "ForwardReference", ClassOptions::ForwardReference); - IO.bitSetCase(Options, "Scoped", ClassOptions::Scoped); - IO.bitSetCase(Options, "HasUniqueName", ClassOptions::HasUniqueName); - IO.bitSetCase(Options, "Sealed", ClassOptions::Sealed); - IO.bitSetCase(Options, "Intrinsic", ClassOptions::Intrinsic); -} - -void ScalarBitSetTraits::bitset(IO &IO, MethodOptions &Options) { - IO.bitSetCase(Options, "None", MethodOptions::None); - IO.bitSetCase(Options, "Pseudo", MethodOptions::Pseudo); - IO.bitSetCase(Options, "NoInherit", MethodOptions::NoInherit); - IO.bitSetCase(Options, "NoConstruct", MethodOptions::NoConstruct); - IO.bitSetCase(Options, "CompilerGenerated", MethodOptions::CompilerGenerated); - IO.bitSetCase(Options, "Sealed", MethodOptions::Sealed); -} - -void MappingTraits::mapping(IO &IO, MemberPointerInfo &MPI) { - IO.mapRequired("ContainingType", MPI.ContainingType); - IO.mapRequired("Representation", MPI.Representation); -} - -namespace llvm { -namespace CodeViewYAML { -namespace detail { - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ModifiedType", Record.ModifiedType); - IO.mapRequired("Modifiers", Record.Modifiers); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ReturnType", Record.ReturnType); - IO.mapRequired("CallConv", Record.CallConv); - IO.mapRequired("Options", Record.Options); - IO.mapRequired("ParameterCount", Record.ParameterCount); - IO.mapRequired("ArgumentList", Record.ArgumentList); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ReturnType", Record.ReturnType); - IO.mapRequired("ClassType", Record.ClassType); - IO.mapRequired("ThisType", Record.ThisType); - IO.mapRequired("CallConv", Record.CallConv); - IO.mapRequired("Options", Record.Options); - IO.mapRequired("ParameterCount", Record.ParameterCount); - IO.mapRequired("ArgumentList", Record.ArgumentList); - IO.mapRequired("ThisPointerAdjustment", Record.ThisPointerAdjustment); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("Mode", Record.Mode); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ClassType", Record.ClassType); - IO.mapRequired("FunctionType", Record.FunctionType); - IO.mapRequired("Name", Record.Name); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ArgIndices", Record.ArgIndices); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("StringIndices", Record.StringIndices); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ReferentType", Record.ReferentType); - IO.mapRequired("Attrs", Record.Attrs); - IO.mapOptional("MemberInfo", Record.MemberInfo); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ElementType", Record.ElementType); - IO.mapRequired("IndexType", Record.IndexType); - IO.mapRequired("Size", Record.Size); - IO.mapRequired("Name", Record.Name); -} - -void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("FieldList", Members); -} - -} // end namespace detail -} // end namespace CodeViewYAML -} // end namespace llvm - -namespace { - -class MemberRecordConversionVisitor : public TypeVisitorCallbacks { -public: - explicit MemberRecordConversionVisitor(std::vector &Records) - : Records(Records) {} - -#define TYPE_RECORD(EnumName, EnumVal, Name) -#define MEMBER_RECORD(EnumName, EnumVal, Name) \ - Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override { \ - return visitKnownMemberImpl(Record); \ - } -#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) -#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" -private: - template Error visitKnownMemberImpl(T &Record) { - TypeLeafKind K = static_cast(Record.getKind()); - auto Impl = std::make_shared>(K); - Impl->Record = Record; - Records.push_back(MemberRecord{Impl}); - return Error::success(); - } - - std::vector &Records; -}; - -} // end anonymous namespace - -Error LeafRecordImpl::fromCodeViewRecord(CVType Type) { - MemberRecordConversionVisitor V(Members); - return visitMemberRecordStream(Type.content(), V); -} - -CVType LeafRecordImpl::toCodeViewRecord( - AppendingTypeTableBuilder &TS) const { - ContinuationRecordBuilder CRB; - CRB.begin(ContinuationRecordKind::FieldList); - for (const auto &Member : Members) { - Member.Member->writeTo(CRB); - } - TS.insertRecord(CRB); - return CVType(Kind, TS.records().back()); -} - -void MappingTraits::mapping(IO &io, OneMethodRecord &Record) { - io.mapRequired("Type", Record.Type); - io.mapRequired("Attrs", Record.Attrs.Attrs); - io.mapRequired("VFTableOffset", Record.VFTableOffset); - io.mapRequired("Name", Record.Name); -} - -namespace llvm { -namespace CodeViewYAML { -namespace detail { - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("MemberCount", Record.MemberCount); - IO.mapRequired("Options", Record.Options); - IO.mapRequired("FieldList", Record.FieldList); - IO.mapRequired("Name", Record.Name); - IO.mapRequired("UniqueName", Record.UniqueName); - IO.mapRequired("DerivationList", Record.DerivationList); - IO.mapRequired("VTableShape", Record.VTableShape); - IO.mapRequired("Size", Record.Size); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("MemberCount", Record.MemberCount); - IO.mapRequired("Options", Record.Options); - IO.mapRequired("FieldList", Record.FieldList); - IO.mapRequired("Name", Record.Name); - IO.mapRequired("UniqueName", Record.UniqueName); - IO.mapRequired("Size", Record.Size); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("NumEnumerators", Record.MemberCount); - IO.mapRequired("Options", Record.Options); - IO.mapRequired("FieldList", Record.FieldList); - IO.mapRequired("Name", Record.Name); - IO.mapRequired("UniqueName", Record.UniqueName); - IO.mapRequired("UnderlyingType", Record.UnderlyingType); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("Type", Record.Type); - IO.mapRequired("BitSize", Record.BitSize); - IO.mapRequired("BitOffset", Record.BitOffset); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("Slots", Record.Slots); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("Guid", Record.Guid); - IO.mapRequired("Age", Record.Age); - IO.mapRequired("Name", Record.Name); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("Id", Record.Id); - IO.mapRequired("String", Record.String); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ParentScope", Record.ParentScope); - IO.mapRequired("FunctionType", Record.FunctionType); - IO.mapRequired("Name", Record.Name); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("UDT", Record.UDT); - IO.mapRequired("SourceFile", Record.SourceFile); - IO.mapRequired("LineNumber", Record.LineNumber); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("UDT", Record.UDT); - IO.mapRequired("SourceFile", Record.SourceFile); - IO.mapRequired("LineNumber", Record.LineNumber); - IO.mapRequired("Module", Record.Module); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("ArgIndices", Record.ArgIndices); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("CompleteClass", Record.CompleteClass); - IO.mapRequired("OverriddenVFTable", Record.OverriddenVFTable); - IO.mapRequired("VFPtrOffset", Record.VFPtrOffset); - IO.mapRequired("MethodNames", Record.MethodNames); -} - -template <> void LeafRecordImpl::map(IO &IO) { - IO.mapRequired("Methods", Record.Methods); -} - -template <> void MemberRecordImpl::map(IO &IO) { - MappingTraits::mapping(IO, Record); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("NumOverloads", Record.NumOverloads); - IO.mapRequired("MethodList", Record.MethodList); - IO.mapRequired("Name", Record.Name); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("Type", Record.Type); - IO.mapRequired("Name", Record.Name); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("Attrs", Record.Attrs.Attrs); - IO.mapRequired("Type", Record.Type); - IO.mapRequired("FieldOffset", Record.FieldOffset); - IO.mapRequired("Name", Record.Name); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("Attrs", Record.Attrs.Attrs); - IO.mapRequired("Type", Record.Type); - IO.mapRequired("Name", Record.Name); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("Attrs", Record.Attrs.Attrs); - IO.mapRequired("Value", Record.Value); - IO.mapRequired("Name", Record.Name); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("Type", Record.Type); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("Attrs", Record.Attrs.Attrs); - IO.mapRequired("Type", Record.Type); - IO.mapRequired("Offset", Record.Offset); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("Attrs", Record.Attrs.Attrs); - IO.mapRequired("BaseType", Record.BaseType); - IO.mapRequired("VBPtrType", Record.VBPtrType); - IO.mapRequired("VBPtrOffset", Record.VBPtrOffset); - IO.mapRequired("VTableIndex", Record.VTableIndex); -} - -template <> void MemberRecordImpl::map(IO &IO) { - IO.mapRequired("ContinuationIndex", Record.ContinuationIndex); -} - -} // end namespace detail -} // end namespace CodeViewYAML -} // end namespace llvm - -template -static inline Expected fromCodeViewRecordImpl(CVType Type) { - LeafRecord Result; - - auto Impl = std::make_shared>(Type.kind()); - if (auto EC = Impl->fromCodeViewRecord(Type)) - return std::move(EC); - Result.Leaf = Impl; - return Result; -} - -Expected LeafRecord::fromCodeViewRecord(CVType Type) { -#define TYPE_RECORD(EnumName, EnumVal, ClassName) \ - case EnumName: \ - return fromCodeViewRecordImpl(Type); -#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \ - TYPE_RECORD(EnumName, EnumVal, ClassName) -#define MEMBER_RECORD(EnumName, EnumVal, ClassName) -#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) - switch (Type.kind()) { -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" - default: - llvm_unreachable("Unknown leaf kind!"); - } - return make_error(cv_error_code::corrupt_record); -} - -CVType -LeafRecord::toCodeViewRecord(AppendingTypeTableBuilder &Serializer) const { - return Leaf->toCodeViewRecord(Serializer); -} - -namespace llvm { -namespace yaml { - -template <> struct MappingTraits { - static void mapping(IO &io, LeafRecordBase &Record) { Record.map(io); } -}; - -template <> struct MappingTraits { - static void mapping(IO &io, MemberRecordBase &Record) { Record.map(io); } -}; - -} // end namespace yaml -} // end namespace llvm - -template -static void mapLeafRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind, - LeafRecord &Obj) { - if (!IO.outputting()) - Obj.Leaf = std::make_shared>(Kind); - - if (Kind == LF_FIELDLIST) - Obj.Leaf->map(IO); - else - IO.mapRequired(Class, *Obj.Leaf); -} - -void MappingTraits::mapping(IO &IO, LeafRecord &Obj) { - TypeLeafKind Kind; - if (IO.outputting()) - Kind = Obj.Leaf->Kind; - IO.mapRequired("Kind", Kind); - -#define TYPE_RECORD(EnumName, EnumVal, ClassName) \ - case EnumName: \ - mapLeafRecordImpl(IO, #ClassName, Kind, Obj); \ - break; -#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \ - TYPE_RECORD(EnumName, EnumVal, ClassName) -#define MEMBER_RECORD(EnumName, EnumVal, ClassName) -#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) - switch (Kind) { -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" - default: { llvm_unreachable("Unknown leaf kind!"); } - } -} - -template -static void mapMemberRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind, - MemberRecord &Obj) { - if (!IO.outputting()) - Obj.Member = std::make_shared>(Kind); - - IO.mapRequired(Class, *Obj.Member); -} - -void MappingTraits::mapping(IO &IO, MemberRecord &Obj) { - TypeLeafKind Kind; - if (IO.outputting()) - Kind = Obj.Member->Kind; - IO.mapRequired("Kind", Kind); - -#define MEMBER_RECORD(EnumName, EnumVal, ClassName) \ - case EnumName: \ - mapMemberRecordImpl(IO, #ClassName, Kind, Obj); \ - break; -#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \ - MEMBER_RECORD(EnumName, EnumVal, ClassName) -#define TYPE_RECORD(EnumName, EnumVal, ClassName) -#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) - switch (Kind) { -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" - default: { llvm_unreachable("Unknown member kind!"); } - } -} - -std::vector -llvm::CodeViewYAML::fromDebugT(ArrayRef DebugT) { - ExitOnError Err("Invalid .debug$T section!"); - BinaryStreamReader Reader(DebugT, support::little); - CVTypeArray Types; - uint32_t Magic; - - Err(Reader.readInteger(Magic)); - assert(Magic == COFF::DEBUG_SECTION_MAGIC && "Invalid .debug$T section!"); - - std::vector Result; - Err(Reader.readArray(Types, Reader.bytesRemaining())); - for (const auto &T : Types) { - auto CVT = Err(LeafRecord::fromCodeViewRecord(T)); - Result.push_back(CVT); - } - return Result; -} - -ArrayRef llvm::CodeViewYAML::toDebugT(ArrayRef Leafs, - BumpPtrAllocator &Alloc) { - AppendingTypeTableBuilder TS(Alloc); - uint32_t Size = sizeof(uint32_t); - for (const auto &Leaf : Leafs) { - CVType T = Leaf.Leaf->toCodeViewRecord(TS); - Size += T.length(); - assert(T.length() % 4 == 0 && "Improper type record alignment!"); - } - uint8_t *ResultBuffer = Alloc.Allocate(Size); - MutableArrayRef Output(ResultBuffer, Size); - BinaryStreamWriter Writer(Output, support::little); - ExitOnError Err("Error writing type record to .debug$T section"); - Err(Writer.writeInteger(COFF::DEBUG_SECTION_MAGIC)); - for (const auto &R : TS.records()) { - Err(Writer.writeBytes(R)); - } - assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!"); - return Output; -} +//===- CodeViewYAMLTypes.cpp - CodeView YAMLIO types implementation -------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines classes for handling the YAML representation of CodeView +// Debug Info. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ObjectYAML/CodeViewYAMLTypes.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h" +#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/CodeViewError.h" +#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h" +#include "llvm/DebugInfo/CodeView/TypeDeserializer.h" +#include "llvm/DebugInfo/CodeView/TypeIndex.h" +#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/BinaryStreamReader.h" +#include "llvm/Support/BinaryStreamWriter.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/YAMLTraits.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include + +using namespace llvm; +using namespace llvm::codeview; +using namespace llvm::CodeViewYAML; +using namespace llvm::CodeViewYAML::detail; +using namespace llvm::yaml; + +LLVM_YAML_IS_SEQUENCE_VECTOR(OneMethodRecord) +LLVM_YAML_IS_SEQUENCE_VECTOR(VFTableSlotKind) +LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TypeIndex) + +LLVM_YAML_DECLARE_SCALAR_TRAITS(TypeIndex, QuotingType::None) +LLVM_YAML_DECLARE_SCALAR_TRAITS(APSInt, QuotingType::None) + +LLVM_YAML_DECLARE_ENUM_TRAITS(TypeLeafKind) +LLVM_YAML_DECLARE_ENUM_TRAITS(PointerToMemberRepresentation) +LLVM_YAML_DECLARE_ENUM_TRAITS(VFTableSlotKind) +LLVM_YAML_DECLARE_ENUM_TRAITS(CallingConvention) +LLVM_YAML_DECLARE_ENUM_TRAITS(PointerKind) +LLVM_YAML_DECLARE_ENUM_TRAITS(PointerMode) +LLVM_YAML_DECLARE_ENUM_TRAITS(HfaKind) +LLVM_YAML_DECLARE_ENUM_TRAITS(MemberAccess) +LLVM_YAML_DECLARE_ENUM_TRAITS(MethodKind) +LLVM_YAML_DECLARE_ENUM_TRAITS(WindowsRTClassKind) +LLVM_YAML_DECLARE_ENUM_TRAITS(LabelType) + +LLVM_YAML_DECLARE_BITSET_TRAITS(PointerOptions) +LLVM_YAML_DECLARE_BITSET_TRAITS(ModifierOptions) +LLVM_YAML_DECLARE_BITSET_TRAITS(FunctionOptions) +LLVM_YAML_DECLARE_BITSET_TRAITS(ClassOptions) +LLVM_YAML_DECLARE_BITSET_TRAITS(MethodOptions) + +LLVM_YAML_DECLARE_MAPPING_TRAITS(OneMethodRecord) +LLVM_YAML_DECLARE_MAPPING_TRAITS(MemberPointerInfo) + +namespace llvm { +namespace CodeViewYAML { +namespace detail { + +struct LeafRecordBase { + TypeLeafKind Kind; + + explicit LeafRecordBase(TypeLeafKind K) : Kind(K) {} + virtual ~LeafRecordBase() = default; + + virtual void map(yaml::IO &io) = 0; + virtual CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const = 0; + virtual Error fromCodeViewRecord(CVType Type) = 0; +}; + +template struct LeafRecordImpl : public LeafRecordBase { + explicit LeafRecordImpl(TypeLeafKind K) + : LeafRecordBase(K), Record(static_cast(K)) {} + + void map(yaml::IO &io) override; + + Error fromCodeViewRecord(CVType Type) override { + return TypeDeserializer::deserializeAs(Type, Record); + } + + CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override { + TS.writeLeafType(Record); + return CVType(Kind, TS.records().back()); + } + + mutable T Record; +}; + +template <> struct LeafRecordImpl : public LeafRecordBase { + explicit LeafRecordImpl(TypeLeafKind K) : LeafRecordBase(K) {} + + void map(yaml::IO &io) override; + CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override; + Error fromCodeViewRecord(CVType Type) override; + + std::vector Members; +}; + +struct MemberRecordBase { + TypeLeafKind Kind; + + explicit MemberRecordBase(TypeLeafKind K) : Kind(K) {} + virtual ~MemberRecordBase() = default; + + virtual void map(yaml::IO &io) = 0; + virtual void writeTo(ContinuationRecordBuilder &CRB) = 0; +}; + +template struct MemberRecordImpl : public MemberRecordBase { + explicit MemberRecordImpl(TypeLeafKind K) + : MemberRecordBase(K), Record(static_cast(K)) {} + + void map(yaml::IO &io) override; + + void writeTo(ContinuationRecordBuilder &CRB) override { + CRB.writeMemberType(Record); + } + + mutable T Record; +}; + +} // end namespace detail +} // end namespace CodeViewYAML +} // end namespace llvm + +void ScalarTraits::output(const GUID &G, void *, llvm::raw_ostream &OS) { + OS << G; +} + +StringRef ScalarTraits::input(StringRef Scalar, void *Ctx, GUID &S) { + if (Scalar.size() != 38) + return "GUID strings are 38 characters long"; + if (Scalar[0] != '{' || Scalar[37] != '}') + return "GUID is not enclosed in {}"; + if (Scalar[9] != '-' || Scalar[14] != '-' || Scalar[19] != '-' || + Scalar[24] != '-') + return "GUID sections are not properly delineated with dashes"; + + uint8_t *OutBuffer = S.Guid; + for (auto Iter = Scalar.begin(); Iter != Scalar.end();) { + if (*Iter == '-' || *Iter == '{' || *Iter == '}') { + ++Iter; + continue; + } + uint8_t Value = (llvm::hexDigitValue(*Iter++) << 4); + Value |= llvm::hexDigitValue(*Iter++); + *OutBuffer++ = Value; + } + + return ""; +} + +void ScalarTraits::output(const TypeIndex &S, void *, + raw_ostream &OS) { + OS << S.getIndex(); +} + +StringRef ScalarTraits::input(StringRef Scalar, void *Ctx, + TypeIndex &S) { + uint32_t I; + StringRef Result = ScalarTraits::input(Scalar, Ctx, I); + S.setIndex(I); + return Result; +} + +void ScalarTraits::output(const APSInt &S, void *, raw_ostream &OS) { + S.print(OS, S.isSigned()); +} + +StringRef ScalarTraits::input(StringRef Scalar, void *Ctx, APSInt &S) { + S = APSInt(Scalar); + return ""; +} + +void ScalarEnumerationTraits::enumeration(IO &io, + TypeLeafKind &Value) { +#define CV_TYPE(name, val) io.enumCase(Value, #name, name); +#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" +#undef CV_TYPE +} + +void ScalarEnumerationTraits::enumeration( + IO &IO, PointerToMemberRepresentation &Value) { + IO.enumCase(Value, "Unknown", PointerToMemberRepresentation::Unknown); + IO.enumCase(Value, "SingleInheritanceData", + PointerToMemberRepresentation::SingleInheritanceData); + IO.enumCase(Value, "MultipleInheritanceData", + PointerToMemberRepresentation::MultipleInheritanceData); + IO.enumCase(Value, "VirtualInheritanceData", + PointerToMemberRepresentation::VirtualInheritanceData); + IO.enumCase(Value, "GeneralData", PointerToMemberRepresentation::GeneralData); + IO.enumCase(Value, "SingleInheritanceFunction", + PointerToMemberRepresentation::SingleInheritanceFunction); + IO.enumCase(Value, "MultipleInheritanceFunction", + PointerToMemberRepresentation::MultipleInheritanceFunction); + IO.enumCase(Value, "VirtualInheritanceFunction", + PointerToMemberRepresentation::VirtualInheritanceFunction); + IO.enumCase(Value, "GeneralFunction", + PointerToMemberRepresentation::GeneralFunction); +} + +void ScalarEnumerationTraits::enumeration( + IO &IO, VFTableSlotKind &Kind) { + IO.enumCase(Kind, "Near16", VFTableSlotKind::Near16); + IO.enumCase(Kind, "Far16", VFTableSlotKind::Far16); + IO.enumCase(Kind, "This", VFTableSlotKind::This); + IO.enumCase(Kind, "Outer", VFTableSlotKind::Outer); + IO.enumCase(Kind, "Meta", VFTableSlotKind::Meta); + IO.enumCase(Kind, "Near", VFTableSlotKind::Near); + IO.enumCase(Kind, "Far", VFTableSlotKind::Far); +} + +void ScalarEnumerationTraits::enumeration( + IO &IO, CallingConvention &Value) { + IO.enumCase(Value, "NearC", CallingConvention::NearC); + IO.enumCase(Value, "FarC", CallingConvention::FarC); + IO.enumCase(Value, "NearPascal", CallingConvention::NearPascal); + IO.enumCase(Value, "FarPascal", CallingConvention::FarPascal); + IO.enumCase(Value, "NearFast", CallingConvention::NearFast); + IO.enumCase(Value, "FarFast", CallingConvention::FarFast); + IO.enumCase(Value, "NearStdCall", CallingConvention::NearStdCall); + IO.enumCase(Value, "FarStdCall", CallingConvention::FarStdCall); + IO.enumCase(Value, "NearSysCall", CallingConvention::NearSysCall); + IO.enumCase(Value, "FarSysCall", CallingConvention::FarSysCall); + IO.enumCase(Value, "ThisCall", CallingConvention::ThisCall); + IO.enumCase(Value, "MipsCall", CallingConvention::MipsCall); + IO.enumCase(Value, "Generic", CallingConvention::Generic); + IO.enumCase(Value, "AlphaCall", CallingConvention::AlphaCall); + IO.enumCase(Value, "PpcCall", CallingConvention::PpcCall); + IO.enumCase(Value, "SHCall", CallingConvention::SHCall); + IO.enumCase(Value, "ArmCall", CallingConvention::ArmCall); + IO.enumCase(Value, "AM33Call", CallingConvention::AM33Call); + IO.enumCase(Value, "TriCall", CallingConvention::TriCall); + IO.enumCase(Value, "SH5Call", CallingConvention::SH5Call); + IO.enumCase(Value, "M32RCall", CallingConvention::M32RCall); + IO.enumCase(Value, "ClrCall", CallingConvention::ClrCall); + IO.enumCase(Value, "Inline", CallingConvention::Inline); + IO.enumCase(Value, "NearVector", CallingConvention::NearVector); +} + +void ScalarEnumerationTraits::enumeration(IO &IO, + PointerKind &Kind) { + IO.enumCase(Kind, "Near16", PointerKind::Near16); + IO.enumCase(Kind, "Far16", PointerKind::Far16); + IO.enumCase(Kind, "Huge16", PointerKind::Huge16); + IO.enumCase(Kind, "BasedOnSegment", PointerKind::BasedOnSegment); + IO.enumCase(Kind, "BasedOnValue", PointerKind::BasedOnValue); + IO.enumCase(Kind, "BasedOnSegmentValue", PointerKind::BasedOnSegmentValue); + IO.enumCase(Kind, "BasedOnAddress", PointerKind::BasedOnAddress); + IO.enumCase(Kind, "BasedOnSegmentAddress", + PointerKind::BasedOnSegmentAddress); + IO.enumCase(Kind, "BasedOnType", PointerKind::BasedOnType); + IO.enumCase(Kind, "BasedOnSelf", PointerKind::BasedOnSelf); + IO.enumCase(Kind, "Near32", PointerKind::Near32); + IO.enumCase(Kind, "Far32", PointerKind::Far32); + IO.enumCase(Kind, "Near64", PointerKind::Near64); +} + +void ScalarEnumerationTraits::enumeration(IO &IO, + PointerMode &Mode) { + IO.enumCase(Mode, "Pointer", PointerMode::Pointer); + IO.enumCase(Mode, "LValueReference", PointerMode::LValueReference); + IO.enumCase(Mode, "PointerToDataMember", PointerMode::PointerToDataMember); + IO.enumCase(Mode, "PointerToMemberFunction", + PointerMode::PointerToMemberFunction); + IO.enumCase(Mode, "RValueReference", PointerMode::RValueReference); +} + +void ScalarEnumerationTraits::enumeration(IO &IO, HfaKind &Value) { + IO.enumCase(Value, "None", HfaKind::None); + IO.enumCase(Value, "Float", HfaKind::Float); + IO.enumCase(Value, "Double", HfaKind::Double); + IO.enumCase(Value, "Other", HfaKind::Other); +} + +void ScalarEnumerationTraits::enumeration(IO &IO, + MemberAccess &Access) { + IO.enumCase(Access, "None", MemberAccess::None); + IO.enumCase(Access, "Private", MemberAccess::Private); + IO.enumCase(Access, "Protected", MemberAccess::Protected); + IO.enumCase(Access, "Public", MemberAccess::Public); +} + +void ScalarEnumerationTraits::enumeration(IO &IO, + MethodKind &Kind) { + IO.enumCase(Kind, "Vanilla", MethodKind::Vanilla); + IO.enumCase(Kind, "Virtual", MethodKind::Virtual); + IO.enumCase(Kind, "Static", MethodKind::Static); + IO.enumCase(Kind, "Friend", MethodKind::Friend); + IO.enumCase(Kind, "IntroducingVirtual", MethodKind::IntroducingVirtual); + IO.enumCase(Kind, "PureVirtual", MethodKind::PureVirtual); + IO.enumCase(Kind, "PureIntroducingVirtual", + MethodKind::PureIntroducingVirtual); +} + +void ScalarEnumerationTraits::enumeration( + IO &IO, WindowsRTClassKind &Value) { + IO.enumCase(Value, "None", WindowsRTClassKind::None); + IO.enumCase(Value, "Ref", WindowsRTClassKind::RefClass); + IO.enumCase(Value, "Value", WindowsRTClassKind::ValueClass); + IO.enumCase(Value, "Interface", WindowsRTClassKind::Interface); +} + +void ScalarEnumerationTraits::enumeration(IO &IO, LabelType &Value) { + IO.enumCase(Value, "Near", LabelType::Near); + IO.enumCase(Value, "Far", LabelType::Far); +} + +void ScalarBitSetTraits::bitset(IO &IO, + PointerOptions &Options) { + IO.bitSetCase(Options, "None", PointerOptions::None); + IO.bitSetCase(Options, "Flat32", PointerOptions::Flat32); + IO.bitSetCase(Options, "Volatile", PointerOptions::Volatile); + IO.bitSetCase(Options, "Const", PointerOptions::Const); + IO.bitSetCase(Options, "Unaligned", PointerOptions::Unaligned); + IO.bitSetCase(Options, "Restrict", PointerOptions::Restrict); + IO.bitSetCase(Options, "WinRTSmartPointer", + PointerOptions::WinRTSmartPointer); +} + +void ScalarBitSetTraits::bitset(IO &IO, + ModifierOptions &Options) { + IO.bitSetCase(Options, "None", ModifierOptions::None); + IO.bitSetCase(Options, "Const", ModifierOptions::Const); + IO.bitSetCase(Options, "Volatile", ModifierOptions::Volatile); + IO.bitSetCase(Options, "Unaligned", ModifierOptions::Unaligned); +} + +void ScalarBitSetTraits::bitset(IO &IO, + FunctionOptions &Options) { + IO.bitSetCase(Options, "None", FunctionOptions::None); + IO.bitSetCase(Options, "CxxReturnUdt", FunctionOptions::CxxReturnUdt); + IO.bitSetCase(Options, "Constructor", FunctionOptions::Constructor); + IO.bitSetCase(Options, "ConstructorWithVirtualBases", + FunctionOptions::ConstructorWithVirtualBases); +} + +void ScalarBitSetTraits::bitset(IO &IO, ClassOptions &Options) { + IO.bitSetCase(Options, "None", ClassOptions::None); + IO.bitSetCase(Options, "HasConstructorOrDestructor", + ClassOptions::HasConstructorOrDestructor); + IO.bitSetCase(Options, "HasOverloadedOperator", + ClassOptions::HasOverloadedOperator); + IO.bitSetCase(Options, "Nested", ClassOptions::Nested); + IO.bitSetCase(Options, "ContainsNestedClass", + ClassOptions::ContainsNestedClass); + IO.bitSetCase(Options, "HasOverloadedAssignmentOperator", + ClassOptions::HasOverloadedAssignmentOperator); + IO.bitSetCase(Options, "HasConversionOperator", + ClassOptions::HasConversionOperator); + IO.bitSetCase(Options, "ForwardReference", ClassOptions::ForwardReference); + IO.bitSetCase(Options, "Scoped", ClassOptions::Scoped); + IO.bitSetCase(Options, "HasUniqueName", ClassOptions::HasUniqueName); + IO.bitSetCase(Options, "Sealed", ClassOptions::Sealed); + IO.bitSetCase(Options, "Intrinsic", ClassOptions::Intrinsic); +} + +void ScalarBitSetTraits::bitset(IO &IO, MethodOptions &Options) { + IO.bitSetCase(Options, "None", MethodOptions::None); + IO.bitSetCase(Options, "Pseudo", MethodOptions::Pseudo); + IO.bitSetCase(Options, "NoInherit", MethodOptions::NoInherit); + IO.bitSetCase(Options, "NoConstruct", MethodOptions::NoConstruct); + IO.bitSetCase(Options, "CompilerGenerated", MethodOptions::CompilerGenerated); + IO.bitSetCase(Options, "Sealed", MethodOptions::Sealed); +} + +void MappingTraits::mapping(IO &IO, MemberPointerInfo &MPI) { + IO.mapRequired("ContainingType", MPI.ContainingType); + IO.mapRequired("Representation", MPI.Representation); +} + +namespace llvm { +namespace CodeViewYAML { +namespace detail { + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ModifiedType", Record.ModifiedType); + IO.mapRequired("Modifiers", Record.Modifiers); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ReturnType", Record.ReturnType); + IO.mapRequired("CallConv", Record.CallConv); + IO.mapRequired("Options", Record.Options); + IO.mapRequired("ParameterCount", Record.ParameterCount); + IO.mapRequired("ArgumentList", Record.ArgumentList); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ReturnType", Record.ReturnType); + IO.mapRequired("ClassType", Record.ClassType); + IO.mapRequired("ThisType", Record.ThisType); + IO.mapRequired("CallConv", Record.CallConv); + IO.mapRequired("Options", Record.Options); + IO.mapRequired("ParameterCount", Record.ParameterCount); + IO.mapRequired("ArgumentList", Record.ArgumentList); + IO.mapRequired("ThisPointerAdjustment", Record.ThisPointerAdjustment); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("Mode", Record.Mode); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ClassType", Record.ClassType); + IO.mapRequired("FunctionType", Record.FunctionType); + IO.mapRequired("Name", Record.Name); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ArgIndices", Record.ArgIndices); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("StringIndices", Record.StringIndices); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ReferentType", Record.ReferentType); + IO.mapRequired("Attrs", Record.Attrs); + IO.mapOptional("MemberInfo", Record.MemberInfo); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ElementType", Record.ElementType); + IO.mapRequired("IndexType", Record.IndexType); + IO.mapRequired("Size", Record.Size); + IO.mapRequired("Name", Record.Name); +} + +void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("FieldList", Members); +} + +} // end namespace detail +} // end namespace CodeViewYAML +} // end namespace llvm + +namespace { + +class MemberRecordConversionVisitor : public TypeVisitorCallbacks { +public: + explicit MemberRecordConversionVisitor(std::vector &Records) + : Records(Records) {} + +#define TYPE_RECORD(EnumName, EnumVal, Name) +#define MEMBER_RECORD(EnumName, EnumVal, Name) \ + Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override { \ + return visitKnownMemberImpl(Record); \ + } +#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) +#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) +#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" +private: + template Error visitKnownMemberImpl(T &Record) { + TypeLeafKind K = static_cast(Record.getKind()); + auto Impl = std::make_shared>(K); + Impl->Record = Record; + Records.push_back(MemberRecord{Impl}); + return Error::success(); + } + + std::vector &Records; +}; + +} // end anonymous namespace + +Error LeafRecordImpl::fromCodeViewRecord(CVType Type) { + MemberRecordConversionVisitor V(Members); + return visitMemberRecordStream(Type.content(), V); +} + +CVType LeafRecordImpl::toCodeViewRecord( + AppendingTypeTableBuilder &TS) const { + ContinuationRecordBuilder CRB; + CRB.begin(ContinuationRecordKind::FieldList); + for (const auto &Member : Members) { + Member.Member->writeTo(CRB); + } + TS.insertRecord(CRB); + return CVType(Kind, TS.records().back()); +} + +void MappingTraits::mapping(IO &io, OneMethodRecord &Record) { + io.mapRequired("Type", Record.Type); + io.mapRequired("Attrs", Record.Attrs.Attrs); + io.mapRequired("VFTableOffset", Record.VFTableOffset); + io.mapRequired("Name", Record.Name); +} + +namespace llvm { +namespace CodeViewYAML { +namespace detail { + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("MemberCount", Record.MemberCount); + IO.mapRequired("Options", Record.Options); + IO.mapRequired("FieldList", Record.FieldList); + IO.mapRequired("Name", Record.Name); + IO.mapRequired("UniqueName", Record.UniqueName); + IO.mapRequired("DerivationList", Record.DerivationList); + IO.mapRequired("VTableShape", Record.VTableShape); + IO.mapRequired("Size", Record.Size); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("MemberCount", Record.MemberCount); + IO.mapRequired("Options", Record.Options); + IO.mapRequired("FieldList", Record.FieldList); + IO.mapRequired("Name", Record.Name); + IO.mapRequired("UniqueName", Record.UniqueName); + IO.mapRequired("Size", Record.Size); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("NumEnumerators", Record.MemberCount); + IO.mapRequired("Options", Record.Options); + IO.mapRequired("FieldList", Record.FieldList); + IO.mapRequired("Name", Record.Name); + IO.mapRequired("UniqueName", Record.UniqueName); + IO.mapRequired("UnderlyingType", Record.UnderlyingType); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("Type", Record.Type); + IO.mapRequired("BitSize", Record.BitSize); + IO.mapRequired("BitOffset", Record.BitOffset); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("Slots", Record.Slots); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("Guid", Record.Guid); + IO.mapRequired("Age", Record.Age); + IO.mapRequired("Name", Record.Name); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("Id", Record.Id); + IO.mapRequired("String", Record.String); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ParentScope", Record.ParentScope); + IO.mapRequired("FunctionType", Record.FunctionType); + IO.mapRequired("Name", Record.Name); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("UDT", Record.UDT); + IO.mapRequired("SourceFile", Record.SourceFile); + IO.mapRequired("LineNumber", Record.LineNumber); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("UDT", Record.UDT); + IO.mapRequired("SourceFile", Record.SourceFile); + IO.mapRequired("LineNumber", Record.LineNumber); + IO.mapRequired("Module", Record.Module); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("ArgIndices", Record.ArgIndices); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("CompleteClass", Record.CompleteClass); + IO.mapRequired("OverriddenVFTable", Record.OverriddenVFTable); + IO.mapRequired("VFPtrOffset", Record.VFPtrOffset); + IO.mapRequired("MethodNames", Record.MethodNames); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("Methods", Record.Methods); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("StartTypeIndex", Record.StartTypeIndex); + IO.mapRequired("TypesCount", Record.TypesCount); + IO.mapRequired("Signature", Record.Signature); + IO.mapRequired("PrecompFilePath", Record.PrecompFilePath); +} + +template <> void LeafRecordImpl::map(IO &IO) { + IO.mapRequired("Signature", Record.Signature); +} + +template <> void MemberRecordImpl::map(IO &IO) { + MappingTraits::mapping(IO, Record); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("NumOverloads", Record.NumOverloads); + IO.mapRequired("MethodList", Record.MethodList); + IO.mapRequired("Name", Record.Name); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("Type", Record.Type); + IO.mapRequired("Name", Record.Name); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("Attrs", Record.Attrs.Attrs); + IO.mapRequired("Type", Record.Type); + IO.mapRequired("FieldOffset", Record.FieldOffset); + IO.mapRequired("Name", Record.Name); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("Attrs", Record.Attrs.Attrs); + IO.mapRequired("Type", Record.Type); + IO.mapRequired("Name", Record.Name); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("Attrs", Record.Attrs.Attrs); + IO.mapRequired("Value", Record.Value); + IO.mapRequired("Name", Record.Name); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("Type", Record.Type); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("Attrs", Record.Attrs.Attrs); + IO.mapRequired("Type", Record.Type); + IO.mapRequired("Offset", Record.Offset); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("Attrs", Record.Attrs.Attrs); + IO.mapRequired("BaseType", Record.BaseType); + IO.mapRequired("VBPtrType", Record.VBPtrType); + IO.mapRequired("VBPtrOffset", Record.VBPtrOffset); + IO.mapRequired("VTableIndex", Record.VTableIndex); +} + +template <> void MemberRecordImpl::map(IO &IO) { + IO.mapRequired("ContinuationIndex", Record.ContinuationIndex); +} + +} // end namespace detail +} // end namespace CodeViewYAML +} // end namespace llvm + +template +static inline Expected fromCodeViewRecordImpl(CVType Type) { + LeafRecord Result; + + auto Impl = std::make_shared>(Type.kind()); + if (auto EC = Impl->fromCodeViewRecord(Type)) + return std::move(EC); + Result.Leaf = Impl; + return Result; +} + +Expected LeafRecord::fromCodeViewRecord(CVType Type) { +#define TYPE_RECORD(EnumName, EnumVal, ClassName) \ + case EnumName: \ + return fromCodeViewRecordImpl(Type); +#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \ + TYPE_RECORD(EnumName, EnumVal, ClassName) +#define MEMBER_RECORD(EnumName, EnumVal, ClassName) +#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) + switch (Type.kind()) { +#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" + default: + llvm_unreachable("Unknown leaf kind!"); + } + return make_error(cv_error_code::corrupt_record); +} + +CVType +LeafRecord::toCodeViewRecord(AppendingTypeTableBuilder &Serializer) const { + return Leaf->toCodeViewRecord(Serializer); +} + +namespace llvm { +namespace yaml { + +template <> struct MappingTraits { + static void mapping(IO &io, LeafRecordBase &Record) { Record.map(io); } +}; + +template <> struct MappingTraits { + static void mapping(IO &io, MemberRecordBase &Record) { Record.map(io); } +}; + +} // end namespace yaml +} // end namespace llvm + +template +static void mapLeafRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind, + LeafRecord &Obj) { + if (!IO.outputting()) + Obj.Leaf = std::make_shared>(Kind); + + if (Kind == LF_FIELDLIST) + Obj.Leaf->map(IO); + else + IO.mapRequired(Class, *Obj.Leaf); +} + +void MappingTraits::mapping(IO &IO, LeafRecord &Obj) { + TypeLeafKind Kind; + if (IO.outputting()) + Kind = Obj.Leaf->Kind; + IO.mapRequired("Kind", Kind); + +#define TYPE_RECORD(EnumName, EnumVal, ClassName) \ + case EnumName: \ + mapLeafRecordImpl(IO, #ClassName, Kind, Obj); \ + break; +#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \ + TYPE_RECORD(EnumName, EnumVal, ClassName) +#define MEMBER_RECORD(EnumName, EnumVal, ClassName) +#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) + switch (Kind) { +#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" + default: { llvm_unreachable("Unknown leaf kind!"); } + } +} + +template +static void mapMemberRecordImpl(IO &IO, const char *Class, TypeLeafKind Kind, + MemberRecord &Obj) { + if (!IO.outputting()) + Obj.Member = std::make_shared>(Kind); + + IO.mapRequired(Class, *Obj.Member); +} + +void MappingTraits::mapping(IO &IO, MemberRecord &Obj) { + TypeLeafKind Kind; + if (IO.outputting()) + Kind = Obj.Member->Kind; + IO.mapRequired("Kind", Kind); + +#define MEMBER_RECORD(EnumName, EnumVal, ClassName) \ + case EnumName: \ + mapMemberRecordImpl(IO, #ClassName, Kind, Obj); \ + break; +#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) \ + MEMBER_RECORD(EnumName, EnumVal, ClassName) +#define TYPE_RECORD(EnumName, EnumVal, ClassName) +#define TYPE_RECORD_ALIAS(EnumName, EnumVal, AliasName, ClassName) + switch (Kind) { +#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" + default: { llvm_unreachable("Unknown member kind!"); } + } +} + +std::vector +llvm::CodeViewYAML::fromDebugT(ArrayRef DebugTorP, + StringRef SectionName) { + ExitOnError Err("Invalid " + std::string(SectionName) + " section!"); + BinaryStreamReader Reader(DebugTorP, support::little); + CVTypeArray Types; + uint32_t Magic; + + Err(Reader.readInteger(Magic)); + assert(Magic == COFF::DEBUG_SECTION_MAGIC && + "Invalid .debug$T or .debug$P section!"); + + std::vector Result; + Err(Reader.readArray(Types, Reader.bytesRemaining())); + for (const auto &T : Types) { + auto CVT = Err(LeafRecord::fromCodeViewRecord(T)); + Result.push_back(CVT); + } + return Result; +} + +ArrayRef llvm::CodeViewYAML::toDebugT(ArrayRef Leafs, + BumpPtrAllocator &Alloc, + StringRef SectionName) { + AppendingTypeTableBuilder TS(Alloc); + uint32_t Size = sizeof(uint32_t); + for (const auto &Leaf : Leafs) { + CVType T = Leaf.Leaf->toCodeViewRecord(TS); + Size += T.length(); + assert(T.length() % 4 == 0 && "Improper type record alignment!"); + } + uint8_t *ResultBuffer = Alloc.Allocate(Size); + MutableArrayRef Output(ResultBuffer, Size); + BinaryStreamWriter Writer(Output, support::little); + ExitOnError Err("Error writing type record to " + std::string(SectionName) + + " section"); + Err(Writer.writeInteger(COFF::DEBUG_SECTION_MAGIC)); + for (const auto &R : TS.records()) { + Err(Writer.writeBytes(R)); + } + assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!"); + return Output; +} Index: test/DebugInfo/precomp.test =================================================================== --- test/DebugInfo/precomp.test +++ test/DebugInfo/precomp.test @@ -0,0 +1,67 @@ + +RUN: rm -rf %t1/ +RUN: mkdir %t1 +RUN: obj2yaml %S/Inputs/precomp-a.obj > %t1/precomp-a.yaml +RUN: obj2yaml %S/Inputs/precomp.obj > %t1/precomp.yaml +RUN: yaml2obj %t1/precomp-a.yaml > %t1/a.obj +RUN: yaml2obj %t1/precomp.yaml > %t1/precomp.obj +RUN: llvm-readobj -codeview %t1/a.obj | FileCheck %s -check-prefix PRECOMP +RUN: llvm-readobj -codeview %t1/precomp.obj | FileCheck %s -check-prefix ENDPRECOMP +RUN: llvm-pdbutil dump -all %t1/a.obj | FileCheck %s -check-prefix PDB-PRECOMP +RUN: llvm-pdbutil dump -all %t1/precomp.obj | FileCheck %s -check-prefix PDB-ENDPRECOMP + +ENDPRECOMP: CodeViewTypes [ +ENDPRECOMP-NEXT: Section: .debug$P (3) +ENDPRECOMP: EndPrecomp (0x1407) { +ENDPRECOMP-NEXT: TypeLeafKind: LF_ENDPRECOMP (0x14) +ENDPRECOMP-NEXT: Signature: 0x1116980E +ENDPRECOMP-NEXT: } + +PRECOMP: CodeViewTypes [ +PRECOMP-NEXT: Section: .debug$T (3) +PRECOMP-NEXT: Magic: 0x4 +PRECOMP-NEXT: Precomp (0x1000) { +PRECOMP-NEXT: TypeLeafKind: LF_PRECOMP (0x1509) +PRECOMP-NEXT: StartIndex: 4096 +PRECOMP-NEXT: Count: 1031 +PRECOMP-NEXT: Signature: 0x1116980E + +PDB-PRECOMP: Cross Module Exports +PDB-PRECOMP-NEXT: ============================================================ +PDB-PRECOMP-NEXT: Mod 0000 | `.debug$S`: +PDB-PRECOMP-NEXT: Showing 0 records +PDB-PRECOMP-NEXT: 0x1000 | LF_PRECOMP [size = 60] start index = 4096, types count = 1031, signature = 0x1116980E, precomp path = f:\svn\lld\test\coff\precomp\precomp.obj + +PDB-ENDPRECOMP: Cross Module Exports +PDB-ENDPRECOMP-NEXT: ============================================================ +PDB-ENDPRECOMP-NEXT: Mod 0000 | `.debug$S`: +PDB-ENDPRECOMP-NEXT: Mod 0001 | `.debug$S`: +PDB-ENDPRECOMP-NEXT: Showing 0 records +PDB-ENDPRECOMP: 0x1407 | LF_ENDPRECOMP [size = 8] signature = 0x1116980E + +# // precomp.h +# #pragma once +# int Function(char A); +# +# // precomp.cpp +# // cl.exe precomp.cpp /Z7 /Ycprecomp.h /c +# #include "precomp.h" +# +# // a.cpp +# #include "precomp.h" +# int main(void) { +# Function('a'); +# return 0; +# } +# +# // b.cpp +# #include "precomp.h" +# int Function(char a) { +# return (int)a; +# } +# +# // cl.exe a.cpp b.cpp /Z7 /Yuprecomp.h /c +# +# // obj2yaml precomp.obj >precomp-precomp.yaml +# // obj2yaml a.obj >precomp-a.yaml +# // obj2yaml b.obj >precomp-b.yaml Index: tools/llvm-pdbutil/DumpOutputStyle.cpp =================================================================== --- tools/llvm-pdbutil/DumpOutputStyle.cpp +++ tools/llvm-pdbutil/DumpOutputStyle.cpp @@ -1058,7 +1058,7 @@ if (auto EC = S.getName(SectionName)) return errorCodeToError(EC); - if (SectionName != ".debug$T") + if (SectionName != ".debug$T" && SectionName != ".debug$P") continue; StringRef Contents; if (auto EC = S.getContents(Contents)) Index: tools/llvm-pdbutil/InputFile.cpp =================================================================== --- tools/llvm-pdbutil/InputFile.cpp +++ tools/llvm-pdbutil/InputFile.cpp @@ -95,7 +95,8 @@ static bool isDebugTSection(SectionRef Section, CVTypeArray &Types) { BinaryStreamReader Reader; - if (!isCodeViewDebugSubsection(Section, ".debug$T", Reader)) + if (!isCodeViewDebugSubsection(Section, ".debug$T", Reader) && + !isCodeViewDebugSubsection(Section, ".debug$P", Reader)) return false; cantFail(Reader.readArray(Types, Reader.bytesRemaining())); return true; Index: tools/llvm-pdbutil/MinimalTypeDumper.cpp =================================================================== --- tools/llvm-pdbutil/MinimalTypeDumper.cpp +++ tools/llvm-pdbutil/MinimalTypeDumper.cpp @@ -464,16 +464,33 @@ Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, LabelRecord &R) { std::string Type = (R.Mode == LabelType::Far) ? "far" : "near"; P.format(" type = {0}", Type); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + PrecompRecord &Precomp) { + std::string Signature = "0x" + utohexstr(Precomp.Signature); + P.format(" start index = {0}, types count = {1}, signature = {2}," + " precomp path = {3}", + Precomp.StartTypeIndex, Precomp.TypesCount, Signature, + Precomp.PrecompFilePath); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + EndPrecompRecord &EP) { + std::string Signature = "0x" + utohexstr(EP.Signature); + P.format(" signature = {0}", Signature); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + NestedTypeRecord &Nested) { + P.format(" [name = `{0}`, parent = {1}]", Nested.Name, Nested.Type); return Error::success(); } Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - NestedTypeRecord &Nested) { - P.format(" [name = `{0}`, parent = {1}]", Nested.Name, Nested.Type); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, OneMethodRecord &Method) { P.format(" [name = `{0}`]", Method.Name); AutoIndent Indent(P); Index: tools/llvm-readobj/COFFDumper.cpp =================================================================== --- tools/llvm-readobj/COFFDumper.cpp +++ tools/llvm-readobj/COFFDumper.cpp @@ -902,7 +902,7 @@ for (const SectionRef &S : Obj->sections()) { StringRef SectionName; error(S.getName(SectionName)); - if (SectionName == ".debug$T") + if (SectionName == ".debug$T" || SectionName == ".debug$P") printCodeViewTypeSection(SectionName, S); } for (const SectionRef &S : Obj->sections()) { @@ -1206,7 +1206,7 @@ for (const SectionRef &S : Obj->sections()) { StringRef SectionName; error(S.getName(SectionName)); - if (SectionName == ".debug$T") { + if (SectionName == ".debug$T" || SectionName == ".debug$P") { StringRef Data; error(S.getContents(Data)); uint32_t Magic; Index: tools/obj2yaml/coff2yaml.cpp =================================================================== --- tools/obj2yaml/coff2yaml.cpp +++ tools/obj2yaml/coff2yaml.cpp @@ -170,7 +170,11 @@ if (NewYAMLSection.Name == ".debug$S") NewYAMLSection.DebugS = CodeViewYAML::fromDebugS(sectionData, SC); else if (NewYAMLSection.Name == ".debug$T") - NewYAMLSection.DebugT = CodeViewYAML::fromDebugT(sectionData); + NewYAMLSection.DebugT = CodeViewYAML::fromDebugT(sectionData, + NewYAMLSection.Name); + else if (NewYAMLSection.Name == ".debug$P") + NewYAMLSection.DebugP = CodeViewYAML::fromDebugT(sectionData, + NewYAMLSection.Name); else if (NewYAMLSection.Name == ".debug$H") NewYAMLSection.DebugH = CodeViewYAML::fromDebugH(sectionData); Index: tools/yaml2obj/yaml2coff.cpp =================================================================== --- tools/yaml2obj/yaml2coff.cpp +++ tools/yaml2obj/yaml2coff.cpp @@ -233,7 +233,10 @@ } } else if (S.Name == ".debug$T") { if (S.SectionData.binary_size() == 0) - S.SectionData = CodeViewYAML::toDebugT(S.DebugT, CP.Allocator); + S.SectionData = CodeViewYAML::toDebugT(S.DebugT, CP.Allocator, S.Name); + } else if (S.Name == ".debug$P") { + if (S.SectionData.binary_size() == 0) + S.SectionData = CodeViewYAML::toDebugT(S.DebugP, CP.Allocator, S.Name); } else if (S.Name == ".debug$H") { if (S.DebugH.hasValue() && S.SectionData.binary_size() == 0) S.SectionData = CodeViewYAML::toDebugH(*S.DebugH, CP.Allocator); Index: unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp =================================================================== --- unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp +++ unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp @@ -1,582 +1,595 @@ -//===- llvm/unittest/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp --------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h" - -#include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h" -#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h" -#include "llvm/DebugInfo/CodeView/SymbolSerializer.h" -#include "llvm/Support/Allocator.h" - -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -using namespace llvm; -using namespace llvm::codeview; - -class TypeIndexIteratorTest : public testing::Test { -public: - TypeIndexIteratorTest() {} - - void SetUp() override { - Refs.clear(); - TTB = make_unique(Storage); - CRB = make_unique(); - Symbols.clear(); - } - - void TearDown() override { - CRB.reset(); - TTB.reset(); - } - -protected: - template - bool checkTypeReferences(uint32_t RecordIndex, Indices &&... TIs) const { - EXPECT_EQ(sizeof...(Indices), countRefs(RecordIndex)); - - // Choose between type or symbol records. The checking code doesn't care - // which we have. - std::vector> CVRecords; - if (Symbols.empty()) { - CVRecords = TTB->records(); - } else { - for (const CVSymbol &S : Symbols) - CVRecords.push_back(S.data()); - } - - return checkTypeReferencesImpl(RecordIndex, CVRecords, - std::forward(TIs)...); - } - - template void writeFieldList(T &&... MemberRecords) { - CRB->begin(ContinuationRecordKind::FieldList); - writeFieldListImpl(std::forward(MemberRecords)...); - auto Records = CRB->end(TTB->nextTypeIndex()); - ASSERT_EQ(1u, Records.size()); - TTB->insertRecordBytes(Records.front().RecordData); - discoverAllTypeIndices(); - } - - template void writeTypeRecords(T &&... Records) { - writeTypeRecordsImpl(std::forward(Records)...); - ASSERT_EQ(sizeof...(T), TTB->records().size()); - discoverAllTypeIndices(); - } - - template void writeSymbolRecords(T &&... Records) { - writeSymbolRecordsImpl(std::forward(Records)...); - ASSERT_EQ(sizeof...(T), Symbols.size()); - discoverTypeIndicesInSymbols(); - } - - std::unique_ptr TTB; - -private: - uint32_t countRefs(uint32_t RecordIndex) const { - auto &R = Refs[RecordIndex]; - uint32_t Count = 0; - for (auto &Ref : R) { - Count += Ref.Count; - } - return Count; - } - - bool checkOneTypeReference(uint32_t RecordIndex, ArrayRef RecordData, - TypeIndex TI) const { - RecordData = RecordData.drop_front(sizeof(RecordPrefix)); - auto &RefList = Refs[RecordIndex]; - for (auto &Ref : RefList) { - uint32_t Offset = Ref.Offset; - ArrayRef Loc = RecordData.drop_front(Offset); - ArrayRef Indices( - reinterpret_cast(Loc.data()), Ref.Count); - if (llvm::any_of(Indices, - [TI](const TypeIndex &Other) { return Other == TI; })) - return true; - } - return false; - } - - template - bool checkTypeReferencesImpl(uint32_t RecordIndex, - ArrayRef> CVRecords) const { - return true; - } - - template - bool checkTypeReferencesImpl(uint32_t RecordIndex, - ArrayRef> CVRecords, - TypeIndex TI, Indices &&... Rest) const { - ArrayRef Record = CVRecords[RecordIndex]; - bool Success = checkOneTypeReference(RecordIndex, Record, TI); - EXPECT_TRUE(Success); - return Success & checkTypeReferencesImpl(RecordIndex, CVRecords, - std::forward(Rest)...); - } - - void discoverAllTypeIndices() { - Refs.resize(TTB->records().size()); - for (uint32_t I = 0; I < TTB->records().size(); ++I) { - ArrayRef Data = TTB->records()[I]; - discoverTypeIndices(Data, Refs[I]); - } - } - - void discoverTypeIndicesInSymbols() { - Refs.resize(Symbols.size()); - for (uint32_t I = 0; I < Symbols.size(); ++I) - discoverTypeIndicesInSymbol(Symbols[I], Refs[I]); - } - - // Helper function to write out a field list record with the given list - // of member records. - void writeFieldListImpl() {} - - template - void writeFieldListImpl(RecType &&Record, Rest &&... Records) { - CRB->writeMemberType(Record); - writeFieldListImpl(std::forward(Records)...); - } - - // Helper function to write out a list of type records. - void writeTypeRecordsImpl() {} - - template - void writeTypeRecordsImpl(RecType &&Record, Rest &&... Records) { - TTB->writeLeafType(Record); - writeTypeRecordsImpl(std::forward(Records)...); - } - - // Helper function to write out a list of symbol records. - void writeSymbolRecordsImpl() {} - - template - void writeSymbolRecordsImpl(RecType &&Record, Rest &&... Records) { - Symbols.push_back(SymbolSerializer::writeOneSymbol(Record, Storage, - CodeViewContainer::Pdb)); - writeSymbolRecordsImpl(std::forward(Records)...); - } - - std::vector> Refs; - std::unique_ptr CRB; - std::vector Symbols; - BumpPtrAllocator Storage; -}; - -namespace leafs { -static FuncIdRecord FuncId(TypeIndex(1), TypeIndex(2), "FuncId"); -static MemberFuncIdRecord MemFuncId(TypeIndex(3), TypeIndex(4), "FuncId"); -static StringIdRecord StringId(TypeIndex(5), "TheString"); -static struct { - std::vector Ids = {TypeIndex(6), TypeIndex(7), TypeIndex(8)}; - StringListRecord Record{TypeRecordKind::StringList, Ids}; -} StringList; -static struct { - std::vector Ids = {TypeIndex(9), TypeIndex(10), TypeIndex(11)}; - BuildInfoRecord Record{Ids}; -} BuildInfo; -static UdtSourceLineRecord UdtSourceLine(TypeIndex(12), TypeIndex(13), 0); -static UdtModSourceLineRecord UdtModSourceLine(TypeIndex(14), TypeIndex(15), 0, - 0); -static ModifierRecord Modifier(TypeIndex(16), ModifierOptions::None); -static ProcedureRecord Procedure(TypeIndex(17), CallingConvention::PpcCall, - FunctionOptions::None, 0, TypeIndex(18)); -static MemberFunctionRecord MemberFunction(TypeIndex(19), TypeIndex(20), - TypeIndex(21), - CallingConvention::ThisCall, - FunctionOptions::None, 2, - TypeIndex(22), 0); -static struct { - std::vector Ids = {TypeIndex(23), TypeIndex(24), TypeIndex(25)}; - ArgListRecord Record{TypeRecordKind::ArgList, Ids}; -} ArgList; -static ArrayRecord Array(TypeIndex(26), TypeIndex(27), 10, "MyArray"); -static ClassRecord Class(TypeRecordKind::Class, 3, ClassOptions::None, - TypeIndex(28), TypeIndex(29), TypeIndex(30), 10, - "MyClass", "MyClassUniqueName"); -static ClassRecord Struct(TypeRecordKind::Struct, 3, ClassOptions::None, - TypeIndex(31), TypeIndex(32), TypeIndex(33), 10, - "MyClass", "MyClassUniqueName"); -static UnionRecord Union(1, ClassOptions::None, TypeIndex(34), 10, "MyUnion", - "MyUnionUniqueName"); -static EnumRecord Enum(1, ClassOptions::None, TypeIndex(35), "MyEnum", - "EnumUniqueName", TypeIndex(36)); -static BitFieldRecord BitField(TypeIndex(37), 1, 0); -static VFTableRecord VFTable(TypeIndex(38), TypeIndex(39), 1, "VFT", {}); -static VFTableShapeRecord VTableShape({}); -static struct { - const TypeIndex T1{40}; - const TypeIndex T2{41}; - const TypeIndex T3{42}; - const TypeIndex T4{43}; - - std::vector Methods{ - {T1, MemberAccess::Public, MethodKind::IntroducingVirtual, - MethodOptions::None, 0, "Method1"}, - {T2, MemberAccess::Public, MethodKind::PureVirtual, MethodOptions::None, - 0, "Method1"}, - {T3, MemberAccess::Public, MethodKind::PureIntroducingVirtual, - MethodOptions::None, 0, "Method1"}, - {T4, MemberAccess::Public, MethodKind::Static, MethodOptions::None, 0, - "Method1"}}; - - MethodOverloadListRecord Record{Methods}; -} MethodOverloadList; -static PointerRecord Pointer(TypeIndex(44), PointerKind::Near32, - PointerMode::Pointer, PointerOptions::Const, 3); -static PointerRecord MemberPointer( - TypeIndex(45), PointerKind::Near32, PointerMode::PointerToDataMember, - PointerOptions::Const, 3, - MemberPointerInfo(TypeIndex(46), - PointerToMemberRepresentation::GeneralData)); -} - -namespace members { -static BaseClassRecord BaseClass(MemberAccess::Public, TypeIndex(47), 0); -static EnumeratorRecord Enumerator(MemberAccess::Public, - APSInt(APInt(8, 3, false)), "Test"); -DataMemberRecord DataMember(MemberAccess::Public, TypeIndex(48), 0, "Test"); -OverloadedMethodRecord OverloadedMethod(3, TypeIndex(49), "MethodList"); -static struct { - const TypeIndex T1{50}; - const TypeIndex T2{51}; - const TypeIndex T3{52}; - const TypeIndex T4{53}; - OneMethodRecord R1{T1, - MemberAccess::Public, - MethodKind::IntroducingVirtual, - MethodOptions::None, - 0, - "M1"}; - OneMethodRecord R2{T2, - MemberAccess::Public, - MethodKind::PureVirtual, - MethodOptions::None, - 0, - "M2"}; - OneMethodRecord R3{T3, - MemberAccess::Public, - MethodKind::PureIntroducingVirtual, - MethodOptions::None, - 0, - "M3"}; - OneMethodRecord R4{T4, - MemberAccess::Protected, - MethodKind::Vanilla, - MethodOptions::CompilerGenerated, - 0, - "M4"}; -} OneMethod; -static NestedTypeRecord NestedType(TypeIndex(54), "MyClass"); -static StaticDataMemberRecord StaticDataMember(MemberAccess::Public, - TypeIndex(55), "Foo"); -static VirtualBaseClassRecord VirtualBaseClass(TypeRecordKind::VirtualBaseClass, - MemberAccess::Public, - TypeIndex(56), TypeIndex(57), 0, - 0); -static VFPtrRecord VFPtr(TypeIndex(58)); -static ListContinuationRecord Continuation(TypeIndex(59)); -} - -TEST_F(TypeIndexIteratorTest, FuncId) { - using namespace leafs; - writeTypeRecords(FuncId); - checkTypeReferences(0, FuncId.FunctionType, FuncId.ParentScope); -} - -TEST_F(TypeIndexIteratorTest, MemFuncId) { - using namespace leafs; - writeTypeRecords(MemFuncId); - checkTypeReferences(0, MemFuncId.ClassType, MemFuncId.FunctionType); -} - -TEST_F(TypeIndexIteratorTest, StringId) { - using namespace leafs; - writeTypeRecords(StringId); - checkTypeReferences(0, StringId.Id); -} - -TEST_F(TypeIndexIteratorTest, SubstrList) { - using namespace leafs; - writeTypeRecords(StringList.Record); - checkTypeReferences(0, StringList.Ids[0], StringList.Ids[1], - StringList.Ids[2]); -} - -TEST_F(TypeIndexIteratorTest, BuildInfo) { - using namespace leafs; - writeTypeRecords(BuildInfo.Record); - checkTypeReferences(0, BuildInfo.Ids[0], BuildInfo.Ids[1], BuildInfo.Ids[2]); -} - -TEST_F(TypeIndexIteratorTest, UdtSrcLine) { - using namespace leafs; - writeTypeRecords(UdtSourceLine); - checkTypeReferences(0, UdtSourceLine.UDT, UdtSourceLine.SourceFile); -} - -TEST_F(TypeIndexIteratorTest, UdtModSrcLine) { - using namespace leafs; - writeTypeRecords(UdtModSourceLine); - checkTypeReferences(0, UdtModSourceLine.UDT, UdtModSourceLine.SourceFile); -} - -TEST_F(TypeIndexIteratorTest, Modifier) { - using namespace leafs; - writeTypeRecords(Modifier); - checkTypeReferences(0, Modifier.ModifiedType); -} - -TEST_F(TypeIndexIteratorTest, Procedure) { - using namespace leafs; - writeTypeRecords(Procedure); - checkTypeReferences(0, Procedure.ReturnType, Procedure.ArgumentList); -} - -TEST_F(TypeIndexIteratorTest, MemFunc) { - using namespace leafs; - writeTypeRecords(MemberFunction); - checkTypeReferences(0, MemberFunction.ReturnType, MemberFunction.ClassType, - MemberFunction.ThisType, MemberFunction.ArgumentList); -} - -TEST_F(TypeIndexIteratorTest, ArgList) { - using namespace leafs; - writeTypeRecords(ArgList.Record); - checkTypeReferences(0, ArgList.Ids[0], ArgList.Ids[1], ArgList.Ids[2]); -} - -TEST_F(TypeIndexIteratorTest, Array) { - using namespace leafs; - writeTypeRecords(Array); - checkTypeReferences(0, Array.ElementType, Array.IndexType); -} - -TEST_F(TypeIndexIteratorTest, Class) { - using namespace leafs; - writeTypeRecords(Class); - checkTypeReferences(0, Class.FieldList, Class.DerivationList, - Class.VTableShape); -} - -TEST_F(TypeIndexIteratorTest, Struct) { - using namespace leafs; - writeTypeRecords(Struct); - checkTypeReferences(0, Struct.FieldList, Struct.DerivationList, - Struct.VTableShape); -} - -TEST_F(TypeIndexIteratorTest, Union) { - using namespace leafs; - writeTypeRecords(Union); - checkTypeReferences(0, Union.FieldList); -} - -TEST_F(TypeIndexIteratorTest, Enum) { - using namespace leafs; - writeTypeRecords(Enum); - checkTypeReferences(0, Enum.FieldList, Enum.UnderlyingType); -} - -TEST_F(TypeIndexIteratorTest, Bitfield) { - using namespace leafs; - writeTypeRecords(BitField); - checkTypeReferences(0, BitField.Type); -} - -TEST_F(TypeIndexIteratorTest, VTable) { - using namespace leafs; - writeTypeRecords(VFTable); - checkTypeReferences(0, VFTable.CompleteClass, VFTable.OverriddenVFTable); -} - -TEST_F(TypeIndexIteratorTest, VTShape) { - using namespace leafs; - writeTypeRecords(VTableShape); - checkTypeReferences(0); -} - -TEST_F(TypeIndexIteratorTest, OverloadList) { - using namespace leafs; - writeTypeRecords(MethodOverloadList.Record); - checkTypeReferences(0, MethodOverloadList.T1, MethodOverloadList.T2, - MethodOverloadList.T3, MethodOverloadList.T4); -} - -TEST_F(TypeIndexIteratorTest, Pointer) { - using namespace leafs; - writeTypeRecords(Pointer); - checkTypeReferences(0, Pointer.ReferentType); -} - -TEST_F(TypeIndexIteratorTest, MemberPointer) { - using namespace leafs; - writeTypeRecords(MemberPointer); - checkTypeReferences(0, MemberPointer.ReferentType, - MemberPointer.MemberInfo->ContainingType); -} - -TEST_F(TypeIndexIteratorTest, ManyTypes) { - - using namespace leafs; - writeTypeRecords(FuncId, MemFuncId, StringId, StringList.Record, - BuildInfo.Record, UdtSourceLine, UdtModSourceLine, Modifier, - Procedure, MemberFunction, ArgList.Record, Array, Class, - Union, Enum, BitField, VFTable, VTableShape, - MethodOverloadList.Record, Pointer, MemberPointer); - - checkTypeReferences(0, FuncId.FunctionType, FuncId.ParentScope); - checkTypeReferences(1, MemFuncId.ClassType, MemFuncId.FunctionType); - checkTypeReferences(2, StringId.Id); - checkTypeReferences(3, StringList.Ids[0], StringList.Ids[1], - StringList.Ids[2]); - checkTypeReferences(4, BuildInfo.Ids[0], BuildInfo.Ids[1], BuildInfo.Ids[2]); - checkTypeReferences(5, UdtSourceLine.UDT, UdtSourceLine.SourceFile); - checkTypeReferences(6, UdtModSourceLine.UDT, UdtModSourceLine.SourceFile); - checkTypeReferences(7, Modifier.ModifiedType); - checkTypeReferences(8, Procedure.ReturnType, Procedure.ArgumentList); - checkTypeReferences(9, MemberFunction.ReturnType, MemberFunction.ClassType, - MemberFunction.ThisType, MemberFunction.ArgumentList); - checkTypeReferences(10, ArgList.Ids[0], ArgList.Ids[1], ArgList.Ids[2]); - checkTypeReferences(11, Array.ElementType, Array.IndexType); - checkTypeReferences(12, Class.FieldList, Class.DerivationList, - Class.VTableShape); - checkTypeReferences(13, Union.FieldList); - checkTypeReferences(14, Enum.FieldList, Enum.UnderlyingType); - checkTypeReferences(15, BitField.Type); - checkTypeReferences(16, VFTable.CompleteClass, VFTable.OverriddenVFTable); - checkTypeReferences(17); - checkTypeReferences(18, MethodOverloadList.T1, MethodOverloadList.T2, - MethodOverloadList.T3, MethodOverloadList.T4); - checkTypeReferences(19, Pointer.ReferentType); - checkTypeReferences(20, MemberPointer.ReferentType, - MemberPointer.MemberInfo->ContainingType); -} - -TEST_F(TypeIndexIteratorTest, FieldListBaseClass) { - using namespace members; - writeFieldList(BaseClass); - checkTypeReferences(0, BaseClass.Type); -} - -TEST_F(TypeIndexIteratorTest, FieldListEnumerator) { - using namespace members; - writeFieldList(Enumerator); - checkTypeReferences(0); -} - -TEST_F(TypeIndexIteratorTest, FieldListMember) { - using namespace members; - writeFieldList(DataMember); - checkTypeReferences(0, DataMember.Type); -} - -TEST_F(TypeIndexIteratorTest, FieldListMethod) { - using namespace members; - writeFieldList(OverloadedMethod); - checkTypeReferences(0, OverloadedMethod.MethodList); -} - -TEST_F(TypeIndexIteratorTest, FieldListOneMethod) { - using namespace members; - writeFieldList(OneMethod.R1, OneMethod.R2, OneMethod.R3, OneMethod.R4); - checkTypeReferences(0, OneMethod.T1, OneMethod.T2, OneMethod.T3, - OneMethod.T4); -} - -TEST_F(TypeIndexIteratorTest, FieldListNestedType) { - using namespace members; - writeFieldList(NestedType); - checkTypeReferences(0, NestedType.Type); -} - -TEST_F(TypeIndexIteratorTest, FieldListStaticMember) { - using namespace members; - writeFieldList(StaticDataMember); - checkTypeReferences(0, StaticDataMember.Type); -} - -TEST_F(TypeIndexIteratorTest, FieldListVirtualBase) { - using namespace members; - writeFieldList(VirtualBaseClass); - checkTypeReferences(0, VirtualBaseClass.BaseType, VirtualBaseClass.VBPtrType); -} - -TEST_F(TypeIndexIteratorTest, FieldListVFTable) { - using namespace members; - writeFieldList(VFPtr); - checkTypeReferences(0, VFPtr.Type); -} - -TEST_F(TypeIndexIteratorTest, FieldListContinuation) { - using namespace members; - writeFieldList(Continuation); - checkTypeReferences(0, Continuation.ContinuationIndex); -} - -TEST_F(TypeIndexIteratorTest, ManyMembers) { - using namespace members; - writeFieldList(BaseClass, Enumerator, DataMember, OverloadedMethod, - OneMethod.R1, OneMethod.R2, OneMethod.R3, OneMethod.R4, - NestedType, StaticDataMember, VirtualBaseClass, VFPtr, - Continuation); - - checkTypeReferences( - 0, BaseClass.Type, DataMember.Type, OverloadedMethod.MethodList, - OneMethod.T1, OneMethod.T2, OneMethod.T3, OneMethod.T4, NestedType.Type, - StaticDataMember.Type, VirtualBaseClass.BaseType, - VirtualBaseClass.VBPtrType, VFPtr.Type, Continuation.ContinuationIndex); -} - -TEST_F(TypeIndexIteratorTest, ProcSym) { - ProcSym GS(SymbolRecordKind::GlobalProcSym); - GS.FunctionType = TypeIndex::Float32(); - ProcSym LS(SymbolRecordKind::ProcSym); - LS.FunctionType = TypeIndex::Float64(); - writeSymbolRecords(GS, LS); - checkTypeReferences(0, GS.FunctionType); - checkTypeReferences(1, LS.FunctionType); -} - -TEST_F(TypeIndexIteratorTest, DataSym) { - DataSym DS(SymbolRecordKind::GlobalData); - DS.Type = TypeIndex::Float32(); - writeSymbolRecords(DS); - checkTypeReferences(0, DS.Type); -} - -TEST_F(TypeIndexIteratorTest, RegisterSym) { - RegisterSym Reg(SymbolRecordKind::RegisterSym); - Reg.Index = TypeIndex::UInt32(); - Reg.Register = RegisterId::EAX; - Reg.Name = "Target"; - writeSymbolRecords(Reg); - checkTypeReferences(0, Reg.Index); -} - -TEST_F(TypeIndexIteratorTest, CallerSym) { - CallerSym Callees(SymbolRecordKind::CalleeSym); - Callees.Indices.push_back(TypeIndex(1)); - Callees.Indices.push_back(TypeIndex(2)); - Callees.Indices.push_back(TypeIndex(3)); - CallerSym Callers(SymbolRecordKind::CallerSym); - Callers.Indices.push_back(TypeIndex(4)); - Callers.Indices.push_back(TypeIndex(5)); - Callers.Indices.push_back(TypeIndex(6)); - CallerSym Inlinees(SymbolRecordKind::InlineesSym); - Inlinees.Indices.push_back(TypeIndex(7)); - Inlinees.Indices.push_back(TypeIndex(8)); - Inlinees.Indices.push_back(TypeIndex(9)); - writeSymbolRecords(Callees, Callers, Inlinees); - checkTypeReferences(0, TypeIndex(1), TypeIndex(2), TypeIndex(3)); - checkTypeReferences(1, TypeIndex(4), TypeIndex(5), TypeIndex(6)); - checkTypeReferences(2, TypeIndex(7), TypeIndex(8), TypeIndex(9)); -} - +//===- llvm/unittest/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp --------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h" + +#include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h" +#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h" +#include "llvm/DebugInfo/CodeView/SymbolSerializer.h" +#include "llvm/Support/Allocator.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::codeview; + +class TypeIndexIteratorTest : public testing::Test { +public: + TypeIndexIteratorTest() {} + + void SetUp() override { + Refs.clear(); + TTB = make_unique(Storage); + CRB = make_unique(); + Symbols.clear(); + } + + void TearDown() override { + CRB.reset(); + TTB.reset(); + } + +protected: + template + bool checkTypeReferences(uint32_t RecordIndex, Indices &&... TIs) const { + EXPECT_EQ(sizeof...(Indices), countRefs(RecordIndex)); + + // Choose between type or symbol records. The checking code doesn't care + // which we have. + std::vector> CVRecords; + if (Symbols.empty()) { + CVRecords = TTB->records(); + } else { + for (const CVSymbol &S : Symbols) + CVRecords.push_back(S.data()); + } + + return checkTypeReferencesImpl(RecordIndex, CVRecords, + std::forward(TIs)...); + } + + template void writeFieldList(T &&... MemberRecords) { + CRB->begin(ContinuationRecordKind::FieldList); + writeFieldListImpl(std::forward(MemberRecords)...); + auto Records = CRB->end(TTB->nextTypeIndex()); + ASSERT_EQ(1u, Records.size()); + TTB->insertRecordBytes(Records.front().RecordData); + discoverAllTypeIndices(); + } + + template void writeTypeRecords(T &&... Records) { + writeTypeRecordsImpl(std::forward(Records)...); + ASSERT_EQ(sizeof...(T), TTB->records().size()); + discoverAllTypeIndices(); + } + + template void writeSymbolRecords(T &&... Records) { + writeSymbolRecordsImpl(std::forward(Records)...); + ASSERT_EQ(sizeof...(T), Symbols.size()); + discoverTypeIndicesInSymbols(); + } + + std::unique_ptr TTB; + +private: + uint32_t countRefs(uint32_t RecordIndex) const { + auto &R = Refs[RecordIndex]; + uint32_t Count = 0; + for (auto &Ref : R) { + Count += Ref.Count; + } + return Count; + } + + bool checkOneTypeReference(uint32_t RecordIndex, ArrayRef RecordData, + TypeIndex TI) const { + RecordData = RecordData.drop_front(sizeof(RecordPrefix)); + auto &RefList = Refs[RecordIndex]; + for (auto &Ref : RefList) { + uint32_t Offset = Ref.Offset; + ArrayRef Loc = RecordData.drop_front(Offset); + ArrayRef Indices( + reinterpret_cast(Loc.data()), Ref.Count); + if (llvm::any_of(Indices, + [TI](const TypeIndex &Other) { return Other == TI; })) + return true; + } + return false; + } + + template + bool checkTypeReferencesImpl(uint32_t RecordIndex, + ArrayRef> CVRecords) const { + return true; + } + + template + bool checkTypeReferencesImpl(uint32_t RecordIndex, + ArrayRef> CVRecords, + TypeIndex TI, Indices &&... Rest) const { + ArrayRef Record = CVRecords[RecordIndex]; + bool Success = checkOneTypeReference(RecordIndex, Record, TI); + EXPECT_TRUE(Success); + return Success & checkTypeReferencesImpl(RecordIndex, CVRecords, + std::forward(Rest)...); + } + + void discoverAllTypeIndices() { + Refs.resize(TTB->records().size()); + for (uint32_t I = 0; I < TTB->records().size(); ++I) { + ArrayRef Data = TTB->records()[I]; + discoverTypeIndices(Data, Refs[I]); + } + } + + void discoverTypeIndicesInSymbols() { + Refs.resize(Symbols.size()); + for (uint32_t I = 0; I < Symbols.size(); ++I) + discoverTypeIndicesInSymbol(Symbols[I], Refs[I]); + } + + // Helper function to write out a field list record with the given list + // of member records. + void writeFieldListImpl() {} + + template + void writeFieldListImpl(RecType &&Record, Rest &&... Records) { + CRB->writeMemberType(Record); + writeFieldListImpl(std::forward(Records)...); + } + + // Helper function to write out a list of type records. + void writeTypeRecordsImpl() {} + + template + void writeTypeRecordsImpl(RecType &&Record, Rest &&... Records) { + TTB->writeLeafType(Record); + writeTypeRecordsImpl(std::forward(Records)...); + } + + // Helper function to write out a list of symbol records. + void writeSymbolRecordsImpl() {} + + template + void writeSymbolRecordsImpl(RecType &&Record, Rest &&... Records) { + Symbols.push_back(SymbolSerializer::writeOneSymbol(Record, Storage, + CodeViewContainer::Pdb)); + writeSymbolRecordsImpl(std::forward(Records)...); + } + + std::vector> Refs; + std::unique_ptr CRB; + std::vector Symbols; + BumpPtrAllocator Storage; +}; + +namespace leafs { +static FuncIdRecord FuncId(TypeIndex(1), TypeIndex(2), "FuncId"); +static MemberFuncIdRecord MemFuncId(TypeIndex(3), TypeIndex(4), "FuncId"); +static StringIdRecord StringId(TypeIndex(5), "TheString"); +static struct { + std::vector Ids = {TypeIndex(6), TypeIndex(7), TypeIndex(8)}; + StringListRecord Record{TypeRecordKind::StringList, Ids}; +} StringList; +static struct { + std::vector Ids = {TypeIndex(9), TypeIndex(10), TypeIndex(11)}; + BuildInfoRecord Record{Ids}; +} BuildInfo; +static UdtSourceLineRecord UdtSourceLine(TypeIndex(12), TypeIndex(13), 0); +static UdtModSourceLineRecord UdtModSourceLine(TypeIndex(14), TypeIndex(15), 0, + 0); +static ModifierRecord Modifier(TypeIndex(16), ModifierOptions::None); +static ProcedureRecord Procedure(TypeIndex(17), CallingConvention::PpcCall, + FunctionOptions::None, 0, TypeIndex(18)); +static MemberFunctionRecord MemberFunction(TypeIndex(19), TypeIndex(20), + TypeIndex(21), + CallingConvention::ThisCall, + FunctionOptions::None, 2, + TypeIndex(22), 0); +static struct { + std::vector Ids = {TypeIndex(23), TypeIndex(24), TypeIndex(25)}; + ArgListRecord Record{TypeRecordKind::ArgList, Ids}; +} ArgList; +static ArrayRecord Array(TypeIndex(26), TypeIndex(27), 10, "MyArray"); +static ClassRecord Class(TypeRecordKind::Class, 3, ClassOptions::None, + TypeIndex(28), TypeIndex(29), TypeIndex(30), 10, + "MyClass", "MyClassUniqueName"); +static ClassRecord Struct(TypeRecordKind::Struct, 3, ClassOptions::None, + TypeIndex(31), TypeIndex(32), TypeIndex(33), 10, + "MyClass", "MyClassUniqueName"); +static UnionRecord Union(1, ClassOptions::None, TypeIndex(34), 10, "MyUnion", + "MyUnionUniqueName"); +static EnumRecord Enum(1, ClassOptions::None, TypeIndex(35), "MyEnum", + "EnumUniqueName", TypeIndex(36)); +static BitFieldRecord BitField(TypeIndex(37), 1, 0); +static VFTableRecord VFTable(TypeIndex(38), TypeIndex(39), 1, "VFT", {}); +static VFTableShapeRecord VTableShape({}); +static struct { + const TypeIndex T1{40}; + const TypeIndex T2{41}; + const TypeIndex T3{42}; + const TypeIndex T4{43}; + + std::vector Methods{ + {T1, MemberAccess::Public, MethodKind::IntroducingVirtual, + MethodOptions::None, 0, "Method1"}, + {T2, MemberAccess::Public, MethodKind::PureVirtual, MethodOptions::None, + 0, "Method1"}, + {T3, MemberAccess::Public, MethodKind::PureIntroducingVirtual, + MethodOptions::None, 0, "Method1"}, + {T4, MemberAccess::Public, MethodKind::Static, MethodOptions::None, 0, + "Method1"}}; + + MethodOverloadListRecord Record{Methods}; +} MethodOverloadList; +static PointerRecord Pointer(TypeIndex(44), PointerKind::Near32, + PointerMode::Pointer, PointerOptions::Const, 3); +static PointerRecord MemberPointer( + TypeIndex(45), PointerKind::Near32, PointerMode::PointerToDataMember, + PointerOptions::Const, 3, + MemberPointerInfo(TypeIndex(46), + PointerToMemberRepresentation::GeneralData)); +} + +namespace members { +static BaseClassRecord BaseClass(MemberAccess::Public, TypeIndex(47), 0); +static EnumeratorRecord Enumerator(MemberAccess::Public, + APSInt(APInt(8, 3, false)), "Test"); +DataMemberRecord DataMember(MemberAccess::Public, TypeIndex(48), 0, "Test"); +OverloadedMethodRecord OverloadedMethod(3, TypeIndex(49), "MethodList"); +static struct { + const TypeIndex T1{50}; + const TypeIndex T2{51}; + const TypeIndex T3{52}; + const TypeIndex T4{53}; + OneMethodRecord R1{T1, + MemberAccess::Public, + MethodKind::IntroducingVirtual, + MethodOptions::None, + 0, + "M1"}; + OneMethodRecord R2{T2, + MemberAccess::Public, + MethodKind::PureVirtual, + MethodOptions::None, + 0, + "M2"}; + OneMethodRecord R3{T3, + MemberAccess::Public, + MethodKind::PureIntroducingVirtual, + MethodOptions::None, + 0, + "M3"}; + OneMethodRecord R4{T4, + MemberAccess::Protected, + MethodKind::Vanilla, + MethodOptions::CompilerGenerated, + 0, + "M4"}; +} OneMethod; +static NestedTypeRecord NestedType(TypeIndex(54), "MyClass"); +static StaticDataMemberRecord StaticDataMember(MemberAccess::Public, + TypeIndex(55), "Foo"); +static VirtualBaseClassRecord VirtualBaseClass(TypeRecordKind::VirtualBaseClass, + MemberAccess::Public, + TypeIndex(56), TypeIndex(57), 0, + 0); +static VFPtrRecord VFPtr(TypeIndex(58)); +static ListContinuationRecord Continuation(TypeIndex(59)); +} + +TEST_F(TypeIndexIteratorTest, FuncId) { + using namespace leafs; + writeTypeRecords(FuncId); + checkTypeReferences(0, FuncId.FunctionType, FuncId.ParentScope); +} + +TEST_F(TypeIndexIteratorTest, MemFuncId) { + using namespace leafs; + writeTypeRecords(MemFuncId); + checkTypeReferences(0, MemFuncId.ClassType, MemFuncId.FunctionType); +} + +TEST_F(TypeIndexIteratorTest, StringId) { + using namespace leafs; + writeTypeRecords(StringId); + checkTypeReferences(0, StringId.Id); +} + +TEST_F(TypeIndexIteratorTest, SubstrList) { + using namespace leafs; + writeTypeRecords(StringList.Record); + checkTypeReferences(0, StringList.Ids[0], StringList.Ids[1], + StringList.Ids[2]); +} + +TEST_F(TypeIndexIteratorTest, BuildInfo) { + using namespace leafs; + writeTypeRecords(BuildInfo.Record); + checkTypeReferences(0, BuildInfo.Ids[0], BuildInfo.Ids[1], BuildInfo.Ids[2]); +} + +TEST_F(TypeIndexIteratorTest, UdtSrcLine) { + using namespace leafs; + writeTypeRecords(UdtSourceLine); + checkTypeReferences(0, UdtSourceLine.UDT, UdtSourceLine.SourceFile); +} + +TEST_F(TypeIndexIteratorTest, UdtModSrcLine) { + using namespace leafs; + writeTypeRecords(UdtModSourceLine); + checkTypeReferences(0, UdtModSourceLine.UDT, UdtModSourceLine.SourceFile); +} + +TEST_F(TypeIndexIteratorTest, Modifier) { + using namespace leafs; + writeTypeRecords(Modifier); + checkTypeReferences(0, Modifier.ModifiedType); +} + +TEST_F(TypeIndexIteratorTest, Procedure) { + using namespace leafs; + writeTypeRecords(Procedure); + checkTypeReferences(0, Procedure.ReturnType, Procedure.ArgumentList); +} + +TEST_F(TypeIndexIteratorTest, MemFunc) { + using namespace leafs; + writeTypeRecords(MemberFunction); + checkTypeReferences(0, MemberFunction.ReturnType, MemberFunction.ClassType, + MemberFunction.ThisType, MemberFunction.ArgumentList); +} + +TEST_F(TypeIndexIteratorTest, ArgList) { + using namespace leafs; + writeTypeRecords(ArgList.Record); + checkTypeReferences(0, ArgList.Ids[0], ArgList.Ids[1], ArgList.Ids[2]); +} + +TEST_F(TypeIndexIteratorTest, Array) { + using namespace leafs; + writeTypeRecords(Array); + checkTypeReferences(0, Array.ElementType, Array.IndexType); +} + +TEST_F(TypeIndexIteratorTest, Class) { + using namespace leafs; + writeTypeRecords(Class); + checkTypeReferences(0, Class.FieldList, Class.DerivationList, + Class.VTableShape); +} + +TEST_F(TypeIndexIteratorTest, Struct) { + using namespace leafs; + writeTypeRecords(Struct); + checkTypeReferences(0, Struct.FieldList, Struct.DerivationList, + Struct.VTableShape); +} + +TEST_F(TypeIndexIteratorTest, Union) { + using namespace leafs; + writeTypeRecords(Union); + checkTypeReferences(0, Union.FieldList); +} + +TEST_F(TypeIndexIteratorTest, Enum) { + using namespace leafs; + writeTypeRecords(Enum); + checkTypeReferences(0, Enum.FieldList, Enum.UnderlyingType); +} + +TEST_F(TypeIndexIteratorTest, Bitfield) { + using namespace leafs; + writeTypeRecords(BitField); + checkTypeReferences(0, BitField.Type); +} + +TEST_F(TypeIndexIteratorTest, VTable) { + using namespace leafs; + writeTypeRecords(VFTable); + checkTypeReferences(0, VFTable.CompleteClass, VFTable.OverriddenVFTable); +} + +TEST_F(TypeIndexIteratorTest, VTShape) { + using namespace leafs; + writeTypeRecords(VTableShape); + checkTypeReferences(0); +} + +TEST_F(TypeIndexIteratorTest, OverloadList) { + using namespace leafs; + writeTypeRecords(MethodOverloadList.Record); + checkTypeReferences(0, MethodOverloadList.T1, MethodOverloadList.T2, + MethodOverloadList.T3, MethodOverloadList.T4); +} + +TEST_F(TypeIndexIteratorTest, Pointer) { + using namespace leafs; + writeTypeRecords(Pointer); + checkTypeReferences(0, Pointer.ReferentType); +} + +TEST_F(TypeIndexIteratorTest, MemberPointer) { + using namespace leafs; + writeTypeRecords(MemberPointer); + checkTypeReferences(0, MemberPointer.ReferentType, + MemberPointer.MemberInfo->ContainingType); +} + +TEST_F(TypeIndexIteratorTest, ManyTypes) { + + using namespace leafs; + writeTypeRecords(FuncId, MemFuncId, StringId, StringList.Record, + BuildInfo.Record, UdtSourceLine, UdtModSourceLine, Modifier, + Procedure, MemberFunction, ArgList.Record, Array, Class, + Union, Enum, BitField, VFTable, VTableShape, + MethodOverloadList.Record, Pointer, MemberPointer); + + checkTypeReferences(0, FuncId.FunctionType, FuncId.ParentScope); + checkTypeReferences(1, MemFuncId.ClassType, MemFuncId.FunctionType); + checkTypeReferences(2, StringId.Id); + checkTypeReferences(3, StringList.Ids[0], StringList.Ids[1], + StringList.Ids[2]); + checkTypeReferences(4, BuildInfo.Ids[0], BuildInfo.Ids[1], BuildInfo.Ids[2]); + checkTypeReferences(5, UdtSourceLine.UDT, UdtSourceLine.SourceFile); + checkTypeReferences(6, UdtModSourceLine.UDT, UdtModSourceLine.SourceFile); + checkTypeReferences(7, Modifier.ModifiedType); + checkTypeReferences(8, Procedure.ReturnType, Procedure.ArgumentList); + checkTypeReferences(9, MemberFunction.ReturnType, MemberFunction.ClassType, + MemberFunction.ThisType, MemberFunction.ArgumentList); + checkTypeReferences(10, ArgList.Ids[0], ArgList.Ids[1], ArgList.Ids[2]); + checkTypeReferences(11, Array.ElementType, Array.IndexType); + checkTypeReferences(12, Class.FieldList, Class.DerivationList, + Class.VTableShape); + checkTypeReferences(13, Union.FieldList); + checkTypeReferences(14, Enum.FieldList, Enum.UnderlyingType); + checkTypeReferences(15, BitField.Type); + checkTypeReferences(16, VFTable.CompleteClass, VFTable.OverriddenVFTable); + checkTypeReferences(17); + checkTypeReferences(18, MethodOverloadList.T1, MethodOverloadList.T2, + MethodOverloadList.T3, MethodOverloadList.T4); + checkTypeReferences(19, Pointer.ReferentType); + checkTypeReferences(20, MemberPointer.ReferentType, + MemberPointer.MemberInfo->ContainingType); +} + +TEST_F(TypeIndexIteratorTest, FieldListBaseClass) { + using namespace members; + writeFieldList(BaseClass); + checkTypeReferences(0, BaseClass.Type); +} + +TEST_F(TypeIndexIteratorTest, FieldListEnumerator) { + using namespace members; + writeFieldList(Enumerator); + checkTypeReferences(0); +} + +TEST_F(TypeIndexIteratorTest, FieldListMember) { + using namespace members; + writeFieldList(DataMember); + checkTypeReferences(0, DataMember.Type); +} + +TEST_F(TypeIndexIteratorTest, FieldListMethod) { + using namespace members; + writeFieldList(OverloadedMethod); + checkTypeReferences(0, OverloadedMethod.MethodList); +} + +TEST_F(TypeIndexIteratorTest, FieldListOneMethod) { + using namespace members; + writeFieldList(OneMethod.R1, OneMethod.R2, OneMethod.R3, OneMethod.R4); + checkTypeReferences(0, OneMethod.T1, OneMethod.T2, OneMethod.T3, + OneMethod.T4); +} + +TEST_F(TypeIndexIteratorTest, FieldListNestedType) { + using namespace members; + writeFieldList(NestedType); + checkTypeReferences(0, NestedType.Type); +} + +TEST_F(TypeIndexIteratorTest, FieldListStaticMember) { + using namespace members; + writeFieldList(StaticDataMember); + checkTypeReferences(0, StaticDataMember.Type); +} + +TEST_F(TypeIndexIteratorTest, FieldListVirtualBase) { + using namespace members; + writeFieldList(VirtualBaseClass); + checkTypeReferences(0, VirtualBaseClass.BaseType, VirtualBaseClass.VBPtrType); +} + +TEST_F(TypeIndexIteratorTest, FieldListVFTable) { + using namespace members; + writeFieldList(VFPtr); + checkTypeReferences(0, VFPtr.Type); +} + +TEST_F(TypeIndexIteratorTest, FieldListContinuation) { + using namespace members; + writeFieldList(Continuation); + checkTypeReferences(0, Continuation.ContinuationIndex); +} + +TEST_F(TypeIndexIteratorTest, ManyMembers) { + using namespace members; + writeFieldList(BaseClass, Enumerator, DataMember, OverloadedMethod, + OneMethod.R1, OneMethod.R2, OneMethod.R3, OneMethod.R4, + NestedType, StaticDataMember, VirtualBaseClass, VFPtr, + Continuation); + + checkTypeReferences( + 0, BaseClass.Type, DataMember.Type, OverloadedMethod.MethodList, + OneMethod.T1, OneMethod.T2, OneMethod.T3, OneMethod.T4, NestedType.Type, + StaticDataMember.Type, VirtualBaseClass.BaseType, + VirtualBaseClass.VBPtrType, VFPtr.Type, Continuation.ContinuationIndex); +} + +TEST_F(TypeIndexIteratorTest, ProcSym) { + ProcSym GS(SymbolRecordKind::GlobalProcSym); + GS.FunctionType = TypeIndex::Float32(); + ProcSym LS(SymbolRecordKind::ProcSym); + LS.FunctionType = TypeIndex::Float64(); + writeSymbolRecords(GS, LS); + checkTypeReferences(0, GS.FunctionType); + checkTypeReferences(1, LS.FunctionType); +} + +TEST_F(TypeIndexIteratorTest, DataSym) { + DataSym DS(SymbolRecordKind::GlobalData); + DS.Type = TypeIndex::Float32(); + writeSymbolRecords(DS); + checkTypeReferences(0, DS.Type); +} + +TEST_F(TypeIndexIteratorTest, RegisterSym) { + RegisterSym Reg(SymbolRecordKind::RegisterSym); + Reg.Index = TypeIndex::UInt32(); + Reg.Register = RegisterId::EAX; + Reg.Name = "Target"; + writeSymbolRecords(Reg); + checkTypeReferences(0, Reg.Index); +} + +TEST_F(TypeIndexIteratorTest, CallerSym) { + CallerSym Callees(SymbolRecordKind::CalleeSym); + Callees.Indices.push_back(TypeIndex(1)); + Callees.Indices.push_back(TypeIndex(2)); + Callees.Indices.push_back(TypeIndex(3)); + CallerSym Callers(SymbolRecordKind::CallerSym); + Callers.Indices.push_back(TypeIndex(4)); + Callers.Indices.push_back(TypeIndex(5)); + Callers.Indices.push_back(TypeIndex(6)); + CallerSym Inlinees(SymbolRecordKind::InlineesSym); + Inlinees.Indices.push_back(TypeIndex(7)); + Inlinees.Indices.push_back(TypeIndex(8)); + Inlinees.Indices.push_back(TypeIndex(9)); + writeSymbolRecords(Callees, Callers, Inlinees); + checkTypeReferences(0, TypeIndex(1), TypeIndex(2), TypeIndex(3)); + checkTypeReferences(1, TypeIndex(4), TypeIndex(5), TypeIndex(6)); + checkTypeReferences(2, TypeIndex(7), TypeIndex(8), TypeIndex(9)); +} + +TEST_F(TypeIndexIteratorTest, Precomp) { + PrecompRecord P(TypeRecordKind::Precomp); + P.StartTypeIndex = TypeIndex::FirstNonSimpleIndex; + P.TypesCount = 100; + P.Signature = 0x12345678; + P.PrecompFilePath = "C:/precomp.obj"; + + EndPrecompRecord EP(TypeRecordKind::EndPrecomp); + EP.Signature = P.Signature; + + writeTypeRecords(P, EP); + checkTypeReferences(0); +}