From d9e96741c464f35722bbbb4d11bb7fa7c6f4fb21 Mon Sep 17 00:00:00 2001 From: Alexandre Ganea Date: Mon, 9 Apr 2018 20:17:56 +0000 Subject: [PATCH] [Debuginfo][COFF] Minimal serialization support for precompiled types records This change adds support for the LF_PRECOMP and LF_ENDPRECOMP records required to read/write Microsoft precompiled types .objs. See https://en.wikipedia.org/wiki/Precompiled_header#Microsoft_Visual_C_and_C++ This also adds handling for the .debug$P section, which is actually a .debug$T section in disguise, found only in precompiled .objs. Differential Revision: https://reviews.llvm.org/D45283 llvm-svn: 329613 --- llvm/include/llvm/DebugInfo/CodeView/CodeView.h | 4 +- .../llvm/DebugInfo/CodeView/CodeViewTypes.def | 4 +- llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h | 1831 ++++++++++---------- llvm/include/llvm/ObjectYAML/COFFYAML.h | 1 + .../llvm/ObjectYAML/CodeViewYAMLTypeHashing.h | 2 +- llvm/include/llvm/ObjectYAML/CodeViewYAMLTypes.h | 6 +- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 2 +- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h | 3 +- llvm/lib/DebugInfo/CodeView/RecordName.cpp | 656 +++---- llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp | 1125 ++++++------ llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp | 979 +++++------ llvm/lib/ObjectYAML/COFFYAML.cpp | 8 +- llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp | 1621 ++++++++--------- llvm/test/DebugInfo/Inputs/precomp-a.obj | Bin 0 -> 2275 bytes llvm/test/DebugInfo/Inputs/precomp.obj | Bin 0 -> 62021 bytes llvm/test/DebugInfo/precomp.test | 57 + llvm/tools/llvm-pdbutil/InputFile.cpp | 3 +- llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp | 1097 ++++++------ llvm/tools/obj2yaml/coff2yaml.cpp | 6 +- llvm/tools/yaml2obj/yaml2coff.cpp | 5 +- .../DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp | 1177 ++++++------- 21 files changed, 4384 insertions(+), 4203 deletions(-) create mode 100644 llvm/test/DebugInfo/Inputs/precomp-a.obj create mode 100644 llvm/test/DebugInfo/Inputs/precomp.obj create mode 100644 llvm/test/DebugInfo/precomp.test diff --git a/llvm/include/llvm/DebugInfo/CodeView/CodeView.h b/llvm/include/llvm/DebugInfo/CodeView/CodeView.h index 301e4f6..4ce9f68 100644 --- a/llvm/include/llvm/DebugInfo/CodeView/CodeView.h +++ b/llvm/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" diff --git a/llvm/include/llvm/DebugInfo/CodeView/CodeViewTypes.def b/llvm/include/llvm/DebugInfo/CodeView/CodeViewTypes.def index 69ce960..e9a479d 100644 --- a/llvm/include/llvm/DebugInfo/CodeView/CodeViewTypes.def +++ b/llvm/include/llvm/DebugInfo/CodeView/CodeViewTypes.def @@ -87,6 +87,8 @@ TYPE_RECORD(LF_UDT_MOD_SRC_LINE, 0x1607, UdtModSourceLine) TYPE_RECORD(LF_METHODLIST, 0x1206, MethodOverloadList) +TYPE_RECORD(LF_PRECOMP, 0x1509, Precomp) +TYPE_RECORD(LF_ENDPRECOMP, 0x0014, EndPrecomp) // 16 bit type records. CV_TYPE(LF_MODIFIER_16t, 0x0001) @@ -106,7 +108,6 @@ CV_TYPE(LF_NOTTRAN, 0x0010) CV_TYPE(LF_DIMARRAY_16t, 0x0011) CV_TYPE(LF_VFTPATH_16t, 0x0012) CV_TYPE(LF_PRECOMP_16t, 0x0013) -CV_TYPE(LF_ENDPRECOMP, 0x0014) CV_TYPE(LF_OEM_16t, 0x0015) CV_TYPE(LF_TYPESERVER_ST, 0x0016) @@ -181,7 +182,6 @@ CV_TYPE(LF_MANAGED_ST, 0x140f) CV_TYPE(LF_ST_MAX, 0x1500) CV_TYPE(LF_TYPESERVER, 0x1501) CV_TYPE(LF_DIMARRAY, 0x1508) -CV_TYPE(LF_PRECOMP, 0x1509) CV_TYPE(LF_ALIAS, 0x150a) CV_TYPE(LF_DEFARG, 0x150b) CV_TYPE(LF_FRIENDFCN, 0x150c) diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h b/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h index 55f2822..3b37c3d 100644 --- a/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h +++ b/llvm/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 diff --git a/llvm/include/llvm/ObjectYAML/COFFYAML.h b/llvm/include/llvm/ObjectYAML/COFFYAML.h index 8794eaa..78f021f 100644 --- a/llvm/include/llvm/ObjectYAML/COFFYAML.h +++ b/llvm/include/llvm/ObjectYAML/COFFYAML.h @@ -67,6 +67,7 @@ struct Section { yaml::BinaryRef SectionData; std::vector DebugS; std::vector DebugT; + std::vector DebugP; Optional DebugH; std::vector Relocations; StringRef Name; diff --git a/llvm/include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h b/llvm/include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h index 4f0d9ef..18cec55 100644 --- a/llvm/include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h +++ b/llvm/include/llvm/ObjectYAML/CodeViewYAMLTypeHashing.h @@ -47,7 +47,7 @@ struct DebugHSection { std::vector Hashes; }; -DebugHSection fromDebugH(ArrayRef DebugT); +DebugHSection fromDebugH(ArrayRef DebugH); ArrayRef toDebugH(const DebugHSection &DebugH, BumpPtrAllocator &Alloc); diff --git a/llvm/include/llvm/ObjectYAML/CodeViewYAMLTypes.h b/llvm/include/llvm/ObjectYAML/CodeViewYAMLTypes.h index bc3b556..1b1306d 100644 --- a/llvm/include/llvm/ObjectYAML/CodeViewYAMLTypes.h +++ b/llvm/include/llvm/ObjectYAML/CodeViewYAMLTypes.h @@ -51,8 +51,10 @@ struct LeafRecord { 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 diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index fa3fd17..f8cd01a 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -524,7 +524,7 @@ void CodeViewDebug::emitTypeInformation() { 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(); diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h index 236a70ef..e58c4c6 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -239,7 +239,8 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase { } /// 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(); diff --git a/llvm/lib/DebugInfo/CodeView/RecordName.cpp b/llvm/lib/DebugInfo/CodeView/RecordName.cpp index e6fd7cd..d18d346 100644 --- a/llvm/lib/DebugInfo/CodeView/RecordName.cpp +++ b/llvm/lib/DebugInfo/CodeView/RecordName.cpp @@ -1,323 +1,333 @@ -//===- RecordName.cpp ----------------------------------------- *- C++ --*-===// -// -// 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/RecordName.h" - -#include "llvm/ADT/SmallString.h" -#include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h" -#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" -#include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h" -#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" -#include "llvm/Support/FormatVariadic.h" - -using namespace llvm; -using namespace llvm::codeview; - -namespace { -class TypeNameComputer : public TypeVisitorCallbacks { - /// The type collection. Used to calculate names of nested types. - TypeCollection &Types; - TypeIndex CurrentTypeIndex = TypeIndex::None(); - - /// Name of the current type. Only valid before visitTypeEnd. - SmallString<256> Name; - -public: - explicit TypeNameComputer(TypeCollection &Types) : Types(Types) {} - - StringRef name() const { return Name; } - - /// Paired begin/end actions for all types. Receives all record data, - /// including the fixed-length record prefix. - Error visitTypeBegin(CVType &Record) override; - Error visitTypeBegin(CVType &Record, TypeIndex Index) override; - Error visitTypeEnd(CVType &Record) override; - -#define TYPE_RECORD(EnumName, EnumVal, Name) \ - Error visitKnownRecord(CVType &CVR, Name##Record &Record) override; -#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) -#define MEMBER_RECORD(EnumName, EnumVal, Name) -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" -}; -} // namespace - -Error TypeNameComputer::visitTypeBegin(CVType &Record) { - llvm_unreachable("Must call visitTypeBegin with a TypeIndex!"); - return Error::success(); -} - -Error TypeNameComputer::visitTypeBegin(CVType &Record, TypeIndex Index) { - // Reset Name to the empty string. If the visitor sets it, we know it. - Name = ""; - CurrentTypeIndex = Index; - return Error::success(); -} - -Error TypeNameComputer::visitTypeEnd(CVType &CVR) { return Error::success(); } - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, - FieldListRecord &FieldList) { - Name = ""; - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVRecord &CVR, - StringIdRecord &String) { - Name = String.getString(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, ArgListRecord &Args) { - auto Indices = Args.getIndices(); - uint32_t Size = Indices.size(); - Name = "("; - for (uint32_t I = 0; I < Size; ++I) { - assert(Indices[I] < CurrentTypeIndex); - - Name.append(Types.getTypeName(Indices[I])); - if (I + 1 != Size) - Name.append(", "); - } - Name.push_back(')'); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, - StringListRecord &Strings) { - auto Indices = Strings.getIndices(); - uint32_t Size = Indices.size(); - Name = "\""; - for (uint32_t I = 0; I < Size; ++I) { - Name.append(Types.getTypeName(Indices[I])); - if (I + 1 != Size) - Name.append("\" \""); - } - Name.push_back('\"'); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, ClassRecord &Class) { - Name = Class.getName(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, UnionRecord &Union) { - Name = Union.getName(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, EnumRecord &Enum) { - Name = Enum.getName(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, ArrayRecord &AT) { - Name = AT.getName(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, VFTableRecord &VFT) { - Name = VFT.getName(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, MemberFuncIdRecord &Id) { - Name = Id.getName(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, ProcedureRecord &Proc) { - StringRef Ret = Types.getTypeName(Proc.getReturnType()); - StringRef Params = Types.getTypeName(Proc.getArgumentList()); - Name = formatv("{0} {1}", Ret, Params).sstr<256>(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, - MemberFunctionRecord &MF) { - StringRef Ret = Types.getTypeName(MF.getReturnType()); - StringRef Class = Types.getTypeName(MF.getClassType()); - StringRef Params = Types.getTypeName(MF.getArgumentList()); - Name = formatv("{0} {1}::{2}", Ret, Class, Params).sstr<256>(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, FuncIdRecord &Func) { - Name = Func.getName(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) { - Name = TS.getName(); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { - - if (Ptr.isPointerToMember()) { - const MemberPointerInfo &MI = Ptr.getMemberInfo(); - - StringRef Pointee = Types.getTypeName(Ptr.getReferentType()); - StringRef Class = Types.getTypeName(MI.getContainingType()); - Name = formatv("{0} {1}::*", Pointee, Class); - } else { - Name.append(Types.getTypeName(Ptr.getReferentType())); - - if (Ptr.getMode() == PointerMode::LValueReference) - Name.append("&"); - else if (Ptr.getMode() == PointerMode::RValueReference) - Name.append("&&"); - else if (Ptr.getMode() == PointerMode::Pointer) - Name.append("*"); - - // Qualifiers in pointer records apply to the pointer, not the pointee, so - // they go on the right. - if (Ptr.isConst()) - Name.append(" const"); - if (Ptr.isVolatile()) - Name.append(" volatile"); - if (Ptr.isUnaligned()) - Name.append(" __unaligned"); - if (Ptr.isRestrict()) - Name.append(" __restrict"); - } - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, ModifierRecord &Mod) { - uint16_t Mods = static_cast(Mod.getModifiers()); - - if (Mods & uint16_t(ModifierOptions::Const)) - Name.append("const "); - if (Mods & uint16_t(ModifierOptions::Volatile)) - Name.append("volatile "); - if (Mods & uint16_t(ModifierOptions::Unaligned)) - Name.append("__unaligned "); - Name.append(Types.getTypeName(Mod.getModifiedType())); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, - VFTableShapeRecord &Shape) { - Name = formatv("", Shape.getEntryCount()); - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord( - CVType &CVR, UdtModSourceLineRecord &ModSourceLine) { - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, - UdtSourceLineRecord &SourceLine) { - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, BitFieldRecord &BF) { - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, - MethodOverloadListRecord &Overloads) { - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, BuildInfoRecord &BI) { - return Error::success(); -} - -Error TypeNameComputer::visitKnownRecord(CVType &CVR, LabelRecord &R) { - 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)); - return ""; - } - return Computer.name(); -} - -static int getSymbolNameOffset(CVSymbol Sym) { - switch (Sym.kind()) { - // See ProcSym - case SymbolKind::S_GPROC32: - case SymbolKind::S_LPROC32: - case SymbolKind::S_GPROC32_ID: - case SymbolKind::S_LPROC32_ID: - case SymbolKind::S_LPROC32_DPC: - case SymbolKind::S_LPROC32_DPC_ID: - return 35; - // See Thunk32Sym - case SymbolKind::S_THUNK32: - return 21; - // See SectionSym - case SymbolKind::S_SECTION: - return 16; - // See CoffGroupSym - case SymbolKind::S_COFFGROUP: - return 14; - // See PublicSym32, FileStaticSym, RegRelativeSym, DataSym, ThreadLocalDataSym - case SymbolKind::S_PUB32: - case SymbolKind::S_FILESTATIC: - case SymbolKind::S_REGREL32: - case SymbolKind::S_GDATA32: - case SymbolKind::S_LDATA32: - case SymbolKind::S_LMANDATA: - case SymbolKind::S_GMANDATA: - case SymbolKind::S_LTHREAD32: - case SymbolKind::S_GTHREAD32: - return 10; - // See RegisterSym and LocalSym - case SymbolKind::S_REGISTER: - case SymbolKind::S_LOCAL: - return 6; - // See BlockSym - case SymbolKind::S_BLOCK32: - return 18; - // See LabelSym - case SymbolKind::S_LABEL32: - return 7; - // See ObjNameSym, ExportSym, and UDTSym - case SymbolKind::S_OBJNAME: - case SymbolKind::S_EXPORT: - case SymbolKind::S_UDT: - return 4; - // See BPRelativeSym - case SymbolKind::S_BPREL32: - return 8; - default: - return -1; - } -} - -StringRef llvm::codeview::getSymbolName(CVSymbol Sym) { - if (Sym.kind() == SymbolKind::S_CONSTANT) { - // S_CONSTANT is preceded by an APSInt, which has a variable length. So we - // have to do a full deserialization. - BinaryStreamReader Reader(Sym.content(), llvm::support::little); - // The container doesn't matter for single records. - SymbolRecordMapping Mapping(Reader, CodeViewContainer::ObjectFile); - ConstantSym Const(SymbolKind::S_CONSTANT); - cantFail(Mapping.visitSymbolBegin(Sym)); - cantFail(Mapping.visitKnownRecord(Sym, Const)); - cantFail(Mapping.visitSymbolEnd(Sym)); - return Const.Name; - } - - int Offset = getSymbolNameOffset(Sym); - if (Offset == -1) - return StringRef(); - - StringRef StringData = toStringRef(Sym.content()).drop_front(Offset); - return StringData.split('\0').first; -} +//===- RecordName.cpp ----------------------------------------- *- C++ --*-===// +// +// 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/RecordName.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h" +#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" +#include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h" +#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" +#include "llvm/Support/FormatVariadic.h" + +using namespace llvm; +using namespace llvm::codeview; + +namespace { +class TypeNameComputer : public TypeVisitorCallbacks { + /// The type collection. Used to calculate names of nested types. + TypeCollection &Types; + TypeIndex CurrentTypeIndex = TypeIndex::None(); + + /// Name of the current type. Only valid before visitTypeEnd. + SmallString<256> Name; + +public: + explicit TypeNameComputer(TypeCollection &Types) : Types(Types) {} + + StringRef name() const { return Name; } + + /// Paired begin/end actions for all types. Receives all record data, + /// including the fixed-length record prefix. + Error visitTypeBegin(CVType &Record) override; + Error visitTypeBegin(CVType &Record, TypeIndex Index) override; + Error visitTypeEnd(CVType &Record) override; + +#define TYPE_RECORD(EnumName, EnumVal, Name) \ + Error visitKnownRecord(CVType &CVR, Name##Record &Record) override; +#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) +#define MEMBER_RECORD(EnumName, EnumVal, Name) +#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" +}; +} // namespace + +Error TypeNameComputer::visitTypeBegin(CVType &Record) { + llvm_unreachable("Must call visitTypeBegin with a TypeIndex!"); + return Error::success(); +} + +Error TypeNameComputer::visitTypeBegin(CVType &Record, TypeIndex Index) { + // Reset Name to the empty string. If the visitor sets it, we know it. + Name = ""; + CurrentTypeIndex = Index; + return Error::success(); +} + +Error TypeNameComputer::visitTypeEnd(CVType &CVR) { return Error::success(); } + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, + FieldListRecord &FieldList) { + Name = ""; + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVRecord &CVR, + StringIdRecord &String) { + Name = String.getString(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, ArgListRecord &Args) { + auto Indices = Args.getIndices(); + uint32_t Size = Indices.size(); + Name = "("; + for (uint32_t I = 0; I < Size; ++I) { + assert(Indices[I] < CurrentTypeIndex); + + Name.append(Types.getTypeName(Indices[I])); + if (I + 1 != Size) + Name.append(", "); + } + Name.push_back(')'); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, + StringListRecord &Strings) { + auto Indices = Strings.getIndices(); + uint32_t Size = Indices.size(); + Name = "\""; + for (uint32_t I = 0; I < Size; ++I) { + Name.append(Types.getTypeName(Indices[I])); + if (I + 1 != Size) + Name.append("\" \""); + } + Name.push_back('\"'); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, ClassRecord &Class) { + Name = Class.getName(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, UnionRecord &Union) { + Name = Union.getName(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, EnumRecord &Enum) { + Name = Enum.getName(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, ArrayRecord &AT) { + Name = AT.getName(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, VFTableRecord &VFT) { + Name = VFT.getName(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, MemberFuncIdRecord &Id) { + Name = Id.getName(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, ProcedureRecord &Proc) { + StringRef Ret = Types.getTypeName(Proc.getReturnType()); + StringRef Params = Types.getTypeName(Proc.getArgumentList()); + Name = formatv("{0} {1}", Ret, Params).sstr<256>(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, + MemberFunctionRecord &MF) { + StringRef Ret = Types.getTypeName(MF.getReturnType()); + StringRef Class = Types.getTypeName(MF.getClassType()); + StringRef Params = Types.getTypeName(MF.getArgumentList()); + Name = formatv("{0} {1}::{2}", Ret, Class, Params).sstr<256>(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, FuncIdRecord &Func) { + Name = Func.getName(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) { + Name = TS.getName(); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { + + if (Ptr.isPointerToMember()) { + const MemberPointerInfo &MI = Ptr.getMemberInfo(); + + StringRef Pointee = Types.getTypeName(Ptr.getReferentType()); + StringRef Class = Types.getTypeName(MI.getContainingType()); + Name = formatv("{0} {1}::*", Pointee, Class); + } else { + Name.append(Types.getTypeName(Ptr.getReferentType())); + + if (Ptr.getMode() == PointerMode::LValueReference) + Name.append("&"); + else if (Ptr.getMode() == PointerMode::RValueReference) + Name.append("&&"); + else if (Ptr.getMode() == PointerMode::Pointer) + Name.append("*"); + + // Qualifiers in pointer records apply to the pointer, not the pointee, so + // they go on the right. + if (Ptr.isConst()) + Name.append(" const"); + if (Ptr.isVolatile()) + Name.append(" volatile"); + if (Ptr.isUnaligned()) + Name.append(" __unaligned"); + if (Ptr.isRestrict()) + Name.append(" __restrict"); + } + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, ModifierRecord &Mod) { + uint16_t Mods = static_cast(Mod.getModifiers()); + + if (Mods & uint16_t(ModifierOptions::Const)) + Name.append("const "); + if (Mods & uint16_t(ModifierOptions::Volatile)) + Name.append("volatile "); + if (Mods & uint16_t(ModifierOptions::Unaligned)) + Name.append("__unaligned "); + Name.append(Types.getTypeName(Mod.getModifiedType())); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, + VFTableShapeRecord &Shape) { + Name = formatv("", Shape.getEntryCount()); + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord( + CVType &CVR, UdtModSourceLineRecord &ModSourceLine) { + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, + UdtSourceLineRecord &SourceLine) { + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, BitFieldRecord &BF) { + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, + MethodOverloadListRecord &Overloads) { + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, BuildInfoRecord &BI) { + return Error::success(); +} + +Error TypeNameComputer::visitKnownRecord(CVType &CVR, LabelRecord &R) { + 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)); + return ""; + } + return Computer.name(); +} + +static int getSymbolNameOffset(CVSymbol Sym) { + switch (Sym.kind()) { + // See ProcSym + case SymbolKind::S_GPROC32: + case SymbolKind::S_LPROC32: + case SymbolKind::S_GPROC32_ID: + case SymbolKind::S_LPROC32_ID: + case SymbolKind::S_LPROC32_DPC: + case SymbolKind::S_LPROC32_DPC_ID: + return 35; + // See Thunk32Sym + case SymbolKind::S_THUNK32: + return 21; + // See SectionSym + case SymbolKind::S_SECTION: + return 16; + // See CoffGroupSym + case SymbolKind::S_COFFGROUP: + return 14; + // See PublicSym32, FileStaticSym, RegRelativeSym, DataSym, ThreadLocalDataSym + case SymbolKind::S_PUB32: + case SymbolKind::S_FILESTATIC: + case SymbolKind::S_REGREL32: + case SymbolKind::S_GDATA32: + case SymbolKind::S_LDATA32: + case SymbolKind::S_LMANDATA: + case SymbolKind::S_GMANDATA: + case SymbolKind::S_LTHREAD32: + case SymbolKind::S_GTHREAD32: + return 10; + // See RegisterSym and LocalSym + case SymbolKind::S_REGISTER: + case SymbolKind::S_LOCAL: + return 6; + // See BlockSym + case SymbolKind::S_BLOCK32: + return 18; + // See LabelSym + case SymbolKind::S_LABEL32: + return 7; + // See ObjNameSym, ExportSym, and UDTSym + case SymbolKind::S_OBJNAME: + case SymbolKind::S_EXPORT: + case SymbolKind::S_UDT: + return 4; + // See BPRelativeSym + case SymbolKind::S_BPREL32: + return 8; + default: + return -1; + } +} + +StringRef llvm::codeview::getSymbolName(CVSymbol Sym) { + if (Sym.kind() == SymbolKind::S_CONSTANT) { + // S_CONSTANT is preceded by an APSInt, which has a variable length. So we + // have to do a full deserialization. + BinaryStreamReader Reader(Sym.content(), llvm::support::little); + // The container doesn't matter for single records. + SymbolRecordMapping Mapping(Reader, CodeViewContainer::ObjectFile); + ConstantSym Const(SymbolKind::S_CONSTANT); + cantFail(Mapping.visitSymbolBegin(Sym)); + cantFail(Mapping.visitKnownRecord(Sym, Const)); + cantFail(Mapping.visitSymbolEnd(Sym)); + return Const.Name; + } + + int Offset = getSymbolNameOffset(Sym); + if (Offset == -1) + return StringRef(); + + StringRef StringData = toStringRef(Sym.content()).drop_front(Offset); + return StringData.split('\0').first; +} diff --git a/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp b/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp index 2482c9e..f6e0b5b 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp @@ -1,555 +1,570 @@ -//===-- TypeDumpVisitor.cpp - CodeView type info dumper ----------*- C++-*-===// -// -// 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/TypeDumpVisitor.h" - -#include "llvm/ADT/SmallString.h" -#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" -#include "llvm/DebugInfo/CodeView/Formatters.h" -#include "llvm/DebugInfo/CodeView/TypeCollection.h" -#include "llvm/DebugInfo/CodeView/TypeIndex.h" -#include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/Support/FormatVariadic.h" -#include "llvm/Support/ScopedPrinter.h" - -using namespace llvm; -using namespace llvm::codeview; - -static const EnumEntry LeafTypeNames[] = { -#define CV_TYPE(enum, val) {#enum, enum}, -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" -}; - -#define ENUM_ENTRY(enum_class, enum) \ - { #enum, std::underlying_type < enum_class > ::type(enum_class::enum) } - -static const EnumEntry ClassOptionNames[] = { - ENUM_ENTRY(ClassOptions, Packed), - ENUM_ENTRY(ClassOptions, HasConstructorOrDestructor), - ENUM_ENTRY(ClassOptions, HasOverloadedOperator), - ENUM_ENTRY(ClassOptions, Nested), - ENUM_ENTRY(ClassOptions, ContainsNestedClass), - ENUM_ENTRY(ClassOptions, HasOverloadedAssignmentOperator), - ENUM_ENTRY(ClassOptions, HasConversionOperator), - ENUM_ENTRY(ClassOptions, ForwardReference), - ENUM_ENTRY(ClassOptions, Scoped), - ENUM_ENTRY(ClassOptions, HasUniqueName), - ENUM_ENTRY(ClassOptions, Sealed), - ENUM_ENTRY(ClassOptions, Intrinsic), -}; - -static const EnumEntry MemberAccessNames[] = { - ENUM_ENTRY(MemberAccess, None), ENUM_ENTRY(MemberAccess, Private), - ENUM_ENTRY(MemberAccess, Protected), ENUM_ENTRY(MemberAccess, Public), -}; - -static const EnumEntry MethodOptionNames[] = { - ENUM_ENTRY(MethodOptions, Pseudo), - ENUM_ENTRY(MethodOptions, NoInherit), - ENUM_ENTRY(MethodOptions, NoConstruct), - ENUM_ENTRY(MethodOptions, CompilerGenerated), - ENUM_ENTRY(MethodOptions, Sealed), -}; - -static const EnumEntry MemberKindNames[] = { - ENUM_ENTRY(MethodKind, Vanilla), - ENUM_ENTRY(MethodKind, Virtual), - ENUM_ENTRY(MethodKind, Static), - ENUM_ENTRY(MethodKind, Friend), - ENUM_ENTRY(MethodKind, IntroducingVirtual), - ENUM_ENTRY(MethodKind, PureVirtual), - ENUM_ENTRY(MethodKind, PureIntroducingVirtual), -}; - -static const EnumEntry PtrKindNames[] = { - ENUM_ENTRY(PointerKind, Near16), - ENUM_ENTRY(PointerKind, Far16), - ENUM_ENTRY(PointerKind, Huge16), - ENUM_ENTRY(PointerKind, BasedOnSegment), - ENUM_ENTRY(PointerKind, BasedOnValue), - ENUM_ENTRY(PointerKind, BasedOnSegmentValue), - ENUM_ENTRY(PointerKind, BasedOnAddress), - ENUM_ENTRY(PointerKind, BasedOnSegmentAddress), - ENUM_ENTRY(PointerKind, BasedOnType), - ENUM_ENTRY(PointerKind, BasedOnSelf), - ENUM_ENTRY(PointerKind, Near32), - ENUM_ENTRY(PointerKind, Far32), - ENUM_ENTRY(PointerKind, Near64), -}; - -static const EnumEntry PtrModeNames[] = { - ENUM_ENTRY(PointerMode, Pointer), - ENUM_ENTRY(PointerMode, LValueReference), - ENUM_ENTRY(PointerMode, PointerToDataMember), - ENUM_ENTRY(PointerMode, PointerToMemberFunction), - ENUM_ENTRY(PointerMode, RValueReference), -}; - -static const EnumEntry PtrMemberRepNames[] = { - ENUM_ENTRY(PointerToMemberRepresentation, Unknown), - ENUM_ENTRY(PointerToMemberRepresentation, SingleInheritanceData), - ENUM_ENTRY(PointerToMemberRepresentation, MultipleInheritanceData), - ENUM_ENTRY(PointerToMemberRepresentation, VirtualInheritanceData), - ENUM_ENTRY(PointerToMemberRepresentation, GeneralData), - ENUM_ENTRY(PointerToMemberRepresentation, SingleInheritanceFunction), - ENUM_ENTRY(PointerToMemberRepresentation, MultipleInheritanceFunction), - ENUM_ENTRY(PointerToMemberRepresentation, VirtualInheritanceFunction), - ENUM_ENTRY(PointerToMemberRepresentation, GeneralFunction), -}; - -static const EnumEntry TypeModifierNames[] = { - ENUM_ENTRY(ModifierOptions, Const), ENUM_ENTRY(ModifierOptions, Volatile), - ENUM_ENTRY(ModifierOptions, Unaligned), -}; - -static const EnumEntry CallingConventions[] = { - ENUM_ENTRY(CallingConvention, NearC), - ENUM_ENTRY(CallingConvention, FarC), - ENUM_ENTRY(CallingConvention, NearPascal), - ENUM_ENTRY(CallingConvention, FarPascal), - ENUM_ENTRY(CallingConvention, NearFast), - ENUM_ENTRY(CallingConvention, FarFast), - ENUM_ENTRY(CallingConvention, NearStdCall), - ENUM_ENTRY(CallingConvention, FarStdCall), - ENUM_ENTRY(CallingConvention, NearSysCall), - ENUM_ENTRY(CallingConvention, FarSysCall), - ENUM_ENTRY(CallingConvention, ThisCall), - ENUM_ENTRY(CallingConvention, MipsCall), - ENUM_ENTRY(CallingConvention, Generic), - ENUM_ENTRY(CallingConvention, AlphaCall), - ENUM_ENTRY(CallingConvention, PpcCall), - ENUM_ENTRY(CallingConvention, SHCall), - ENUM_ENTRY(CallingConvention, ArmCall), - ENUM_ENTRY(CallingConvention, AM33Call), - ENUM_ENTRY(CallingConvention, TriCall), - ENUM_ENTRY(CallingConvention, SH5Call), - ENUM_ENTRY(CallingConvention, M32RCall), - ENUM_ENTRY(CallingConvention, ClrCall), - ENUM_ENTRY(CallingConvention, Inline), - ENUM_ENTRY(CallingConvention, NearVector), -}; - -static const EnumEntry FunctionOptionEnum[] = { - ENUM_ENTRY(FunctionOptions, CxxReturnUdt), - ENUM_ENTRY(FunctionOptions, Constructor), - ENUM_ENTRY(FunctionOptions, ConstructorWithVirtualBases), -}; - -static const EnumEntry LabelTypeEnum[] = { - ENUM_ENTRY(LabelType, Near), ENUM_ENTRY(LabelType, Far), -}; - -#undef ENUM_ENTRY - -static StringRef getLeafTypeName(TypeLeafKind LT) { - switch (LT) { -#define TYPE_RECORD(ename, value, name) \ - case ename: \ - return #name; -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" - default: - break; - } - return "UnknownLeaf"; -} - -void TypeDumpVisitor::printTypeIndex(StringRef FieldName, TypeIndex TI) const { - codeview::printTypeIndex(*W, FieldName, TI, TpiTypes); -} - -void TypeDumpVisitor::printItemIndex(StringRef FieldName, TypeIndex TI) const { - codeview::printTypeIndex(*W, FieldName, TI, getSourceTypes()); -} - -Error TypeDumpVisitor::visitTypeBegin(CVType &Record) { - return visitTypeBegin(Record, TypeIndex::fromArrayIndex(TpiTypes.size())); -} - -Error TypeDumpVisitor::visitTypeBegin(CVType &Record, TypeIndex Index) { - W->startLine() << getLeafTypeName(Record.Type); - W->getOStream() << " (" << HexNumber(Index.getIndex()) << ")"; - W->getOStream() << " {\n"; - W->indent(); - W->printEnum("TypeLeafKind", unsigned(Record.Type), - makeArrayRef(LeafTypeNames)); - return Error::success(); -} - -Error TypeDumpVisitor::visitTypeEnd(CVType &Record) { - if (PrintRecordBytes) - W->printBinaryBlock("LeafData", getBytesAsCharacters(Record.content())); - - W->unindent(); - W->startLine() << "}\n"; - return Error::success(); -} - -Error TypeDumpVisitor::visitMemberBegin(CVMemberRecord &Record) { - W->startLine() << getLeafTypeName(Record.Kind); - W->getOStream() << " {\n"; - W->indent(); - W->printEnum("TypeLeafKind", unsigned(Record.Kind), - makeArrayRef(LeafTypeNames)); - return Error::success(); -} - -Error TypeDumpVisitor::visitMemberEnd(CVMemberRecord &Record) { - if (PrintRecordBytes) - W->printBinaryBlock("LeafData", getBytesAsCharacters(Record.Data)); - - W->unindent(); - W->startLine() << "}\n"; - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, - FieldListRecord &FieldList) { - if (auto EC = codeview::visitMemberRecordStream(FieldList.Data, *this)) - return EC; - - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, StringIdRecord &String) { - printItemIndex("Id", String.getId()); - W->printString("StringData", String.getString()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ArgListRecord &Args) { - auto Indices = Args.getIndices(); - uint32_t Size = Indices.size(); - W->printNumber("NumArgs", Size); - ListScope Arguments(*W, "Arguments"); - for (uint32_t I = 0; I < Size; ++I) { - printTypeIndex("ArgType", Indices[I]); - } - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, StringListRecord &Strs) { - auto Indices = Strs.getIndices(); - uint32_t Size = Indices.size(); - W->printNumber("NumStrings", Size); - ListScope Arguments(*W, "Strings"); - for (uint32_t I = 0; I < Size; ++I) { - printItemIndex("String", Indices[I]); - } - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ClassRecord &Class) { - uint16_t Props = static_cast(Class.getOptions()); - W->printNumber("MemberCount", Class.getMemberCount()); - W->printFlags("Properties", Props, makeArrayRef(ClassOptionNames)); - printTypeIndex("FieldList", Class.getFieldList()); - printTypeIndex("DerivedFrom", Class.getDerivationList()); - printTypeIndex("VShape", Class.getVTableShape()); - W->printNumber("SizeOf", Class.getSize()); - W->printString("Name", Class.getName()); - if (Props & uint16_t(ClassOptions::HasUniqueName)) - W->printString("LinkageName", Class.getUniqueName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, UnionRecord &Union) { - uint16_t Props = static_cast(Union.getOptions()); - W->printNumber("MemberCount", Union.getMemberCount()); - W->printFlags("Properties", Props, makeArrayRef(ClassOptionNames)); - printTypeIndex("FieldList", Union.getFieldList()); - W->printNumber("SizeOf", Union.getSize()); - W->printString("Name", Union.getName()); - if (Props & uint16_t(ClassOptions::HasUniqueName)) - W->printString("LinkageName", Union.getUniqueName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, EnumRecord &Enum) { - uint16_t Props = static_cast(Enum.getOptions()); - W->printNumber("NumEnumerators", Enum.getMemberCount()); - W->printFlags("Properties", uint16_t(Enum.getOptions()), - makeArrayRef(ClassOptionNames)); - printTypeIndex("UnderlyingType", Enum.getUnderlyingType()); - printTypeIndex("FieldListType", Enum.getFieldList()); - W->printString("Name", Enum.getName()); - if (Props & uint16_t(ClassOptions::HasUniqueName)) - W->printString("LinkageName", Enum.getUniqueName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ArrayRecord &AT) { - printTypeIndex("ElementType", AT.getElementType()); - printTypeIndex("IndexType", AT.getIndexType()); - W->printNumber("SizeOf", AT.getSize()); - W->printString("Name", AT.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, VFTableRecord &VFT) { - printTypeIndex("CompleteClass", VFT.getCompleteClass()); - printTypeIndex("OverriddenVFTable", VFT.getOverriddenVTable()); - W->printHex("VFPtrOffset", VFT.getVFPtrOffset()); - W->printString("VFTableName", VFT.getName()); - for (auto N : VFT.getMethodNames()) - W->printString("MethodName", N); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFuncIdRecord &Id) { - printTypeIndex("ClassType", Id.getClassType()); - printTypeIndex("FunctionType", Id.getFunctionType()); - W->printString("Name", Id.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ProcedureRecord &Proc) { - printTypeIndex("ReturnType", Proc.getReturnType()); - W->printEnum("CallingConvention", uint8_t(Proc.getCallConv()), - makeArrayRef(CallingConventions)); - W->printFlags("FunctionOptions", uint8_t(Proc.getOptions()), - makeArrayRef(FunctionOptionEnum)); - W->printNumber("NumParameters", Proc.getParameterCount()); - printTypeIndex("ArgListType", Proc.getArgumentList()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFunctionRecord &MF) { - printTypeIndex("ReturnType", MF.getReturnType()); - printTypeIndex("ClassType", MF.getClassType()); - printTypeIndex("ThisType", MF.getThisType()); - W->printEnum("CallingConvention", uint8_t(MF.getCallConv()), - makeArrayRef(CallingConventions)); - W->printFlags("FunctionOptions", uint8_t(MF.getOptions()), - makeArrayRef(FunctionOptionEnum)); - W->printNumber("NumParameters", MF.getParameterCount()); - printTypeIndex("ArgListType", MF.getArgumentList()); - W->printNumber("ThisAdjustment", MF.getThisPointerAdjustment()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, - MethodOverloadListRecord &MethodList) { - for (auto &M : MethodList.getMethods()) { - ListScope S(*W, "Method"); - printMemberAttributes(M.getAccess(), M.getMethodKind(), M.getOptions()); - printTypeIndex("Type", M.getType()); - if (M.isIntroducingVirtual()) - W->printHex("VFTableOffset", M.getVFTableOffset()); - } - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, FuncIdRecord &Func) { - printItemIndex("ParentScope", Func.getParentScope()); - printTypeIndex("FunctionType", Func.getFunctionType()); - W->printString("Name", Func.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) { - W->printString("Guid", formatv("{0}", TS.getGuid()).str()); - W->printNumber("Age", TS.getAge()); - W->printString("Name", TS.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { - printTypeIndex("PointeeType", Ptr.getReferentType()); - W->printHex("PointerAttributes", uint32_t(Ptr.getOptions())); - W->printEnum("PtrType", unsigned(Ptr.getPointerKind()), - makeArrayRef(PtrKindNames)); - W->printEnum("PtrMode", unsigned(Ptr.getMode()), makeArrayRef(PtrModeNames)); - - W->printNumber("IsFlat", Ptr.isFlat()); - W->printNumber("IsConst", Ptr.isConst()); - W->printNumber("IsVolatile", Ptr.isVolatile()); - W->printNumber("IsUnaligned", Ptr.isUnaligned()); - W->printNumber("IsRestrict", Ptr.isRestrict()); - W->printNumber("SizeOf", Ptr.getSize()); - - if (Ptr.isPointerToMember()) { - const MemberPointerInfo &MI = Ptr.getMemberInfo(); - - printTypeIndex("ClassType", MI.getContainingType()); - W->printEnum("Representation", uint16_t(MI.getRepresentation()), - makeArrayRef(PtrMemberRepNames)); - } - - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ModifierRecord &Mod) { - uint16_t Mods = static_cast(Mod.getModifiers()); - printTypeIndex("ModifiedType", Mod.getModifiedType()); - W->printFlags("Modifiers", Mods, makeArrayRef(TypeModifierNames)); - - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, BitFieldRecord &BitField) { - printTypeIndex("Type", BitField.getType()); - W->printNumber("BitSize", BitField.getBitSize()); - W->printNumber("BitOffset", BitField.getBitOffset()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, - VFTableShapeRecord &Shape) { - W->printNumber("VFEntryCount", Shape.getEntryCount()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, - UdtSourceLineRecord &Line) { - printTypeIndex("UDT", Line.getUDT()); - printItemIndex("SourceFile", Line.getSourceFile()); - W->printNumber("LineNumber", Line.getLineNumber()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, - UdtModSourceLineRecord &Line) { - printTypeIndex("UDT", Line.getUDT()); - printItemIndex("SourceFile", Line.getSourceFile()); - W->printNumber("LineNumber", Line.getLineNumber()); - W->printNumber("Module", Line.getModule()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, BuildInfoRecord &Args) { - W->printNumber("NumArgs", static_cast(Args.getArgs().size())); - - ListScope Arguments(*W, "Arguments"); - for (auto Arg : Args.getArgs()) { - printItemIndex("ArgType", Arg); - } - return Error::success(); -} - -void TypeDumpVisitor::printMemberAttributes(MemberAttributes Attrs) { - return printMemberAttributes(Attrs.getAccess(), Attrs.getMethodKind(), - Attrs.getFlags()); -} - -void TypeDumpVisitor::printMemberAttributes(MemberAccess Access, - MethodKind Kind, - MethodOptions Options) { - W->printEnum("AccessSpecifier", uint8_t(Access), - makeArrayRef(MemberAccessNames)); - // Data members will be vanilla. Don't try to print a method kind for them. - if (Kind != MethodKind::Vanilla) - W->printEnum("MethodKind", unsigned(Kind), makeArrayRef(MemberKindNames)); - if (Options != MethodOptions::None) { - W->printFlags("MethodOptions", unsigned(Options), - makeArrayRef(MethodOptionNames)); - } -} - -Error TypeDumpVisitor::visitUnknownMember(CVMemberRecord &Record) { - W->printHex("UnknownMember", unsigned(Record.Kind)); - return Error::success(); -} - -Error TypeDumpVisitor::visitUnknownType(CVType &Record) { - W->printEnum("Kind", uint16_t(Record.kind()), makeArrayRef(LeafTypeNames)); - W->printNumber("Length", uint32_t(Record.content().size())); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - NestedTypeRecord &Nested) { - printTypeIndex("Type", Nested.getNestedType()); - W->printString("Name", Nested.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - OneMethodRecord &Method) { - MethodKind K = Method.getMethodKind(); - printMemberAttributes(Method.getAccess(), K, Method.getOptions()); - printTypeIndex("Type", Method.getType()); - // If virtual, then read the vftable offset. - if (Method.isIntroducingVirtual()) - W->printHex("VFTableOffset", Method.getVFTableOffset()); - W->printString("Name", Method.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - OverloadedMethodRecord &Method) { - W->printHex("MethodCount", Method.getNumOverloads()); - printTypeIndex("MethodListIndex", Method.getMethodList()); - W->printString("Name", Method.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - DataMemberRecord &Field) { - printMemberAttributes(Field.getAccess(), MethodKind::Vanilla, - MethodOptions::None); - printTypeIndex("Type", Field.getType()); - W->printHex("FieldOffset", Field.getFieldOffset()); - W->printString("Name", Field.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - StaticDataMemberRecord &Field) { - printMemberAttributes(Field.getAccess(), MethodKind::Vanilla, - MethodOptions::None); - printTypeIndex("Type", Field.getType()); - W->printString("Name", Field.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - VFPtrRecord &VFTable) { - printTypeIndex("Type", VFTable.getType()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - EnumeratorRecord &Enum) { - printMemberAttributes(Enum.getAccess(), MethodKind::Vanilla, - MethodOptions::None); - W->printNumber("EnumValue", Enum.getValue()); - W->printString("Name", Enum.getName()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - BaseClassRecord &Base) { - printMemberAttributes(Base.getAccess(), MethodKind::Vanilla, - MethodOptions::None); - printTypeIndex("BaseType", Base.getBaseType()); - W->printHex("BaseOffset", Base.getBaseOffset()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - VirtualBaseClassRecord &Base) { - printMemberAttributes(Base.getAccess(), MethodKind::Vanilla, - MethodOptions::None); - printTypeIndex("BaseType", Base.getBaseType()); - printTypeIndex("VBPtrType", Base.getVBPtrType()); - W->printHex("VBPtrOffset", Base.getVBPtrOffset()); - W->printHex("VBTableIndex", Base.getVTableIndex()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - ListContinuationRecord &Cont) { - printTypeIndex("ContinuationIndex", Cont.getContinuationIndex()); - return Error::success(); -} - -Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, LabelRecord &LR) { - W->printEnum("Mode", uint16_t(LR.Mode), makeArrayRef(LabelTypeEnum)); - return Error::success(); -} +//===-- TypeDumpVisitor.cpp - CodeView type info dumper ----------*- C++-*-===// +// +// 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/TypeDumpVisitor.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" +#include "llvm/DebugInfo/CodeView/Formatters.h" +#include "llvm/DebugInfo/CodeView/TypeCollection.h" +#include "llvm/DebugInfo/CodeView/TypeIndex.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/ScopedPrinter.h" + +using namespace llvm; +using namespace llvm::codeview; + +static const EnumEntry LeafTypeNames[] = { +#define CV_TYPE(enum, val) {#enum, enum}, +#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" +}; + +#define ENUM_ENTRY(enum_class, enum) \ + { #enum, std::underlying_type < enum_class > ::type(enum_class::enum) } + +static const EnumEntry ClassOptionNames[] = { + ENUM_ENTRY(ClassOptions, Packed), + ENUM_ENTRY(ClassOptions, HasConstructorOrDestructor), + ENUM_ENTRY(ClassOptions, HasOverloadedOperator), + ENUM_ENTRY(ClassOptions, Nested), + ENUM_ENTRY(ClassOptions, ContainsNestedClass), + ENUM_ENTRY(ClassOptions, HasOverloadedAssignmentOperator), + ENUM_ENTRY(ClassOptions, HasConversionOperator), + ENUM_ENTRY(ClassOptions, ForwardReference), + ENUM_ENTRY(ClassOptions, Scoped), + ENUM_ENTRY(ClassOptions, HasUniqueName), + ENUM_ENTRY(ClassOptions, Sealed), + ENUM_ENTRY(ClassOptions, Intrinsic), +}; + +static const EnumEntry MemberAccessNames[] = { + ENUM_ENTRY(MemberAccess, None), ENUM_ENTRY(MemberAccess, Private), + ENUM_ENTRY(MemberAccess, Protected), ENUM_ENTRY(MemberAccess, Public), +}; + +static const EnumEntry MethodOptionNames[] = { + ENUM_ENTRY(MethodOptions, Pseudo), + ENUM_ENTRY(MethodOptions, NoInherit), + ENUM_ENTRY(MethodOptions, NoConstruct), + ENUM_ENTRY(MethodOptions, CompilerGenerated), + ENUM_ENTRY(MethodOptions, Sealed), +}; + +static const EnumEntry MemberKindNames[] = { + ENUM_ENTRY(MethodKind, Vanilla), + ENUM_ENTRY(MethodKind, Virtual), + ENUM_ENTRY(MethodKind, Static), + ENUM_ENTRY(MethodKind, Friend), + ENUM_ENTRY(MethodKind, IntroducingVirtual), + ENUM_ENTRY(MethodKind, PureVirtual), + ENUM_ENTRY(MethodKind, PureIntroducingVirtual), +}; + +static const EnumEntry PtrKindNames[] = { + ENUM_ENTRY(PointerKind, Near16), + ENUM_ENTRY(PointerKind, Far16), + ENUM_ENTRY(PointerKind, Huge16), + ENUM_ENTRY(PointerKind, BasedOnSegment), + ENUM_ENTRY(PointerKind, BasedOnValue), + ENUM_ENTRY(PointerKind, BasedOnSegmentValue), + ENUM_ENTRY(PointerKind, BasedOnAddress), + ENUM_ENTRY(PointerKind, BasedOnSegmentAddress), + ENUM_ENTRY(PointerKind, BasedOnType), + ENUM_ENTRY(PointerKind, BasedOnSelf), + ENUM_ENTRY(PointerKind, Near32), + ENUM_ENTRY(PointerKind, Far32), + ENUM_ENTRY(PointerKind, Near64), +}; + +static const EnumEntry PtrModeNames[] = { + ENUM_ENTRY(PointerMode, Pointer), + ENUM_ENTRY(PointerMode, LValueReference), + ENUM_ENTRY(PointerMode, PointerToDataMember), + ENUM_ENTRY(PointerMode, PointerToMemberFunction), + ENUM_ENTRY(PointerMode, RValueReference), +}; + +static const EnumEntry PtrMemberRepNames[] = { + ENUM_ENTRY(PointerToMemberRepresentation, Unknown), + ENUM_ENTRY(PointerToMemberRepresentation, SingleInheritanceData), + ENUM_ENTRY(PointerToMemberRepresentation, MultipleInheritanceData), + ENUM_ENTRY(PointerToMemberRepresentation, VirtualInheritanceData), + ENUM_ENTRY(PointerToMemberRepresentation, GeneralData), + ENUM_ENTRY(PointerToMemberRepresentation, SingleInheritanceFunction), + ENUM_ENTRY(PointerToMemberRepresentation, MultipleInheritanceFunction), + ENUM_ENTRY(PointerToMemberRepresentation, VirtualInheritanceFunction), + ENUM_ENTRY(PointerToMemberRepresentation, GeneralFunction), +}; + +static const EnumEntry TypeModifierNames[] = { + ENUM_ENTRY(ModifierOptions, Const), ENUM_ENTRY(ModifierOptions, Volatile), + ENUM_ENTRY(ModifierOptions, Unaligned), +}; + +static const EnumEntry CallingConventions[] = { + ENUM_ENTRY(CallingConvention, NearC), + ENUM_ENTRY(CallingConvention, FarC), + ENUM_ENTRY(CallingConvention, NearPascal), + ENUM_ENTRY(CallingConvention, FarPascal), + ENUM_ENTRY(CallingConvention, NearFast), + ENUM_ENTRY(CallingConvention, FarFast), + ENUM_ENTRY(CallingConvention, NearStdCall), + ENUM_ENTRY(CallingConvention, FarStdCall), + ENUM_ENTRY(CallingConvention, NearSysCall), + ENUM_ENTRY(CallingConvention, FarSysCall), + ENUM_ENTRY(CallingConvention, ThisCall), + ENUM_ENTRY(CallingConvention, MipsCall), + ENUM_ENTRY(CallingConvention, Generic), + ENUM_ENTRY(CallingConvention, AlphaCall), + ENUM_ENTRY(CallingConvention, PpcCall), + ENUM_ENTRY(CallingConvention, SHCall), + ENUM_ENTRY(CallingConvention, ArmCall), + ENUM_ENTRY(CallingConvention, AM33Call), + ENUM_ENTRY(CallingConvention, TriCall), + ENUM_ENTRY(CallingConvention, SH5Call), + ENUM_ENTRY(CallingConvention, M32RCall), + ENUM_ENTRY(CallingConvention, ClrCall), + ENUM_ENTRY(CallingConvention, Inline), + ENUM_ENTRY(CallingConvention, NearVector), +}; + +static const EnumEntry FunctionOptionEnum[] = { + ENUM_ENTRY(FunctionOptions, CxxReturnUdt), + ENUM_ENTRY(FunctionOptions, Constructor), + ENUM_ENTRY(FunctionOptions, ConstructorWithVirtualBases), +}; + +static const EnumEntry LabelTypeEnum[] = { + ENUM_ENTRY(LabelType, Near), ENUM_ENTRY(LabelType, Far), +}; + +#undef ENUM_ENTRY + +static StringRef getLeafTypeName(TypeLeafKind LT) { + switch (LT) { +#define TYPE_RECORD(ename, value, name) \ + case ename: \ + return #name; +#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" + default: + break; + } + return "UnknownLeaf"; +} + +void TypeDumpVisitor::printTypeIndex(StringRef FieldName, TypeIndex TI) const { + codeview::printTypeIndex(*W, FieldName, TI, TpiTypes); +} + +void TypeDumpVisitor::printItemIndex(StringRef FieldName, TypeIndex TI) const { + codeview::printTypeIndex(*W, FieldName, TI, getSourceTypes()); +} + +Error TypeDumpVisitor::visitTypeBegin(CVType &Record) { + return visitTypeBegin(Record, TypeIndex::fromArrayIndex(TpiTypes.size())); +} + +Error TypeDumpVisitor::visitTypeBegin(CVType &Record, TypeIndex Index) { + W->startLine() << getLeafTypeName(Record.Type); + W->getOStream() << " (" << HexNumber(Index.getIndex()) << ")"; + W->getOStream() << " {\n"; + W->indent(); + W->printEnum("TypeLeafKind", unsigned(Record.Type), + makeArrayRef(LeafTypeNames)); + return Error::success(); +} + +Error TypeDumpVisitor::visitTypeEnd(CVType &Record) { + if (PrintRecordBytes) + W->printBinaryBlock("LeafData", getBytesAsCharacters(Record.content())); + + W->unindent(); + W->startLine() << "}\n"; + return Error::success(); +} + +Error TypeDumpVisitor::visitMemberBegin(CVMemberRecord &Record) { + W->startLine() << getLeafTypeName(Record.Kind); + W->getOStream() << " {\n"; + W->indent(); + W->printEnum("TypeLeafKind", unsigned(Record.Kind), + makeArrayRef(LeafTypeNames)); + return Error::success(); +} + +Error TypeDumpVisitor::visitMemberEnd(CVMemberRecord &Record) { + if (PrintRecordBytes) + W->printBinaryBlock("LeafData", getBytesAsCharacters(Record.Data)); + + W->unindent(); + W->startLine() << "}\n"; + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, + FieldListRecord &FieldList) { + if (auto EC = codeview::visitMemberRecordStream(FieldList.Data, *this)) + return EC; + + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, StringIdRecord &String) { + printItemIndex("Id", String.getId()); + W->printString("StringData", String.getString()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ArgListRecord &Args) { + auto Indices = Args.getIndices(); + uint32_t Size = Indices.size(); + W->printNumber("NumArgs", Size); + ListScope Arguments(*W, "Arguments"); + for (uint32_t I = 0; I < Size; ++I) { + printTypeIndex("ArgType", Indices[I]); + } + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, StringListRecord &Strs) { + auto Indices = Strs.getIndices(); + uint32_t Size = Indices.size(); + W->printNumber("NumStrings", Size); + ListScope Arguments(*W, "Strings"); + for (uint32_t I = 0; I < Size; ++I) { + printItemIndex("String", Indices[I]); + } + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ClassRecord &Class) { + uint16_t Props = static_cast(Class.getOptions()); + W->printNumber("MemberCount", Class.getMemberCount()); + W->printFlags("Properties", Props, makeArrayRef(ClassOptionNames)); + printTypeIndex("FieldList", Class.getFieldList()); + printTypeIndex("DerivedFrom", Class.getDerivationList()); + printTypeIndex("VShape", Class.getVTableShape()); + W->printNumber("SizeOf", Class.getSize()); + W->printString("Name", Class.getName()); + if (Props & uint16_t(ClassOptions::HasUniqueName)) + W->printString("LinkageName", Class.getUniqueName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, UnionRecord &Union) { + uint16_t Props = static_cast(Union.getOptions()); + W->printNumber("MemberCount", Union.getMemberCount()); + W->printFlags("Properties", Props, makeArrayRef(ClassOptionNames)); + printTypeIndex("FieldList", Union.getFieldList()); + W->printNumber("SizeOf", Union.getSize()); + W->printString("Name", Union.getName()); + if (Props & uint16_t(ClassOptions::HasUniqueName)) + W->printString("LinkageName", Union.getUniqueName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, EnumRecord &Enum) { + uint16_t Props = static_cast(Enum.getOptions()); + W->printNumber("NumEnumerators", Enum.getMemberCount()); + W->printFlags("Properties", uint16_t(Enum.getOptions()), + makeArrayRef(ClassOptionNames)); + printTypeIndex("UnderlyingType", Enum.getUnderlyingType()); + printTypeIndex("FieldListType", Enum.getFieldList()); + W->printString("Name", Enum.getName()); + if (Props & uint16_t(ClassOptions::HasUniqueName)) + W->printString("LinkageName", Enum.getUniqueName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ArrayRecord &AT) { + printTypeIndex("ElementType", AT.getElementType()); + printTypeIndex("IndexType", AT.getIndexType()); + W->printNumber("SizeOf", AT.getSize()); + W->printString("Name", AT.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, VFTableRecord &VFT) { + printTypeIndex("CompleteClass", VFT.getCompleteClass()); + printTypeIndex("OverriddenVFTable", VFT.getOverriddenVTable()); + W->printHex("VFPtrOffset", VFT.getVFPtrOffset()); + W->printString("VFTableName", VFT.getName()); + for (auto N : VFT.getMethodNames()) + W->printString("MethodName", N); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFuncIdRecord &Id) { + printTypeIndex("ClassType", Id.getClassType()); + printTypeIndex("FunctionType", Id.getFunctionType()); + W->printString("Name", Id.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ProcedureRecord &Proc) { + printTypeIndex("ReturnType", Proc.getReturnType()); + W->printEnum("CallingConvention", uint8_t(Proc.getCallConv()), + makeArrayRef(CallingConventions)); + W->printFlags("FunctionOptions", uint8_t(Proc.getOptions()), + makeArrayRef(FunctionOptionEnum)); + W->printNumber("NumParameters", Proc.getParameterCount()); + printTypeIndex("ArgListType", Proc.getArgumentList()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, MemberFunctionRecord &MF) { + printTypeIndex("ReturnType", MF.getReturnType()); + printTypeIndex("ClassType", MF.getClassType()); + printTypeIndex("ThisType", MF.getThisType()); + W->printEnum("CallingConvention", uint8_t(MF.getCallConv()), + makeArrayRef(CallingConventions)); + W->printFlags("FunctionOptions", uint8_t(MF.getOptions()), + makeArrayRef(FunctionOptionEnum)); + W->printNumber("NumParameters", MF.getParameterCount()); + printTypeIndex("ArgListType", MF.getArgumentList()); + W->printNumber("ThisAdjustment", MF.getThisPointerAdjustment()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, + MethodOverloadListRecord &MethodList) { + for (auto &M : MethodList.getMethods()) { + ListScope S(*W, "Method"); + printMemberAttributes(M.getAccess(), M.getMethodKind(), M.getOptions()); + printTypeIndex("Type", M.getType()); + if (M.isIntroducingVirtual()) + W->printHex("VFTableOffset", M.getVFTableOffset()); + } + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, FuncIdRecord &Func) { + printItemIndex("ParentScope", Func.getParentScope()); + printTypeIndex("FunctionType", Func.getFunctionType()); + W->printString("Name", Func.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, TypeServer2Record &TS) { + W->printString("Guid", formatv("{0}", TS.getGuid()).str()); + W->printNumber("Age", TS.getAge()); + W->printString("Name", TS.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, PointerRecord &Ptr) { + printTypeIndex("PointeeType", Ptr.getReferentType()); + W->printHex("PointerAttributes", uint32_t(Ptr.getOptions())); + W->printEnum("PtrType", unsigned(Ptr.getPointerKind()), + makeArrayRef(PtrKindNames)); + W->printEnum("PtrMode", unsigned(Ptr.getMode()), makeArrayRef(PtrModeNames)); + + W->printNumber("IsFlat", Ptr.isFlat()); + W->printNumber("IsConst", Ptr.isConst()); + W->printNumber("IsVolatile", Ptr.isVolatile()); + W->printNumber("IsUnaligned", Ptr.isUnaligned()); + W->printNumber("IsRestrict", Ptr.isRestrict()); + W->printNumber("SizeOf", Ptr.getSize()); + + if (Ptr.isPointerToMember()) { + const MemberPointerInfo &MI = Ptr.getMemberInfo(); + + printTypeIndex("ClassType", MI.getContainingType()); + W->printEnum("Representation", uint16_t(MI.getRepresentation()), + makeArrayRef(PtrMemberRepNames)); + } + + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, ModifierRecord &Mod) { + uint16_t Mods = static_cast(Mod.getModifiers()); + printTypeIndex("ModifiedType", Mod.getModifiedType()); + W->printFlags("Modifiers", Mods, makeArrayRef(TypeModifierNames)); + + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, BitFieldRecord &BitField) { + printTypeIndex("Type", BitField.getType()); + W->printNumber("BitSize", BitField.getBitSize()); + W->printNumber("BitOffset", BitField.getBitOffset()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, + VFTableShapeRecord &Shape) { + W->printNumber("VFEntryCount", Shape.getEntryCount()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, + UdtSourceLineRecord &Line) { + printTypeIndex("UDT", Line.getUDT()); + printItemIndex("SourceFile", Line.getSourceFile()); + W->printNumber("LineNumber", Line.getLineNumber()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, + UdtModSourceLineRecord &Line) { + printTypeIndex("UDT", Line.getUDT()); + printItemIndex("SourceFile", Line.getSourceFile()); + W->printNumber("LineNumber", Line.getLineNumber()); + W->printNumber("Module", Line.getModule()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, BuildInfoRecord &Args) { + W->printNumber("NumArgs", static_cast(Args.getArgs().size())); + + ListScope Arguments(*W, "Arguments"); + for (auto Arg : Args.getArgs()) { + printItemIndex("ArgType", Arg); + } + return Error::success(); +} + +void TypeDumpVisitor::printMemberAttributes(MemberAttributes Attrs) { + return printMemberAttributes(Attrs.getAccess(), Attrs.getMethodKind(), + Attrs.getFlags()); +} + +void TypeDumpVisitor::printMemberAttributes(MemberAccess Access, + MethodKind Kind, + MethodOptions Options) { + W->printEnum("AccessSpecifier", uint8_t(Access), + makeArrayRef(MemberAccessNames)); + // Data members will be vanilla. Don't try to print a method kind for them. + if (Kind != MethodKind::Vanilla) + W->printEnum("MethodKind", unsigned(Kind), makeArrayRef(MemberKindNames)); + if (Options != MethodOptions::None) { + W->printFlags("MethodOptions", unsigned(Options), + makeArrayRef(MethodOptionNames)); + } +} + +Error TypeDumpVisitor::visitUnknownMember(CVMemberRecord &Record) { + W->printHex("UnknownMember", unsigned(Record.Kind)); + return Error::success(); +} + +Error TypeDumpVisitor::visitUnknownType(CVType &Record) { + W->printEnum("Kind", uint16_t(Record.kind()), makeArrayRef(LeafTypeNames)); + W->printNumber("Length", uint32_t(Record.content().size())); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + NestedTypeRecord &Nested) { + printTypeIndex("Type", Nested.getNestedType()); + W->printString("Name", Nested.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + OneMethodRecord &Method) { + MethodKind K = Method.getMethodKind(); + printMemberAttributes(Method.getAccess(), K, Method.getOptions()); + printTypeIndex("Type", Method.getType()); + // If virtual, then read the vftable offset. + if (Method.isIntroducingVirtual()) + W->printHex("VFTableOffset", Method.getVFTableOffset()); + W->printString("Name", Method.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + OverloadedMethodRecord &Method) { + W->printHex("MethodCount", Method.getNumOverloads()); + printTypeIndex("MethodListIndex", Method.getMethodList()); + W->printString("Name", Method.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + DataMemberRecord &Field) { + printMemberAttributes(Field.getAccess(), MethodKind::Vanilla, + MethodOptions::None); + printTypeIndex("Type", Field.getType()); + W->printHex("FieldOffset", Field.getFieldOffset()); + W->printString("Name", Field.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + StaticDataMemberRecord &Field) { + printMemberAttributes(Field.getAccess(), MethodKind::Vanilla, + MethodOptions::None); + printTypeIndex("Type", Field.getType()); + W->printString("Name", Field.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + VFPtrRecord &VFTable) { + printTypeIndex("Type", VFTable.getType()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + EnumeratorRecord &Enum) { + printMemberAttributes(Enum.getAccess(), MethodKind::Vanilla, + MethodOptions::None); + W->printNumber("EnumValue", Enum.getValue()); + W->printString("Name", Enum.getName()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + BaseClassRecord &Base) { + printMemberAttributes(Base.getAccess(), MethodKind::Vanilla, + MethodOptions::None); + printTypeIndex("BaseType", Base.getBaseType()); + W->printHex("BaseOffset", Base.getBaseOffset()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + VirtualBaseClassRecord &Base) { + printMemberAttributes(Base.getAccess(), MethodKind::Vanilla, + MethodOptions::None); + printTypeIndex("BaseType", Base.getBaseType()); + printTypeIndex("VBPtrType", Base.getVBPtrType()); + W->printHex("VBPtrOffset", Base.getVBPtrOffset()); + W->printHex("VBTableIndex", Base.getVTableIndex()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + ListContinuationRecord &Cont) { + printTypeIndex("ContinuationIndex", Cont.getContinuationIndex()); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, LabelRecord &LR) { + W->printEnum("Mode", uint16_t(LR.Mode), makeArrayRef(LabelTypeEnum)); + return Error::success(); +} + +Error TypeDumpVisitor::visitKnownRecord(CVType &CVR, + PrecompRecord &Precomp) { + W->printHex("StartIndex", Precomp.getStartTypeIndex()); + W->printHex("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(); +} diff --git a/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp b/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp index 9b8a6053..b1d51b2 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp @@ -1,482 +1,497 @@ -//===- TypeRecordMapping.cpp ------------------------------------*- C++ -*-===// -// -// 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/TypeRecordMapping.h" - -using namespace llvm; -using namespace llvm::codeview; - -#define error(X) \ - if (auto EC = X) \ - return EC; - -namespace { -struct MapOneMethodRecord { - explicit MapOneMethodRecord(bool IsFromOverloadList) - : IsFromOverloadList(IsFromOverloadList) {} - - Error operator()(CodeViewRecordIO &IO, OneMethodRecord &Method) const { - error(IO.mapInteger(Method.Attrs.Attrs)); - if (IsFromOverloadList) { - uint16_t Padding = 0; - error(IO.mapInteger(Padding)); - } - error(IO.mapInteger(Method.Type)); - if (Method.isIntroducingVirtual()) { - error(IO.mapInteger(Method.VFTableOffset)); - } else if (!IO.isWriting()) - Method.VFTableOffset = -1; - - if (!IsFromOverloadList) - error(IO.mapStringZ(Method.Name)); - - return Error::success(); - } - -private: - bool IsFromOverloadList; -}; -} - -static Error mapNameAndUniqueName(CodeViewRecordIO &IO, StringRef &Name, - StringRef &UniqueName, bool HasUniqueName) { - if (IO.isWriting()) { - // Try to be smart about what we write here. We can't write anything too - // large, so if we're going to go over the limit, truncate both the name - // and unique name by the same amount. - size_t BytesLeft = IO.maxFieldLength(); - if (HasUniqueName) { - size_t BytesNeeded = Name.size() + UniqueName.size() + 2; - StringRef N = Name; - StringRef U = UniqueName; - if (BytesNeeded > BytesLeft) { - size_t BytesToDrop = (BytesNeeded - BytesLeft); - size_t DropN = std::min(N.size(), BytesToDrop / 2); - size_t DropU = std::min(U.size(), BytesToDrop - DropN); - - N = N.drop_back(DropN); - U = U.drop_back(DropU); - } - - error(IO.mapStringZ(N)); - error(IO.mapStringZ(U)); - } else { - // Cap the length of the string at however many bytes we have available, - // plus one for the required null terminator. - auto N = StringRef(Name).take_front(BytesLeft - 1); - error(IO.mapStringZ(N)); - } - } else { - error(IO.mapStringZ(Name)); - if (HasUniqueName) - error(IO.mapStringZ(UniqueName)); - } - - return Error::success(); -} - -Error TypeRecordMapping::visitTypeBegin(CVType &CVR) { - assert(!TypeKind.hasValue() && "Already in a type mapping!"); - assert(!MemberKind.hasValue() && "Already in a member mapping!"); - - // FieldList and MethodList records can be any length because they can be - // split with continuation records. All other record types cannot be - // longer than the maximum record length. - Optional MaxLen; - if (CVR.Type != TypeLeafKind::LF_FIELDLIST && - CVR.Type != TypeLeafKind::LF_METHODLIST) - MaxLen = MaxRecordLength - sizeof(RecordPrefix); - error(IO.beginRecord(MaxLen)); - TypeKind = CVR.Type; - return Error::success(); -} - -Error TypeRecordMapping::visitTypeEnd(CVType &Record) { - assert(TypeKind.hasValue() && "Not in a type mapping!"); - assert(!MemberKind.hasValue() && "Still in a member mapping!"); - - error(IO.endRecord()); - - TypeKind.reset(); - return Error::success(); -} - -Error TypeRecordMapping::visitMemberBegin(CVMemberRecord &Record) { - assert(TypeKind.hasValue() && "Not in a type mapping!"); - assert(!MemberKind.hasValue() && "Already in a member mapping!"); - - // The largest possible subrecord is one in which there is a record prefix, - // followed by the subrecord, followed by a continuation, and that entire - // sequence spaws `MaxRecordLength` bytes. So the record's length is - // calculated as follows. - constexpr uint32_t ContinuationLength = 8; - error(IO.beginRecord(MaxRecordLength - sizeof(RecordPrefix) - - ContinuationLength)); - - MemberKind = Record.Kind; - return Error::success(); -} - -Error TypeRecordMapping::visitMemberEnd(CVMemberRecord &Record) { - assert(TypeKind.hasValue() && "Not in a type mapping!"); - assert(MemberKind.hasValue() && "Not in a member mapping!"); - - if (!IO.isWriting()) { - if (auto EC = IO.skipPadding()) - return EC; - } - - MemberKind.reset(); - error(IO.endRecord()); - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ModifierRecord &Record) { - error(IO.mapInteger(Record.ModifiedType)); - error(IO.mapEnum(Record.Modifiers)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - ProcedureRecord &Record) { - error(IO.mapInteger(Record.ReturnType)); - error(IO.mapEnum(Record.CallConv)); - error(IO.mapEnum(Record.Options)); - error(IO.mapInteger(Record.ParameterCount)); - error(IO.mapInteger(Record.ArgumentList)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - MemberFunctionRecord &Record) { - error(IO.mapInteger(Record.ReturnType)); - error(IO.mapInteger(Record.ClassType)); - error(IO.mapInteger(Record.ThisType)); - error(IO.mapEnum(Record.CallConv)); - error(IO.mapEnum(Record.Options)); - error(IO.mapInteger(Record.ParameterCount)); - error(IO.mapInteger(Record.ArgumentList)); - error(IO.mapInteger(Record.ThisPointerAdjustment)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ArgListRecord &Record) { - error(IO.mapVectorN( - Record.ArgIndices, - [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); })); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - StringListRecord &Record) { - error(IO.mapVectorN( - Record.StringIndices, - [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); })); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, PointerRecord &Record) { - error(IO.mapInteger(Record.ReferentType)); - error(IO.mapInteger(Record.Attrs)); - - if (Record.isPointerToMember()) { - if (!IO.isWriting()) - Record.MemberInfo.emplace(); - - MemberPointerInfo &M = *Record.MemberInfo; - error(IO.mapInteger(M.ContainingType)); - error(IO.mapEnum(M.Representation)); - } - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ArrayRecord &Record) { - error(IO.mapInteger(Record.ElementType)); - error(IO.mapInteger(Record.IndexType)); - error(IO.mapEncodedInteger(Record.Size)); - error(IO.mapStringZ(Record.Name)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ClassRecord &Record) { - assert((CVR.Type == TypeLeafKind::LF_STRUCTURE) || - (CVR.Type == TypeLeafKind::LF_CLASS) || - (CVR.Type == TypeLeafKind::LF_INTERFACE)); - - error(IO.mapInteger(Record.MemberCount)); - error(IO.mapEnum(Record.Options)); - error(IO.mapInteger(Record.FieldList)); - error(IO.mapInteger(Record.DerivationList)); - error(IO.mapInteger(Record.VTableShape)); - error(IO.mapEncodedInteger(Record.Size)); - error(mapNameAndUniqueName(IO, Record.Name, Record.UniqueName, - Record.hasUniqueName())); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, UnionRecord &Record) { - error(IO.mapInteger(Record.MemberCount)); - error(IO.mapEnum(Record.Options)); - error(IO.mapInteger(Record.FieldList)); - error(IO.mapEncodedInteger(Record.Size)); - error(mapNameAndUniqueName(IO, Record.Name, Record.UniqueName, - Record.hasUniqueName())); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, EnumRecord &Record) { - error(IO.mapInteger(Record.MemberCount)); - error(IO.mapEnum(Record.Options)); - error(IO.mapInteger(Record.UnderlyingType)); - error(IO.mapInteger(Record.FieldList)); - error(mapNameAndUniqueName(IO, Record.Name, Record.UniqueName, - Record.hasUniqueName())); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, BitFieldRecord &Record) { - error(IO.mapInteger(Record.Type)); - error(IO.mapInteger(Record.BitSize)); - error(IO.mapInteger(Record.BitOffset)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - VFTableShapeRecord &Record) { - uint16_t Size; - if (IO.isWriting()) { - ArrayRef Slots = Record.getSlots(); - Size = Slots.size(); - error(IO.mapInteger(Size)); - - for (size_t SlotIndex = 0; SlotIndex < Slots.size(); SlotIndex += 2) { - uint8_t Byte = static_cast(Slots[SlotIndex]) << 4; - if ((SlotIndex + 1) < Slots.size()) { - Byte |= static_cast(Slots[SlotIndex + 1]); - } - error(IO.mapInteger(Byte)); - } - } else { - error(IO.mapInteger(Size)); - for (uint16_t I = 0; I < Size; I += 2) { - uint8_t Byte; - error(IO.mapInteger(Byte)); - Record.Slots.push_back(static_cast(Byte & 0xF)); - if ((I + 1) < Size) - Record.Slots.push_back(static_cast(Byte >> 4)); - } - } - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, VFTableRecord &Record) { - error(IO.mapInteger(Record.CompleteClass)); - error(IO.mapInteger(Record.OverriddenVFTable)); - error(IO.mapInteger(Record.VFPtrOffset)); - uint32_t NamesLen = 0; - if (IO.isWriting()) { - for (auto Name : Record.MethodNames) - NamesLen += Name.size() + 1; - } - error(IO.mapInteger(NamesLen)); - error(IO.mapVectorTail( - Record.MethodNames, - [](CodeViewRecordIO &IO, StringRef &S) { return IO.mapStringZ(S); })); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, StringIdRecord &Record) { - error(IO.mapInteger(Record.Id)); - error(IO.mapStringZ(Record.String)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - UdtSourceLineRecord &Record) { - error(IO.mapInteger(Record.UDT)); - error(IO.mapInteger(Record.SourceFile)); - error(IO.mapInteger(Record.LineNumber)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - UdtModSourceLineRecord &Record) { - error(IO.mapInteger(Record.UDT)); - error(IO.mapInteger(Record.SourceFile)); - error(IO.mapInteger(Record.LineNumber)); - error(IO.mapInteger(Record.Module)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, FuncIdRecord &Record) { - error(IO.mapInteger(Record.ParentScope)); - error(IO.mapInteger(Record.FunctionType)); - error(IO.mapStringZ(Record.Name)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - MemberFuncIdRecord &Record) { - error(IO.mapInteger(Record.ClassType)); - error(IO.mapInteger(Record.FunctionType)); - error(IO.mapStringZ(Record.Name)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - BuildInfoRecord &Record) { - error(IO.mapVectorN( - Record.ArgIndices, - [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); })); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - MethodOverloadListRecord &Record) { - // TODO: Split the list into multiple records if it's longer than 64KB, using - // a subrecord of TypeRecordKind::Index to chain the records together. - error(IO.mapVectorTail(Record.Methods, MapOneMethodRecord(true))); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - FieldListRecord &Record) { - error(IO.mapByteVectorTail(Record.Data)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, - TypeServer2Record &Record) { - error(IO.mapGuid(Record.Guid)); - error(IO.mapInteger(Record.Age)); - error(IO.mapStringZ(Record.Name)); - return Error::success(); -} - -Error TypeRecordMapping::visitKnownRecord(CVType &CVR, LabelRecord &Record) { - error(IO.mapEnum(Record.Mode)); - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - BaseClassRecord &Record) { - error(IO.mapInteger(Record.Attrs.Attrs)); - error(IO.mapInteger(Record.Type)); - error(IO.mapEncodedInteger(Record.Offset)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - EnumeratorRecord &Record) { - error(IO.mapInteger(Record.Attrs.Attrs)); - - // FIXME: Handle full APInt such as __int128. - error(IO.mapEncodedInteger(Record.Value)); - error(IO.mapStringZ(Record.Name)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - DataMemberRecord &Record) { - error(IO.mapInteger(Record.Attrs.Attrs)); - error(IO.mapInteger(Record.Type)); - error(IO.mapEncodedInteger(Record.FieldOffset)); - error(IO.mapStringZ(Record.Name)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - OverloadedMethodRecord &Record) { - error(IO.mapInteger(Record.NumOverloads)); - error(IO.mapInteger(Record.MethodList)); - error(IO.mapStringZ(Record.Name)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - OneMethodRecord &Record) { - const bool IsFromOverloadList = (TypeKind == LF_METHODLIST); - MapOneMethodRecord Mapper(IsFromOverloadList); - return Mapper(IO, Record); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - NestedTypeRecord &Record) { - uint16_t Padding = 0; - error(IO.mapInteger(Padding)); - error(IO.mapInteger(Record.Type)); - error(IO.mapStringZ(Record.Name)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - StaticDataMemberRecord &Record) { - - error(IO.mapInteger(Record.Attrs.Attrs)); - error(IO.mapInteger(Record.Type)); - error(IO.mapStringZ(Record.Name)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - VirtualBaseClassRecord &Record) { - - error(IO.mapInteger(Record.Attrs.Attrs)); - error(IO.mapInteger(Record.BaseType)); - error(IO.mapInteger(Record.VBPtrType)); - error(IO.mapEncodedInteger(Record.VBPtrOffset)); - error(IO.mapEncodedInteger(Record.VTableIndex)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - VFPtrRecord &Record) { - uint16_t Padding = 0; - error(IO.mapInteger(Padding)); - error(IO.mapInteger(Record.Type)); - - return Error::success(); -} - -Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, - ListContinuationRecord &Record) { - uint16_t Padding = 0; - error(IO.mapInteger(Padding)); - error(IO.mapInteger(Record.ContinuationIndex)); - - return Error::success(); -} +//===- TypeRecordMapping.cpp ------------------------------------*- C++ -*-===// +// +// 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/TypeRecordMapping.h" + +using namespace llvm; +using namespace llvm::codeview; + +#define error(X) \ + if (auto EC = X) \ + return EC; + +namespace { +struct MapOneMethodRecord { + explicit MapOneMethodRecord(bool IsFromOverloadList) + : IsFromOverloadList(IsFromOverloadList) {} + + Error operator()(CodeViewRecordIO &IO, OneMethodRecord &Method) const { + error(IO.mapInteger(Method.Attrs.Attrs)); + if (IsFromOverloadList) { + uint16_t Padding = 0; + error(IO.mapInteger(Padding)); + } + error(IO.mapInteger(Method.Type)); + if (Method.isIntroducingVirtual()) { + error(IO.mapInteger(Method.VFTableOffset)); + } else if (!IO.isWriting()) + Method.VFTableOffset = -1; + + if (!IsFromOverloadList) + error(IO.mapStringZ(Method.Name)); + + return Error::success(); + } + +private: + bool IsFromOverloadList; +}; +} + +static Error mapNameAndUniqueName(CodeViewRecordIO &IO, StringRef &Name, + StringRef &UniqueName, bool HasUniqueName) { + if (IO.isWriting()) { + // Try to be smart about what we write here. We can't write anything too + // large, so if we're going to go over the limit, truncate both the name + // and unique name by the same amount. + size_t BytesLeft = IO.maxFieldLength(); + if (HasUniqueName) { + size_t BytesNeeded = Name.size() + UniqueName.size() + 2; + StringRef N = Name; + StringRef U = UniqueName; + if (BytesNeeded > BytesLeft) { + size_t BytesToDrop = (BytesNeeded - BytesLeft); + size_t DropN = std::min(N.size(), BytesToDrop / 2); + size_t DropU = std::min(U.size(), BytesToDrop - DropN); + + N = N.drop_back(DropN); + U = U.drop_back(DropU); + } + + error(IO.mapStringZ(N)); + error(IO.mapStringZ(U)); + } else { + // Cap the length of the string at however many bytes we have available, + // plus one for the required null terminator. + auto N = StringRef(Name).take_front(BytesLeft - 1); + error(IO.mapStringZ(N)); + } + } else { + error(IO.mapStringZ(Name)); + if (HasUniqueName) + error(IO.mapStringZ(UniqueName)); + } + + return Error::success(); +} + +Error TypeRecordMapping::visitTypeBegin(CVType &CVR) { + assert(!TypeKind.hasValue() && "Already in a type mapping!"); + assert(!MemberKind.hasValue() && "Already in a member mapping!"); + + // FieldList and MethodList records can be any length because they can be + // split with continuation records. All other record types cannot be + // longer than the maximum record length. + Optional MaxLen; + if (CVR.Type != TypeLeafKind::LF_FIELDLIST && + CVR.Type != TypeLeafKind::LF_METHODLIST) + MaxLen = MaxRecordLength - sizeof(RecordPrefix); + error(IO.beginRecord(MaxLen)); + TypeKind = CVR.Type; + return Error::success(); +} + +Error TypeRecordMapping::visitTypeEnd(CVType &Record) { + assert(TypeKind.hasValue() && "Not in a type mapping!"); + assert(!MemberKind.hasValue() && "Still in a member mapping!"); + + error(IO.endRecord()); + + TypeKind.reset(); + return Error::success(); +} + +Error TypeRecordMapping::visitMemberBegin(CVMemberRecord &Record) { + assert(TypeKind.hasValue() && "Not in a type mapping!"); + assert(!MemberKind.hasValue() && "Already in a member mapping!"); + + // The largest possible subrecord is one in which there is a record prefix, + // followed by the subrecord, followed by a continuation, and that entire + // sequence spaws `MaxRecordLength` bytes. So the record's length is + // calculated as follows. + constexpr uint32_t ContinuationLength = 8; + error(IO.beginRecord(MaxRecordLength - sizeof(RecordPrefix) - + ContinuationLength)); + + MemberKind = Record.Kind; + return Error::success(); +} + +Error TypeRecordMapping::visitMemberEnd(CVMemberRecord &Record) { + assert(TypeKind.hasValue() && "Not in a type mapping!"); + assert(MemberKind.hasValue() && "Not in a member mapping!"); + + if (!IO.isWriting()) { + if (auto EC = IO.skipPadding()) + return EC; + } + + MemberKind.reset(); + error(IO.endRecord()); + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ModifierRecord &Record) { + error(IO.mapInteger(Record.ModifiedType)); + error(IO.mapEnum(Record.Modifiers)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + ProcedureRecord &Record) { + error(IO.mapInteger(Record.ReturnType)); + error(IO.mapEnum(Record.CallConv)); + error(IO.mapEnum(Record.Options)); + error(IO.mapInteger(Record.ParameterCount)); + error(IO.mapInteger(Record.ArgumentList)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + MemberFunctionRecord &Record) { + error(IO.mapInteger(Record.ReturnType)); + error(IO.mapInteger(Record.ClassType)); + error(IO.mapInteger(Record.ThisType)); + error(IO.mapEnum(Record.CallConv)); + error(IO.mapEnum(Record.Options)); + error(IO.mapInteger(Record.ParameterCount)); + error(IO.mapInteger(Record.ArgumentList)); + error(IO.mapInteger(Record.ThisPointerAdjustment)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ArgListRecord &Record) { + error(IO.mapVectorN( + Record.ArgIndices, + [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); })); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + StringListRecord &Record) { + error(IO.mapVectorN( + Record.StringIndices, + [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); })); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, PointerRecord &Record) { + error(IO.mapInteger(Record.ReferentType)); + error(IO.mapInteger(Record.Attrs)); + + if (Record.isPointerToMember()) { + if (!IO.isWriting()) + Record.MemberInfo.emplace(); + + MemberPointerInfo &M = *Record.MemberInfo; + error(IO.mapInteger(M.ContainingType)); + error(IO.mapEnum(M.Representation)); + } + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ArrayRecord &Record) { + error(IO.mapInteger(Record.ElementType)); + error(IO.mapInteger(Record.IndexType)); + error(IO.mapEncodedInteger(Record.Size)); + error(IO.mapStringZ(Record.Name)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, ClassRecord &Record) { + assert((CVR.Type == TypeLeafKind::LF_STRUCTURE) || + (CVR.Type == TypeLeafKind::LF_CLASS) || + (CVR.Type == TypeLeafKind::LF_INTERFACE)); + + error(IO.mapInteger(Record.MemberCount)); + error(IO.mapEnum(Record.Options)); + error(IO.mapInteger(Record.FieldList)); + error(IO.mapInteger(Record.DerivationList)); + error(IO.mapInteger(Record.VTableShape)); + error(IO.mapEncodedInteger(Record.Size)); + error(mapNameAndUniqueName(IO, Record.Name, Record.UniqueName, + Record.hasUniqueName())); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, UnionRecord &Record) { + error(IO.mapInteger(Record.MemberCount)); + error(IO.mapEnum(Record.Options)); + error(IO.mapInteger(Record.FieldList)); + error(IO.mapEncodedInteger(Record.Size)); + error(mapNameAndUniqueName(IO, Record.Name, Record.UniqueName, + Record.hasUniqueName())); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, EnumRecord &Record) { + error(IO.mapInteger(Record.MemberCount)); + error(IO.mapEnum(Record.Options)); + error(IO.mapInteger(Record.UnderlyingType)); + error(IO.mapInteger(Record.FieldList)); + error(mapNameAndUniqueName(IO, Record.Name, Record.UniqueName, + Record.hasUniqueName())); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, BitFieldRecord &Record) { + error(IO.mapInteger(Record.Type)); + error(IO.mapInteger(Record.BitSize)); + error(IO.mapInteger(Record.BitOffset)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + VFTableShapeRecord &Record) { + uint16_t Size; + if (IO.isWriting()) { + ArrayRef Slots = Record.getSlots(); + Size = Slots.size(); + error(IO.mapInteger(Size)); + + for (size_t SlotIndex = 0; SlotIndex < Slots.size(); SlotIndex += 2) { + uint8_t Byte = static_cast(Slots[SlotIndex]) << 4; + if ((SlotIndex + 1) < Slots.size()) { + Byte |= static_cast(Slots[SlotIndex + 1]); + } + error(IO.mapInteger(Byte)); + } + } else { + error(IO.mapInteger(Size)); + for (uint16_t I = 0; I < Size; I += 2) { + uint8_t Byte; + error(IO.mapInteger(Byte)); + Record.Slots.push_back(static_cast(Byte & 0xF)); + if ((I + 1) < Size) + Record.Slots.push_back(static_cast(Byte >> 4)); + } + } + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, VFTableRecord &Record) { + error(IO.mapInteger(Record.CompleteClass)); + error(IO.mapInteger(Record.OverriddenVFTable)); + error(IO.mapInteger(Record.VFPtrOffset)); + uint32_t NamesLen = 0; + if (IO.isWriting()) { + for (auto Name : Record.MethodNames) + NamesLen += Name.size() + 1; + } + error(IO.mapInteger(NamesLen)); + error(IO.mapVectorTail( + Record.MethodNames, + [](CodeViewRecordIO &IO, StringRef &S) { return IO.mapStringZ(S); })); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, StringIdRecord &Record) { + error(IO.mapInteger(Record.Id)); + error(IO.mapStringZ(Record.String)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + UdtSourceLineRecord &Record) { + error(IO.mapInteger(Record.UDT)); + error(IO.mapInteger(Record.SourceFile)); + error(IO.mapInteger(Record.LineNumber)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + UdtModSourceLineRecord &Record) { + error(IO.mapInteger(Record.UDT)); + error(IO.mapInteger(Record.SourceFile)); + error(IO.mapInteger(Record.LineNumber)); + error(IO.mapInteger(Record.Module)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, FuncIdRecord &Record) { + error(IO.mapInteger(Record.ParentScope)); + error(IO.mapInteger(Record.FunctionType)); + error(IO.mapStringZ(Record.Name)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + MemberFuncIdRecord &Record) { + error(IO.mapInteger(Record.ClassType)); + error(IO.mapInteger(Record.FunctionType)); + error(IO.mapStringZ(Record.Name)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + BuildInfoRecord &Record) { + error(IO.mapVectorN( + Record.ArgIndices, + [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); })); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + MethodOverloadListRecord &Record) { + // TODO: Split the list into multiple records if it's longer than 64KB, using + // a subrecord of TypeRecordKind::Index to chain the records together. + error(IO.mapVectorTail(Record.Methods, MapOneMethodRecord(true))); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + FieldListRecord &Record) { + error(IO.mapByteVectorTail(Record.Data)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, + TypeServer2Record &Record) { + error(IO.mapGuid(Record.Guid)); + error(IO.mapInteger(Record.Age)); + error(IO.mapStringZ(Record.Name)); + return Error::success(); +} + +Error TypeRecordMapping::visitKnownRecord(CVType &CVR, LabelRecord &Record) { + error(IO.mapEnum(Record.Mode)); + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + BaseClassRecord &Record) { + error(IO.mapInteger(Record.Attrs.Attrs)); + error(IO.mapInteger(Record.Type)); + error(IO.mapEncodedInteger(Record.Offset)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + EnumeratorRecord &Record) { + error(IO.mapInteger(Record.Attrs.Attrs)); + + // FIXME: Handle full APInt such as __int128. + error(IO.mapEncodedInteger(Record.Value)); + error(IO.mapStringZ(Record.Name)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + DataMemberRecord &Record) { + error(IO.mapInteger(Record.Attrs.Attrs)); + error(IO.mapInteger(Record.Type)); + error(IO.mapEncodedInteger(Record.FieldOffset)); + error(IO.mapStringZ(Record.Name)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + OverloadedMethodRecord &Record) { + error(IO.mapInteger(Record.NumOverloads)); + error(IO.mapInteger(Record.MethodList)); + error(IO.mapStringZ(Record.Name)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + OneMethodRecord &Record) { + const bool IsFromOverloadList = (TypeKind == LF_METHODLIST); + MapOneMethodRecord Mapper(IsFromOverloadList); + return Mapper(IO, Record); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + NestedTypeRecord &Record) { + uint16_t Padding = 0; + error(IO.mapInteger(Padding)); + error(IO.mapInteger(Record.Type)); + error(IO.mapStringZ(Record.Name)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + StaticDataMemberRecord &Record) { + + error(IO.mapInteger(Record.Attrs.Attrs)); + error(IO.mapInteger(Record.Type)); + error(IO.mapStringZ(Record.Name)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + VirtualBaseClassRecord &Record) { + + error(IO.mapInteger(Record.Attrs.Attrs)); + error(IO.mapInteger(Record.BaseType)); + error(IO.mapInteger(Record.VBPtrType)); + error(IO.mapEncodedInteger(Record.VBPtrOffset)); + error(IO.mapEncodedInteger(Record.VTableIndex)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + VFPtrRecord &Record) { + uint16_t Padding = 0; + error(IO.mapInteger(Padding)); + error(IO.mapInteger(Record.Type)); + + return Error::success(); +} + +Error TypeRecordMapping::visitKnownMember(CVMemberRecord &CVR, + ListContinuationRecord &Record) { + uint16_t Padding = 0; + error(IO.mapInteger(Padding)); + error(IO.mapInteger(Record.ContinuationIndex)); + + 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(); +} diff --git a/llvm/lib/ObjectYAML/COFFYAML.cpp b/llvm/lib/ObjectYAML/COFFYAML.cpp index 937b8dc..9351ef9 100644 --- a/llvm/lib/ObjectYAML/COFFYAML.cpp +++ b/llvm/lib/ObjectYAML/COFFYAML.cpp @@ -562,14 +562,16 @@ void MappingTraits::mapping(IO &IO, COFFYAML::Section &Sec) { 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); diff --git a/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp b/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp index ba4ad93..06aeb6d 100644 --- a/llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp +++ b/llvm/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; +} diff --git a/llvm/test/DebugInfo/Inputs/precomp-a.obj b/llvm/test/DebugInfo/Inputs/precomp-a.obj new file mode 100644 index 0000000000000000000000000000000000000000..930d64d98ccab9ddb6a68c39536d2a03270677d7 GIT binary patch literal 2275 zcmbtVO>7%g5T31_G)>ync4-cX!;@>Fq^h^;#B~}A(T)E|6vqj~4sEnby4l^>+uFOv z-c4L2q@Y$D5C?9p1VTti+>y8-^-!t6nN~gY1UFPsB;*wJ!lBHpcO4sv5YdrlXWqPT z=gpfp?~VG=Abk7$?%MiMfK$*RUTtWKwXL~B*hR(9c_UX22Y^?#O}iXf@n#+)<`%N# z>sb6KL&7D$t zyHYN-s>0a#9`7#jMpOnKw7D zK@#2wa#sO<66>zF=X<24w(q`T^bLd96>pV zlGejx+5HnG{ZD62bQU?leSG(~&8KJny7TbqcZmSW|%BIm7>R zDfd=~U&6&~F~68gONa3Eu5PI2PLnO@R#S=zl5QwfTh&nI1wNLToSDJ>+e*U+@I07IT+ZG7D0iPw=s>Z@YHT-ugWJTSU!@+|bmQc5|pmpgjuyu_IWIC$RQL zktZ<^Cs7`pwH@8Sw6SP$nME&Sjd$v$bL;lnygNRqZl!G{78kH1Y(o20@Qn??2(Ee@ zIfxuW4j}Kf=WhN!{*C;EuFTZExtrgQ-=}6VjO+&vo1i~MQ*^KPiTa8U=h2^|(Hn5m z(L{Q#d0oA|KESr*!T5+FxyDW7! zA4h$*pZJ~*OMm+~+6S##`s~rAeeAwxhVQ!bZn%?vAWI})nDWqs9faPVjPE*nrYsOW znE8Q{;ga*fpzdIxw?ktWz`r^f1XxXc@uv3=z!_I{FmN76m%N8d6tB$AWyCdz*ant~ N8gZhHIIX{<{|)@U@|get literal 0 HcmV?d00001 diff --git a/llvm/test/DebugInfo/Inputs/precomp.obj b/llvm/test/DebugInfo/Inputs/precomp.obj new file mode 100644 index 0000000000000000000000000000000000000000..1ae176c254e8070bfb720835917a494645245edd GIT binary patch literal 62021 zcmeHwd7NBDwf~)-NeBVLBtVP^I7Gm(WS9g9Fd$5}foMWvHWo*kp6)v{o%D1!y-YHQ z2#AP?h`7K*MN~vZR7AuL5pl;2<;inFQ52Ww!kZwX@|5@e)~)JWx9+*aox$IKzxsS; zZr66ssc)S+b*kzvh0AAnAN}jy=j=V>@j$ z;Em$%Xs>PVoa^V$?e86^kCg{XrNThNuQvu(uJ7+3r~;nKXw_W1D}&p-Uhm|&ZRdI3 z1KvKUe%-lkt?RmCzE-JMh8kUqHXh!!zS<~`7B484hr3pSMzQ4AP+swU@Bq(yu{Ue( zjD0;Xn;pw%bB#u=IM@W^-ri!dkS*4in-p&m3O)l?v4RDEDAz1C!jea!=Itx}4Xd`K!;tyQYkrX?kjeLyN%&o#!Y4)bqF1@o1BDOb1p;82jfPbyi;7cEG; zQS5H9SaGnHtBq#|OO^cguuY3m{w}F}xl$giRd&>KgC$Ge!%_TpsrYC;+bkC=<&ZM_ z;8v+koGR5stNH!7nc(IZjtMya6gf|@@R7N!K(ONE=onBuZw*Ggq; zey&g{m&QY~gzPG*s6XbH8`*lLS<73HorvO>r7qsvTL}iOpY^@tQ1y~2RHbgA8qs{U zRIS<^EEV%%OID!Z4yoXXU#j}Gh)pP08pWY;B$WX5SV-ek&^SLO4U)~)VQ0$2Apr`p zJtcvfe}1!A^Xu8MT&Zbc{1VXcQ_{%QVe-al$ChMsrABlV_oM#V)34v#t2=Hz z=xj+zCs4C&u8fY!H8AqR-U_i@4ub1a5=6J={dzs?=W4dLvwu%ZNn#XpK~d_PgO6!n|m_q zFHBh<+UfM)NvM55`r75(sD&WS?R=>+tao;_QfS(911HkGq{5iU8WDejUczot$wn<# zu8$TQ*_<`=(TulArGts2R2&Sop=8a|6ykh%kTFMa2WHf4ek4~@V0i3?`z5-ztHP##MJhB>EEIgJzo-EB zNCg`soSh@H$?+(ASGuw=yQaRLH1Ciq!r_J^8mbu8{5Gke1~@FquDC@ii5U!&AidkL zFujT!rNTQf;blj2wfacT>Iq75y;R)C@QL_V^lYw{O48A&lx?CcdWBSUs91A`Fgx#3 zspx2KXJo8X#V(WzR!V-Z3Fl5tULg)_*qBtFrmftxd_hvKN+sdCVvPCadNJa=65(x9 z`P}eu%^!BnE}gHz)WutKIJulFRnxPBu@;?6 zQDshIm3k#t&5q>C1uVitgib)6naOpURRWszYqd%ZE8?L_Sd)H{msk^91}Lw44&$a# zvlcMa?7z(wthmCPJ~r%ATvlrKf%T#ojETJG4P6rQK0`=ZsMoT8D;bT%w zJuzX0W{pW&rbndG)Yj-antJkMsc5y98y?MtvUAWpC>6|MI(AkAB>EkxY|U@L)eDJI zQNAt}%;)NsW5Z(iO2wMkv<#`S<31-9bEbNVcc)a&ok5A?ZBjuF=OLUNguGew7O5!q z7U6W;iyEr^O;XVuy}E3)O_cQpsW3K{;gW;`uz%hr6)gGX;l@a0e3IzZQrR*1do^nt zl0>f%3l_7kAt3^nN@Y=S3@c%4XwsyQOGP6))tmt9QmJO$uVWR!9TepRh9IzEqf(V% zS0pS*35KMC75BvAJgJns%R}R|DMi87c%F|6>setlcBfbQ!K7NLdDQeZOs{9N8#ixW z!xO5K-|*L~5w;cvs8Ojc^%kJm?z-5@9JX6Hs7cCOXb2=%_x3}XcAOH{8-?E9a$0oQTDf||<~8fj@D4=&p<2=i+2yrbZrmfqZf0-BYG%h8IP+?oM2Vpx5CmE3?T>o< zvRtFikU(NHjy?gdCy z?NRu)WD7X6_Y~~_{3ObIqS*XE!2SRs)fDg%TC*1lzX-caYLabuhMdFId}V0J9IBdYcQrqPq7(QdjhWus zxt%y4XT zbY?(jPf$8crbAs&mGJ{Lc1?iyJmS$l)AQzdvpU;V3);LHpflUcbk5ZD#=Q1tZ-5#j;=M${%@T zR|5)F?^?v8bsmd%DK`e2VTS{+Io{0q)Ggd~;H?GSZm&b=ds0wqa)Q0J71MpaC+f1V ziSJ(ceH3CZmHW%pp!f|w5;dG?mIihS3LgR5Dxi3hM;G{+@pCYK8{J-r-$u8O&=|i6X`azvfi3l%eGVI# zIYgBWkP7rTB1%+`<5?|CI585FOF?Q`A`anXY5;GgfYMCZWlBPu9E?xTTSU6hqr-7! zn~BBV_-(K_Qm2altFY&?M2)F~k>BAlzO)sesp7||_!97+rQ*jb8Q7MkR$Dqlw@Hv;=6pIWjSZuY zoQN{ik&CoEoS(g5eh!C}w($#*qioAcoIvI{4RWB=mE6HRzGK9x zl^&J$%Ywem7i>R^y0B-0F0dat&fR|G+;kf9(8rtn(h$b$jQs#{=5(Z)5ccbHYdiaP z4d}9OuL5ymf$^dGmVNOuq_Z#S&s33aZ2mHh&06F`*SGd>=6W#jE$QFR^03>j^>`i1 zbb8zY_mt1g@pp!*$GXgO*QBcB=--CAik_mZT)|S-)u@-?tGIVjx+`ZAchdTtgLE)M zpPqv@X3!UH9uD83>-?SZ{GGo3-R{->+E_7f;vHVIT(A21;!x2qw92nOYjvyqrqvs_ zu35?WkhdH9bXJD8Y9rd?2+-T>NZ4A&L;5q1RbH;&=admzF|lzPK6yBciH^DQ%enQi z8GnyrGN;Z|(GD{=ZbdqEW(DTey^+qcXIg)3a}WNQ#@{B-q?z*BLSb^`Z zbd&M3@#kgs_RiuJ0Wzqy6?w(WwRx}5<>GmP-6DbZR+hWp|=Tsvui&h`*SoNc7ni3tu+V1!`4~G^Z4U^>YOJT_J@6$3tcE6Zqp=2 zl&#InWPDwg<=f&|M5?8cjTmqjk{G-TN}ke&x|^9~<)jHnpdDshQU^GeM{u=qVSF3@ zyiA){ez*z7B$ZC6ky&8;D~a{D|Yr z;rOQAfQF?kA_}P8H`0MZ|*~80`9;Y1o7s%!9 z_)2!#!`G9J4uU-tNTrvZcwGVd#Oop8m2w_&Px}#Gf># zuR^-Zj55;Zy@_>n5XQ7yEwzlq98HE! znt+(rrFVdrjTz(D;ZM?~>yhpdRx(nT{)2UN5Om3{mRd$)asy}+lQqz#p>*?vbe>P1 zLV7Yb?*dO78^+&_KU<%Sk9H%{1>%;U7OZC|KlSK6q@#nNM-r(i$xqyF0uSQ048C^S zF^E-s^p**7jonC*jM@9Z&&G`L_v6pjr-Squycy{+(t4hwPJMv&bP#kZUUdqx5}#W@ zpZJ`f-v5Z-eL|kG)MR`<1b#L?jDHw^woY+Bmp1BFq{m1{d{42SKmm z^iI$wrVC)-683l9HI;K)71>3T1Vq&w zc^CNDcryNJ{MmRKoAw!`N2x~UN8ZGp<(>>>rcL`S>F6L}JP`~JxGs`jf~Aee+)KXBn=$|Y@%dR%1dnS z1zlouH+;{O*hFveBd1b#xHsK(|_I8HvevK%1C6oqqlk?l>jOc(QkMuZY zPx<2X4}QRUItbVZRnyB#d>#aS;?td8XWUzN$^mGvHkV`VP{KV_WpiR8)NUu-vyQ0Z4mYR&& zPr=W|jPZx@C+XAAkRBs#`I|pyJskvnidUV2ti8} zC3xBxG5#q2Y>XD_Iqg?SmuORmC^N_1uUS_I0VlEgRAeSrkAVlVdJMW$2463JucJFR zB;NZ^-btAfW}LTp#)%Qus6ju1vrlYs>faf?3MM8O;QX>(pI`nC^2TPYB*x-FW>R56 zO7JF5zt=c@0OFc62BvXe^S8L#{m%Fw@ke{|2VN2S(N>=4v5q;@j5K^CyrVr5gCi96Ntu9UX+R<5Wv0AF+56bcw}=^y4MrVH|ain2;x+16|;HAs8>X zsSr;BQ9pt)gWFkKV+M~F;%ykbA7IQHGk=53u`!dtT^uqAWd%vqc=@}==?e709GnNh z6njkT!Ifj?Dg3tkneqR{AG*$anpXrf&REZ^J;QQs-oJFYcwV?JHD~PqL|IyzXY>`f z<-_+2#w6*RG08LbHsmEVSIzw_Z^k3XXAfc>9-frL=_sCvs`_QT#sK#{bF9w9Sj~W* z34$+>#EMFpkSCz7?G&FMqkg^~3{%d1IH%N)Fw5gDc+os!(g7u#P1$tdJ%H|; z(4H$Mv=w~tkA3kt_@uO((WeKg0g;qs{PzMc8-K>E?qPC zQjcH_B4-rF$DdDnItb%BMl!AZ#EVa%60Z*IRi)hji#^Rser{qCUe5NJ>F6Nf6eE>ZZsNq}dWq9F)9V$^Z6l8dlbw?$palC$JNH8H zvvFd)i|w;;GW#(HBi$iv*{onc+330fD=`nJjwI)9&O~z+GN7hkwNGP{?6p$M}oc?o5Yw7_SKKy#uUk=8dp?yLY%QZ+r{GCtfz=9jVL4 z^FrIWP~Tgy2xU3{9HFmA>FZ)#`E1ADm_54j+X2JsS2bm~;3H81Ke zBxehnqQ=rv$YARO*^r+Q_odqV#Swt5UcATW6JYq;WZ#cDxRE#(<<<^abkQm z+iK~WvA1DfXm5?b-;X-9x2NGs|AOa*r{i~A68lVy@6rqQr+H?$hJ1Ap^id#{zOBTU zFH#}CzXFex_zJINA$jj?2(m+n9R~*f#o)71Glo8S6y4(`p-Wu7WRdo)4T;+F;f1;*01gg_JP~wl(m# zv1PnYEG%q|{)c&S{coTS^}mTL?_s0}(D^ueA3+fJR|LEbtf^@B)r zift$MJHd(waB{<;X)d3dgm{q-9B7F%HL2|!Ev7Dx5oeA|A_vQ};;ooxx8 zdClT(>To^0uPPf&TYxpPdJ`iLJv2YoKY+7-9WQ{>&*Bl2F5?N{&8n)7RsIm<;hFN1 zEyE&@F9OzOv)lp={m>qpuUS<>Ke}MH$3iIOoS7BbLYv!Emb)ZLGyIfyi zk8ALZOuKglen;Nf8LubJqxH-M%I!ZR|{#*6)P zC1|sMx~6Ea)wptB*w-={PDVn19R_>BcR?8&VcQLk3&xqpe!U8E+WpG-)x;$;%X<^A z2&P}dys+=gTKLT<%f7n?*N3!Se+zz#?a_Tl83H>I9pfF&xTn0q^T2U?g8j(W)}B3< z7dYda?LGkBE#7`qZ{%>pleROY-R0%^T7j%xU)chdr551^YUXk70cM$NH7=CCXR@*G zbeB3cmjFrVN9xgA!HatI2k6ll_@`JqD7{s4pEAMG7wNX9zj$7P6v5fS+aZUoCyc*? zI0*B9m>1WR>rjV!ay_nQ{{IjBPLkJ*U*m@n1J3_9khcz#&j0ats%}W&mxuxT;+^2h zzW6EpfRyVv)fe%XAhQ=@sfoNfPTvjQHvWv?NDOe#fqO;}=7rA*n=u^bg?(e}?|VRx zeRGq(z86>C`@{PR-iO~Yi7lHOjN@>=oaNz_7Ii;6gg2&f><}+Lm-v3rF+n)H{67$VTj%*`qdyUtf>3vMsjpxO6DdZXI(h>SB>LZ{- zUHYiLeq3K~*Vj+rdV|uf8QvZEE#TWahvK=2dh58QZ}Im-1ZP#j+Y!Qb!vYWA%c$cU zKUUo?b%!TD!C}n-i@d>RX?u3a$J;uMt=|Ls`bo%ULXxeQWakJM(i3%tI(sL0QD@gp zQD>Dc8*$#`-ZJz~MuG(P*=G+LZ2qW|cR?;&CmH_?alzT=r+Gy%`V!{F^(D*;^~Knp z&w>v1<#YP_d0c}t%XaT>{1)37@d1N#d(Ib>eU@3>Tkiwe-7Bhj+?1KkH%UM*IIr)9 zzWxIEn2=Q7up;{-?cT2$Lr1TzB&obBI?NeLj5uJ=F6Z%{rQT%eobG$uCL#~ z^-^tbzKP#)97CJInT{`LGQP)iv^5dC!g-KBbETi`=I^QUN2 z#P3hQrU~hZx<=da9q_mHiSh5U?SkJJ=7s%h))(JH9ro`7xSF%J@8h>1PpjWBZcGndw9Eu*|Oo_s?+s z_Gi#AA<0LI@t6{BcxD4U*k3Ncl83_!AR`bXHS8S2}ymH$Y&bZam@V< zJlTg2OwrC^rI-8>Fv>Dnfl2!EACSlHOU9ojE|#4$V=v4L`^)$t|BE{8uYcl7yU6p9 zf8qCJVnzEZSf|h~av$p%%AiA%U7VEmG%;Zx@l$N9&>F^8+pm#Ue%%+>z=z0q`{B1Fp0RPknGP0RdT)j@;kyC&Xlhnr!{?Xg zYZ)j<(zp|OOc@(IivnKkn^$2Tn#!I%_&ZE9*GYfutLH;L zyRR630rAP~=Izfbg6XR;FYaT6d0{^qpYQdVbj*O%DmTZ578BqwMLb>T(eZR-N#hp^q)`*-){ z!@RgIgn4mYI281#3y10Ji*dbH>%t=Z28NEnq20w@r-ClT`<*u1?RVJhNWVi5V*S3z z>G$1XD-MTDCQQ2j?tD6TD%i8%`C(r6`y0^jQ?cRVmwu^sQpO~Ge-!xJeb4w}wq3YS zvm5CWd5#y#&igcvW?dbG`!oYzLi$Sa6lEuN{0=g)dk^Nnl+TJrzlKSkk(55?2AV$g zj(LuerQl`b#P~66tMwd~v6o?9e6K3Zi=Ur{dExjm&sZG`UK~Hi>FY9mJs#KKyrRQ9 z0ly>7v23S)I=f~6rt^#yG3K7tiQr>`@QhVdgp?SwKl%A<_UC2j&vVoHGwxTk$<0Yi z?$eXO&+b#kU&6Loy1zec6#f2FknRvxGE(PHWgQ&^op-CHmXVnBfi^MuEa<27BO(uQ zw;mf(cOS@E0z&G!o)zG2mKgatgC~7Q$lsZC1*);6SIEs zA!g0=&u(IlaK7^nu5O~lkGA1-@UwAZd=1-*_2Uf4!C>zHeJRpiy2fX1=OKOYb`E|< zQ{BJ7aln1dmywE`*AGazj9WgU+5crbh}+9aO9uhB1aeB}Qn!N`ZUi4<_$FYO z(srSXtN31NbcDKzNw{qWKN~m3x3I0&*fj4d+lq9TE_IG_(te%EdO8T>GFFx7xQUXS z#N{l|CN76#EKX6kcrRrX9MfBo9Dy_1M%_9Gylspae+Anr=+*$zMe>n3G}uEky7fxZ z(qR(aibxw7B9R=q9mMcl@F9k;O+P-(u_4csqZo=gGH>hMIe0+3<^}J~fu*eMu)dv> zEA7aQt94Y(dUs9^GCR&xZ?DK(d~=RiQjk);H)l}eb1?8R_b4%qI&dDYwhl1vZ_LUepen?ANA>*J%8(IMw1O8ls+HSn`> zV!Y0_S~wY--axub*S6_R*3&`2C{~r|xQUXS#AOV$iObpW(^J~?O3CM5+$i3`RVhc& zk+US;#AqjY+ZZuE&bC?@8C|*n=`!_DmtMuXItVx=R3}<;mLxYZyAXVc*;VOvi4TPo z>rt?rG=ZC*`z``M8z;tJ!?p@@-^ECG2)EXWYSm+XYry!UmynhY!rbSQBVbONEIYBf z6ttCo0jreHjt>=U^+pV>SgOpEdUY9i+ITVkI=0cm%e>3ya-_#d3x0xmR{Zs(ql17| zoD|WDrOL7suPZ>Gc-@LIkP@#-l>;$XifUIZRpv>&t^`jTFUH@x8OI1FP?|X<7Eckgh?B! z;ASN&UTxOZ{l_N1TB&-x|Nb4Q@3z~lSA#Q`=>4x9#*4;HHI-UJ`GvF@+*7>{v`i4j zL5vNDftx5{&OW{#wAsfugF(tUX$PLc&5q(}ff08ch&cjhZEJ4;Z@Z5fe<#~&*$%V* ze;3k4@)7%?N~mKEv(|Vw>FFR~CzB+AVvgJv;&>zY5XWtp+f&}N6slKrxCrSoU)qzK zz}Lo*@%OUL7KUalgn8juFn;>`P={mT{kWR@HE+gmK^SX}3v`(6<-HLfAYUB>tR+%J zT1c1MOPp^3590iIdYe=%=S$6kvz&7i1&+!G{}A}u_%i-sw$sAb=;*CTcj=lj&ojkV zuJdibkC2`Y0&X#q1kFv9m-GT=89a z^R3++4q_Xld|@m11TuINWO*2etH6%&c5kTWV@=H89bVaQHfrh|m+=|iV5KqQsrT&8 z(C?=H6xtEnD~OAPjRGS*R@_h?d}B9E=xhCMHBD**al1?7_Cerg_6wLsJ9HEhtvVXZ>@CB8| zbaB6+MLs0OQ5H{5!sZ^(r%v6He(yZ^z-*MElO}M}YAYcGRWyEVZ2_a94BLx53-SiSh5Sjlx{^U8E;4w$2Q|RoxO6-1kAuzDIgG2y>403YJ`FmO!iZ|NzsR2+T&l2@U<~y{6V(a!qBXD{}br~anXMw zc0VK?9R%zoQcCXv|Hf{YEI)C32t0_}Y}l!kXaBWadD!uuqDcZb?41VhVdvQ5AIIsB zz}v=-@t?5GSkwKOR|ML8o>~1A@hF$Twg+PsJLy^Yp4#_k8s0%r93D}L>iyF6M<3QS zNmszrAx|iyNpibp&i@(c62ot$_o;#xAw>1gNfWqfoqGiQY}^?C1=}Xr`d=d5A>6X{ zkFt&qf~|L}5fCR$mXUh(E6^q;bJDMWXbTeG?&@X;oRv*`418^D82=61X^ls|w~IRU zTcnFjfwQ^4EmDH&gm2E$zHog0j&yYp^hqRbEL)oP5Xawx2XXvVdb_6InaE|YqhLFV zcse>8$wcd^aZm^J(DPas{U9`3jQg>`ih z#%@A&H9d$;lH?|4Pl69IqZ6LiXLAlFieX&fqHWq!;A7*%_}|z@3!nLV-2NTu7EvV^ z_dox^@;XSEgmS3UV~d0=7u)|dXtMn;MEg^&4TBv!d-@I7sf|24S>UQ{*gwJ3#)9#G zv2E7aGxu^lgLHwRWxpDwLA}2~`DwSjeGE$CJSdP0^oARe&n7=HYXf~^HXoR!^u@5U zE!VMEoXt50HBv?rZtdV})~)c&Ed`7=pR2fB#EAs zA+>|}?FJsi?*!PXl;@>*|55zd#!Zy?(GS}l{A}D9pUrj(xb1;-mu?g@+@^;eJo8O$ zbI!FV>FFTg79&Z_+(b!!;l@$8JX$F<-Mc!3bb%{u))DY$cSn1qX9J9n z+k<@m5#zlfqm41+bBRf2cdwII1hXF!=Ee6z=AkT_>FtB-&tVU__pvX23xZqg3immk zaGhrSoKEvq4Qu~=f%@`kc>j2pwE{GK&bBVH(zRdHT1Ovcdsv!wfJ?A#VCXPyiM6}T zbdEW`!(~5>4~j_d=98MP3|734<-Vj2%?A(a(3ipEQt(Z&H$nf-uVr%$910CK8-BgF z7bpLOI_fC6iG8t(f>_j<1(3o=NdjNmJ{w#71C46M*Thn zve{TOekd^$us#gw0yotrV*O&)(;*$!5;dYNq^E2X@m>Tui1*o$1mkBeMqFkc%n$AAp6g(J%y!epbZZ)Tj@3@%n0rWRxGX)wL z)F2(Eqi?p9ar=)=hv^-jzZypeL9%Wi)6p-h{Gnpm-<%tE>!5!&HEPX#BghEO{7?sd zw6=l=5Zv=aj;1*o=&}-d+_qN0vI$ z7cG=({Lvm9qwT>l9&KUp-TS8co#|YHJlifZz6^h~i^uVbz;{RR-euA;a&b@bcoPq; zgj$P}wmE~O{o!|XPtdfOBb+BaDzZ5^$X{u zlOUIkJ>w@6Ctz>R?#wzV%!{v+UV=JYC!K=prFieTxgTqJspPeO*XuBorE&VnCQTU| ztW#R?3f>{iaapOg>aD^Hg@-YS?0OvVkvIpSMW?^$m-t;=L-#bl?BiatmW8tGwv4(} zJ}{Z#eP_X74dWr9kcTl4Htmgmqgg9&Rr}aRmcZ}?_uiihyyD$wpS7TFv9P`j*|>J> zQMwCMD?8TVL8c-;=c?9zOrPPcDUYC)ykU+ywjX?gKK7*!>3jk~n&+Tn9Q(^519kuT zkYoBj@hF=sd1z8bYW-gc*=+r1d=)XXd}6atyc+2eGxj&zMZdV8b#+MR7mE~$xRjBq zUBvt}$U)36ge=qdi}AD+-uzv6mt2%i&PpX8?ams=XXDQJONpI;`^%6nv-2j{HsZdP zb#+LGdjiGh*fwIn4zdt?AM)G^`KGtG5xgTWn=6+qc=8`^Pq_0Dwf<=ertX*ZklpSV z#y1dKVLk}+;`71FQHS%vMqID`|MNj>9-3@EF!O_Ue${7MQIAA(o2r1Es&FA>R8A+{W%0XJGoLLav-amIw3ukWVzveIqBMsvxa@|839W5%s{#g%7%)%*JzEb1vp?aUw zZty4HsOqvl+L%%+rmCwPCs%6eJ}+&7wY+jGEVYvcOf@ z*SCSEjSu5*XFCOa-huQu<=|WN#OFHJ(?P&Ts7iq1$&#$Z=X%g5KFgs$L+R`+rub?V z&#n1GQGkSWfveV`8^G7bi1Bx_tpY~xLb^a)$xDph&3ZZr7)e#tToiAIEH81o5j=>~ zN$H>c$~WtHt49US1+AZK|**kjyLeT?6HAq4B|f)&gA#XXC>7x7a>wUNdW>FfYC~`Znrt zZS);n=`Zl!^6%oeBZ%@Bf_*9q?I}$8eC7AZQwL!Vbjc7>Crxf6F?|5EiRppqG1b0Y zRM*@@fuqv3AAp~YDdP{aeS)t2C(>QIwyyn<^>h$)EmoDlxQUXS#N{E-CN4|U}~1YBZOgE1HtUXqizJPg{z(QJZek4jF0(C($YZ~ zUjjLWSgcu+{KV{0&?jaC=*yJP`c)e>XM9-+5+CC9Yw)pgV*D|-&C($=ul)w;5hlQc zveAbBmUVOx^e0kHjj3mmjTrn6G>O6IVF*)x*GGMnp0A(r3)u$V^ce*tF;_rG+4JCD z#2&PZSp7HTv9V(Ok8C$|>JPjk7~3A^#clhaP?om+&$#j#INJ8d@jFpG_z&j(F0LB1IRwraqh9onwdI~&hx+-yxN;3n{ro3>yK)du>ZN^7#&%LK|3$t!2=*~X%EGqQ zc&VMl^%>A6uEXhZEfx#0H)%R)0ykv?GM#OBP{GEP@eKZKTzi2N?_X#~x_g=NPMx0uEpy%cP(DCaGI>voUwB4mQ|}4J_i!ZH?LjSzj7c2r8Dsw0&H1yy{y=%4=m{! z(C>i3&+eY?CCiqccp}>0%-0$VVZZ;X+dPS65qf8=-rRrIrd2N+IJSFP_mURv=ICT? zi%>|C2(N~$`Gx09CY2<(C)(?n50&#~L;v=`-%{YPC$5vDwxd`EY+Z{tZ|GWlmN!ph zXA}j_73|Wp>+ZlBYxii|Hd4@K(ZwQa} zb@%jK)8<_qq;wZB4jVYnM1cG3wYMG3pOMgA@CTd2hiqaZv2Jg>?Z8L@M0A-AOs8#c zZ~Mjf`P&ZNgY~+J6O;Bf{tp9bGniCfGlsI_jt@SeRzaoXA3_K2Jomh{`1^NZ`G0zq BM %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 -types %t1/a.obj | FileCheck %s -check-prefix PDB-PRECOMP +RUN: llvm-pdbutil dump -types %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: 0x1000 +PRECOMP-NEXT: Count: 0x407 +PRECOMP-NEXT: Signature: 0x1116980E + +PDB-PRECOMP: Types (.debug$T) +PDB-PRECOMP-NEXT: ============================================================ +PDB-PRECOMP-NEXT: Showing 0 records +PDB-PRECOMP-NEXT: 0x1000 | LF_PRECOMP [size = 60] start index = 0x1000, types count = 0x407, signature = 0x1116980E, precomp path = f:\svn\lld\test\coff\precomp\precomp.obj + +PDB-ENDPRECOMP: Precompiled Types (.debug$P) +PDB-ENDPRECOMP-NEXT: ============================================================ +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; +# } +# +# // cl.exe a.cpp /Z7 /Yuprecomp.h /c +# +# // obj2yaml precomp.obj >precomp-precomp.yaml +# // obj2yaml a.obj >precomp-a.yaml diff --git a/llvm/tools/llvm-pdbutil/InputFile.cpp b/llvm/tools/llvm-pdbutil/InputFile.cpp index 3695cbfc4..7b5af7e 100644 --- a/llvm/tools/llvm-pdbutil/InputFile.cpp +++ b/llvm/tools/llvm-pdbutil/InputFile.cpp @@ -95,7 +95,8 @@ static inline bool isDebugSSection(object::SectionRef Section, 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; diff --git a/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp b/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp index fae8992..3425c58 100644 --- a/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp +++ b/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp @@ -1,541 +1,556 @@ -//===- MinimalTypeDumper.cpp ---------------------------------- *- C++ --*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "MinimalTypeDumper.h" - -#include "FormatUtil.h" -#include "LinePrinter.h" - -#include "llvm/DebugInfo/CodeView/CVRecord.h" -#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" -#include "llvm/DebugInfo/CodeView/CodeView.h" -#include "llvm/DebugInfo/CodeView/Formatters.h" -#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" -#include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/DebugInfo/PDB/Native/TpiHashing.h" -#include "llvm/Support/FormatVariadic.h" -#include "llvm/Support/MathExtras.h" - -using namespace llvm; -using namespace llvm::codeview; -using namespace llvm::pdb; - -static std::string formatClassOptions(uint32_t IndentLevel, - ClassOptions Options) { - std::vector Opts; - PUSH_FLAG(ClassOptions, HasConstructorOrDestructor, Options, - "has ctor / dtor"); - PUSH_FLAG(ClassOptions, ContainsNestedClass, Options, - "contains nested class"); - PUSH_FLAG(ClassOptions, HasConversionOperator, Options, - "conversion operator"); - PUSH_FLAG(ClassOptions, ForwardReference, Options, "forward ref"); - PUSH_FLAG(ClassOptions, HasUniqueName, Options, "has unique name"); - PUSH_FLAG(ClassOptions, Intrinsic, Options, "intrin"); - PUSH_FLAG(ClassOptions, Nested, Options, "is nested"); - PUSH_FLAG(ClassOptions, HasOverloadedOperator, Options, - "overloaded operator"); - PUSH_FLAG(ClassOptions, HasOverloadedAssignmentOperator, Options, - "overloaded operator="); - PUSH_FLAG(ClassOptions, Packed, Options, "packed"); - PUSH_FLAG(ClassOptions, Scoped, Options, "scoped"); - PUSH_FLAG(ClassOptions, Sealed, Options, "sealed"); - - return typesetItemList(Opts, 4, IndentLevel, " | "); -} - -static std::string pointerOptions(PointerOptions Options) { - std::vector Opts; - PUSH_FLAG(PointerOptions, Flat32, Options, "flat32"); - PUSH_FLAG(PointerOptions, Volatile, Options, "volatile"); - PUSH_FLAG(PointerOptions, Const, Options, "const"); - PUSH_FLAG(PointerOptions, Unaligned, Options, "unaligned"); - PUSH_FLAG(PointerOptions, Restrict, Options, "restrict"); - PUSH_FLAG(PointerOptions, WinRTSmartPointer, Options, "winrt"); - if (Opts.empty()) - return "None"; - return join(Opts, " | "); -} - -static std::string modifierOptions(ModifierOptions Options) { - std::vector Opts; - PUSH_FLAG(ModifierOptions, Const, Options, "const"); - PUSH_FLAG(ModifierOptions, Volatile, Options, "volatile"); - PUSH_FLAG(ModifierOptions, Unaligned, Options, "unaligned"); - if (Opts.empty()) - return "None"; - return join(Opts, " | "); -} - -static std::string formatCallingConvention(CallingConvention Convention) { - switch (Convention) { - RETURN_CASE(CallingConvention, AlphaCall, "alphacall"); - RETURN_CASE(CallingConvention, AM33Call, "am33call"); - RETURN_CASE(CallingConvention, ArmCall, "armcall"); - RETURN_CASE(CallingConvention, ClrCall, "clrcall"); - RETURN_CASE(CallingConvention, FarC, "far cdecl"); - RETURN_CASE(CallingConvention, FarFast, "far fastcall"); - RETURN_CASE(CallingConvention, FarPascal, "far pascal"); - RETURN_CASE(CallingConvention, FarStdCall, "far stdcall"); - RETURN_CASE(CallingConvention, FarSysCall, "far syscall"); - RETURN_CASE(CallingConvention, Generic, "generic"); - RETURN_CASE(CallingConvention, Inline, "inline"); - RETURN_CASE(CallingConvention, M32RCall, "m32rcall"); - RETURN_CASE(CallingConvention, MipsCall, "mipscall"); - RETURN_CASE(CallingConvention, NearC, "cdecl"); - RETURN_CASE(CallingConvention, NearFast, "fastcall"); - RETURN_CASE(CallingConvention, NearPascal, "pascal"); - RETURN_CASE(CallingConvention, NearStdCall, "stdcall"); - RETURN_CASE(CallingConvention, NearSysCall, "near syscall"); - RETURN_CASE(CallingConvention, NearVector, "vectorcall"); - RETURN_CASE(CallingConvention, PpcCall, "ppccall"); - RETURN_CASE(CallingConvention, SHCall, "shcall"); - RETURN_CASE(CallingConvention, SH5Call, "sh5call"); - RETURN_CASE(CallingConvention, ThisCall, "thiscall"); - RETURN_CASE(CallingConvention, TriCall, "tricall"); - } - return formatUnknownEnum(Convention); -} - -static std::string formatPointerMode(PointerMode Mode) { - switch (Mode) { - RETURN_CASE(PointerMode, LValueReference, "ref"); - RETURN_CASE(PointerMode, Pointer, "pointer"); - RETURN_CASE(PointerMode, PointerToDataMember, "data member pointer"); - RETURN_CASE(PointerMode, PointerToMemberFunction, "member fn pointer"); - RETURN_CASE(PointerMode, RValueReference, "rvalue ref"); - } - return formatUnknownEnum(Mode); -} - -static std::string memberAccess(MemberAccess Access) { - switch (Access) { - RETURN_CASE(MemberAccess, None, ""); - RETURN_CASE(MemberAccess, Private, "private"); - RETURN_CASE(MemberAccess, Protected, "protected"); - RETURN_CASE(MemberAccess, Public, "public"); - } - return formatUnknownEnum(Access); -} - -static std::string methodKind(MethodKind Kind) { - switch (Kind) { - RETURN_CASE(MethodKind, Vanilla, ""); - RETURN_CASE(MethodKind, Virtual, "virtual"); - RETURN_CASE(MethodKind, Static, "static"); - RETURN_CASE(MethodKind, Friend, "friend"); - RETURN_CASE(MethodKind, IntroducingVirtual, "intro virtual"); - RETURN_CASE(MethodKind, PureVirtual, "pure virtual"); - RETURN_CASE(MethodKind, PureIntroducingVirtual, "pure intro virtual"); - } - return formatUnknownEnum(Kind); -} - -static std::string pointerKind(PointerKind Kind) { - switch (Kind) { - RETURN_CASE(PointerKind, Near16, "ptr16"); - RETURN_CASE(PointerKind, Far16, "far ptr16"); - RETURN_CASE(PointerKind, Huge16, "huge ptr16"); - RETURN_CASE(PointerKind, BasedOnSegment, "segment based"); - RETURN_CASE(PointerKind, BasedOnValue, "value based"); - RETURN_CASE(PointerKind, BasedOnSegmentValue, "segment value based"); - RETURN_CASE(PointerKind, BasedOnAddress, "address based"); - RETURN_CASE(PointerKind, BasedOnSegmentAddress, "segment address based"); - RETURN_CASE(PointerKind, BasedOnType, "type based"); - RETURN_CASE(PointerKind, BasedOnSelf, "self based"); - RETURN_CASE(PointerKind, Near32, "ptr32"); - RETURN_CASE(PointerKind, Far32, "far ptr32"); - RETURN_CASE(PointerKind, Near64, "ptr64"); - } - return formatUnknownEnum(Kind); -} - -static std::string memberAttributes(const MemberAttributes &Attrs) { - std::vector Opts; - std::string Access = memberAccess(Attrs.getAccess()); - std::string Kind = methodKind(Attrs.getMethodKind()); - if (!Access.empty()) - Opts.push_back(Access); - if (!Kind.empty()) - Opts.push_back(Kind); - MethodOptions Flags = Attrs.getFlags(); - PUSH_FLAG(MethodOptions, Pseudo, Flags, "pseudo"); - PUSH_FLAG(MethodOptions, NoInherit, Flags, "noinherit"); - PUSH_FLAG(MethodOptions, NoConstruct, Flags, "noconstruct"); - PUSH_FLAG(MethodOptions, CompilerGenerated, Flags, "compiler-generated"); - PUSH_FLAG(MethodOptions, Sealed, Flags, "sealed"); - return join(Opts, " "); -} - -static std::string formatPointerAttrs(const PointerRecord &Record) { - PointerMode Mode = Record.getMode(); - PointerOptions Opts = Record.getOptions(); - PointerKind Kind = Record.getPointerKind(); - return formatv("mode = {0}, opts = {1}, kind = {2}", formatPointerMode(Mode), - pointerOptions(Opts), pointerKind(Kind)); -} - -static std::string formatFunctionOptions(FunctionOptions Options) { - std::vector Opts; - - PUSH_FLAG(FunctionOptions, CxxReturnUdt, Options, "returns cxx udt"); - PUSH_FLAG(FunctionOptions, ConstructorWithVirtualBases, Options, - "constructor with virtual bases"); - PUSH_FLAG(FunctionOptions, Constructor, Options, "constructor"); - if (Opts.empty()) - return "None"; - return join(Opts, " | "); -} - -Error MinimalTypeDumpVisitor::visitTypeBegin(CVType &Record, TypeIndex Index) { - // formatLine puts the newline at the beginning, so we use formatLine here - // to start a new line, and then individual visit methods use format to - // append to the existing line. - if (!Hashes) { - P.formatLine("{0} | {1} [size = {2}]", - fmt_align(Index, AlignStyle::Right, Width), - formatTypeLeafKind(Record.Type), Record.length()); - } else { - std::string H; - if (Index.toArrayIndex() >= HashValues.size()) { - H = "(not present)"; - } else { - uint32_t Hash = HashValues[Index.toArrayIndex()]; - Expected MaybeHash = hashTypeRecord(Record); - if (!MaybeHash) - return MaybeHash.takeError(); - uint32_t OurHash = *MaybeHash; - OurHash %= NumHashBuckets; - if (Hash == OurHash) - H = "0x" + utohexstr(Hash); - else - H = "0x" + utohexstr(Hash) + ", our hash = 0x" + utohexstr(OurHash); - } - P.formatLine("{0} | {1} [size = {2}, hash = {3}]", - fmt_align(Index, AlignStyle::Right, Width), - formatTypeLeafKind(Record.Type), Record.length(), H); - } - P.Indent(Width + 3); - return Error::success(); -} -Error MinimalTypeDumpVisitor::visitTypeEnd(CVType &Record) { - P.Unindent(Width + 3); - if (RecordBytes) { - AutoIndent Indent(P, 9); - P.formatBinary("Bytes", Record.RecordData, 0); - } - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitMemberBegin(CVMemberRecord &Record) { - P.formatLine("- {0}", formatTypeLeafKind(Record.Kind)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitMemberEnd(CVMemberRecord &Record) { - if (RecordBytes) { - AutoIndent Indent(P, 2); - P.formatBinary("Bytes", Record.Data, 0); - } - return Error::success(); -} - -StringRef MinimalTypeDumpVisitor::getTypeName(TypeIndex TI) const { - if (TI.isNoneType()) - return ""; - return Types.getTypeName(TI); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - FieldListRecord &FieldList) { - if (auto EC = codeview::visitMemberRecordStream(FieldList.Data, *this)) - return EC; - - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - StringIdRecord &String) { - P.format(" ID: {0}, String: {1}", String.getId(), String.getString()); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - ArgListRecord &Args) { - auto Indices = Args.getIndices(); - if (Indices.empty()) - return Error::success(); - - auto Max = std::max_element(Indices.begin(), Indices.end()); - uint32_t W = NumDigits(Max->getIndex()) + 2; - - for (auto I : Indices) - P.formatLine("{0}: `{1}`", fmt_align(I, AlignStyle::Right, W), - getTypeName(I)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - StringListRecord &Strings) { - auto Indices = Strings.getIndices(); - if (Indices.empty()) - return Error::success(); - - auto Max = std::max_element(Indices.begin(), Indices.end()); - uint32_t W = NumDigits(Max->getIndex()) + 2; - - for (auto I : Indices) - P.formatLine("{0}: `{1}`", fmt_align(I, AlignStyle::Right, W), - getTypeName(I)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - ClassRecord &Class) { - P.format(" `{0}`", Class.Name); - if (Class.hasUniqueName()) - P.formatLine("unique name: `{0}`", Class.UniqueName); - P.formatLine("vtable: {0}, base list: {1}, field list: {2}", - Class.VTableShape, Class.DerivationList, Class.FieldList); - P.formatLine("options: {0}", - formatClassOptions(P.getIndentLevel(), Class.Options)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - UnionRecord &Union) { - P.format(" `{0}`", Union.Name); - if (Union.hasUniqueName()) - P.formatLine("unique name: `{0}`", Union.UniqueName); - P.formatLine("field list: {0}", Union.FieldList); - P.formatLine("options: {0}", - formatClassOptions(P.getIndentLevel(), Union.Options)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, EnumRecord &Enum) { - P.format(" `{0}`", Enum.Name); - if (Enum.hasUniqueName()) - P.formatLine("unique name: `{0}`", Enum.UniqueName); - P.formatLine("field list: {0}, underlying type: {1}", Enum.FieldList, - Enum.UnderlyingType); - P.formatLine("options: {0}", - formatClassOptions(P.getIndentLevel(), Enum.Options)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, ArrayRecord &AT) { - if (AT.Name.empty()) { - P.formatLine("size: {0}, index type: {1}, element type: {2}", AT.Size, - AT.IndexType, AT.ElementType); - } else { - P.formatLine("name: {0}, size: {1}, index type: {2}, element type: {3}", - AT.Name, AT.Size, AT.IndexType, AT.ElementType); - } - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - VFTableRecord &VFT) { - P.formatLine("offset: {0}, complete class: {1}, overridden vftable: {2}", - VFT.VFPtrOffset, VFT.CompleteClass, VFT.OverriddenVFTable); - P.formatLine("method names: "); - if (!VFT.MethodNames.empty()) { - std::string Sep = - formatv("\n{0}", - fmt_repeat(' ', P.getIndentLevel() + strlen("method names: "))) - .str(); - P.print(join(VFT.MethodNames, Sep)); - } - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - MemberFuncIdRecord &Id) { - P.formatLine("name = {0}, type = {1}, class type = {2}", Id.Name, - Id.FunctionType, Id.ClassType); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - ProcedureRecord &Proc) { - P.formatLine("return type = {0}, # args = {1}, param list = {2}", - Proc.ReturnType, Proc.ParameterCount, Proc.ArgumentList); - P.formatLine("calling conv = {0}, options = {1}", - formatCallingConvention(Proc.CallConv), - formatFunctionOptions(Proc.Options)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - MemberFunctionRecord &MF) { - P.formatLine("return type = {0}, # args = {1}, param list = {2}", - MF.ReturnType, MF.ParameterCount, MF.ArgumentList); - P.formatLine("class type = {0}, this type = {1}, this adjust = {2}", - MF.ClassType, MF.ThisType, MF.ThisPointerAdjustment); - P.formatLine("calling conv = {0}, options = {1}", - formatCallingConvention(MF.CallConv), - formatFunctionOptions(MF.Options)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - FuncIdRecord &Func) { - P.formatLine("name = {0}, type = {1}, parent scope = {2}", Func.Name, - Func.FunctionType, Func.ParentScope); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - TypeServer2Record &TS) { - P.formatLine("name = {0}, age = {1}, guid = {2}", TS.Name, TS.Age, TS.Guid); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - PointerRecord &Ptr) { - P.formatLine("referent = {0}, {1}", Ptr.ReferentType, - formatPointerAttrs(Ptr)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - ModifierRecord &Mod) { - P.formatLine("referent = {0}, modifiers = {1}", Mod.ModifiedType, - modifierOptions(Mod.Modifiers)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - VFTableShapeRecord &Shape) { - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - UdtModSourceLineRecord &U) { - P.formatLine("udt = {0}, mod = {1}, file = {2}, line = {3}", U.UDT, U.Module, - U.SourceFile.getIndex(), U.LineNumber); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - UdtSourceLineRecord &U) { - P.formatLine("udt = {0}, file = {1}, line = {2}", U.UDT, - U.SourceFile.getIndex(), U.LineNumber); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - BitFieldRecord &BF) { - P.formatLine("type = {0}, bit offset = {1}, # bits = {2}", BF.Type, - BF.BitOffset, BF.BitSize); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord( - CVType &CVR, MethodOverloadListRecord &Overloads) { - for (auto &M : Overloads.Methods) - P.formatLine("- Method [type = {0}, vftable offset = {1}, attrs = {2}]", - M.Type, M.VFTableOffset, memberAttributes(M.Attrs)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, - BuildInfoRecord &BI) { - auto Indices = BI.ArgIndices; - if (Indices.empty()) - return Error::success(); - - auto Max = std::max_element(Indices.begin(), Indices.end()); - uint32_t W = NumDigits(Max->getIndex()) + 2; - - for (auto I : Indices) - P.formatLine("{0}: `{1}`", fmt_align(I, AlignStyle::Right, W), - getTypeName(I)); - return Error::success(); -} - -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::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); - P.formatLine("type = {0}, vftable offset = {1}, attrs = {2}", Method.Type, - Method.VFTableOffset, memberAttributes(Method.Attrs)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - OverloadedMethodRecord &Method) { - P.format(" [name = `{0}`, # overloads = {1}, overload list = {2}]", - Method.Name, Method.NumOverloads, Method.MethodList); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - DataMemberRecord &Field) { - P.format(" [name = `{0}`, Type = {1}, offset = {2}, attrs = {3}]", Field.Name, - Field.Type, Field.FieldOffset, memberAttributes(Field.Attrs)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - StaticDataMemberRecord &Field) { - P.format(" [name = `{0}`, type = {1}, attrs = {2}]", Field.Name, Field.Type, - memberAttributes(Field.Attrs)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - EnumeratorRecord &Enum) { - P.format(" [{0} = {1}]", Enum.Name, - Enum.Value.toString(10, Enum.Value.isSigned())); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - BaseClassRecord &Base) { - AutoIndent Indent(P); - P.formatLine("type = {0}, offset = {1}, attrs = {2}", Base.Type, Base.Offset, - memberAttributes(Base.Attrs)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - VirtualBaseClassRecord &Base) { - AutoIndent Indent(P); - P.formatLine( - "base = {0}, vbptr = {1}, vbptr offset = {2}, vtable index = {3}", - Base.BaseType, Base.VBPtrType, Base.VBPtrOffset, Base.VTableIndex); - P.formatLine("attrs = {0}", memberAttributes(Base.Attrs)); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - ListContinuationRecord &Cont) { - P.format(" continuation = {0}", Cont.ContinuationIndex); - return Error::success(); -} - -Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, - VFPtrRecord &VFP) { - P.format(" type = {0}", VFP.Type); - return Error::success(); -} +//===- MinimalTypeDumper.cpp ---------------------------------- *- C++ --*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "MinimalTypeDumper.h" + +#include "FormatUtil.h" +#include "LinePrinter.h" + +#include "llvm/DebugInfo/CodeView/CVRecord.h" +#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/Formatters.h" +#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" +#include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/TpiHashing.h" +#include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/MathExtras.h" + +using namespace llvm; +using namespace llvm::codeview; +using namespace llvm::pdb; + +static std::string formatClassOptions(uint32_t IndentLevel, + ClassOptions Options) { + std::vector Opts; + PUSH_FLAG(ClassOptions, HasConstructorOrDestructor, Options, + "has ctor / dtor"); + PUSH_FLAG(ClassOptions, ContainsNestedClass, Options, + "contains nested class"); + PUSH_FLAG(ClassOptions, HasConversionOperator, Options, + "conversion operator"); + PUSH_FLAG(ClassOptions, ForwardReference, Options, "forward ref"); + PUSH_FLAG(ClassOptions, HasUniqueName, Options, "has unique name"); + PUSH_FLAG(ClassOptions, Intrinsic, Options, "intrin"); + PUSH_FLAG(ClassOptions, Nested, Options, "is nested"); + PUSH_FLAG(ClassOptions, HasOverloadedOperator, Options, + "overloaded operator"); + PUSH_FLAG(ClassOptions, HasOverloadedAssignmentOperator, Options, + "overloaded operator="); + PUSH_FLAG(ClassOptions, Packed, Options, "packed"); + PUSH_FLAG(ClassOptions, Scoped, Options, "scoped"); + PUSH_FLAG(ClassOptions, Sealed, Options, "sealed"); + + return typesetItemList(Opts, 4, IndentLevel, " | "); +} + +static std::string pointerOptions(PointerOptions Options) { + std::vector Opts; + PUSH_FLAG(PointerOptions, Flat32, Options, "flat32"); + PUSH_FLAG(PointerOptions, Volatile, Options, "volatile"); + PUSH_FLAG(PointerOptions, Const, Options, "const"); + PUSH_FLAG(PointerOptions, Unaligned, Options, "unaligned"); + PUSH_FLAG(PointerOptions, Restrict, Options, "restrict"); + PUSH_FLAG(PointerOptions, WinRTSmartPointer, Options, "winrt"); + if (Opts.empty()) + return "None"; + return join(Opts, " | "); +} + +static std::string modifierOptions(ModifierOptions Options) { + std::vector Opts; + PUSH_FLAG(ModifierOptions, Const, Options, "const"); + PUSH_FLAG(ModifierOptions, Volatile, Options, "volatile"); + PUSH_FLAG(ModifierOptions, Unaligned, Options, "unaligned"); + if (Opts.empty()) + return "None"; + return join(Opts, " | "); +} + +static std::string formatCallingConvention(CallingConvention Convention) { + switch (Convention) { + RETURN_CASE(CallingConvention, AlphaCall, "alphacall"); + RETURN_CASE(CallingConvention, AM33Call, "am33call"); + RETURN_CASE(CallingConvention, ArmCall, "armcall"); + RETURN_CASE(CallingConvention, ClrCall, "clrcall"); + RETURN_CASE(CallingConvention, FarC, "far cdecl"); + RETURN_CASE(CallingConvention, FarFast, "far fastcall"); + RETURN_CASE(CallingConvention, FarPascal, "far pascal"); + RETURN_CASE(CallingConvention, FarStdCall, "far stdcall"); + RETURN_CASE(CallingConvention, FarSysCall, "far syscall"); + RETURN_CASE(CallingConvention, Generic, "generic"); + RETURN_CASE(CallingConvention, Inline, "inline"); + RETURN_CASE(CallingConvention, M32RCall, "m32rcall"); + RETURN_CASE(CallingConvention, MipsCall, "mipscall"); + RETURN_CASE(CallingConvention, NearC, "cdecl"); + RETURN_CASE(CallingConvention, NearFast, "fastcall"); + RETURN_CASE(CallingConvention, NearPascal, "pascal"); + RETURN_CASE(CallingConvention, NearStdCall, "stdcall"); + RETURN_CASE(CallingConvention, NearSysCall, "near syscall"); + RETURN_CASE(CallingConvention, NearVector, "vectorcall"); + RETURN_CASE(CallingConvention, PpcCall, "ppccall"); + RETURN_CASE(CallingConvention, SHCall, "shcall"); + RETURN_CASE(CallingConvention, SH5Call, "sh5call"); + RETURN_CASE(CallingConvention, ThisCall, "thiscall"); + RETURN_CASE(CallingConvention, TriCall, "tricall"); + } + return formatUnknownEnum(Convention); +} + +static std::string formatPointerMode(PointerMode Mode) { + switch (Mode) { + RETURN_CASE(PointerMode, LValueReference, "ref"); + RETURN_CASE(PointerMode, Pointer, "pointer"); + RETURN_CASE(PointerMode, PointerToDataMember, "data member pointer"); + RETURN_CASE(PointerMode, PointerToMemberFunction, "member fn pointer"); + RETURN_CASE(PointerMode, RValueReference, "rvalue ref"); + } + return formatUnknownEnum(Mode); +} + +static std::string memberAccess(MemberAccess Access) { + switch (Access) { + RETURN_CASE(MemberAccess, None, ""); + RETURN_CASE(MemberAccess, Private, "private"); + RETURN_CASE(MemberAccess, Protected, "protected"); + RETURN_CASE(MemberAccess, Public, "public"); + } + return formatUnknownEnum(Access); +} + +static std::string methodKind(MethodKind Kind) { + switch (Kind) { + RETURN_CASE(MethodKind, Vanilla, ""); + RETURN_CASE(MethodKind, Virtual, "virtual"); + RETURN_CASE(MethodKind, Static, "static"); + RETURN_CASE(MethodKind, Friend, "friend"); + RETURN_CASE(MethodKind, IntroducingVirtual, "intro virtual"); + RETURN_CASE(MethodKind, PureVirtual, "pure virtual"); + RETURN_CASE(MethodKind, PureIntroducingVirtual, "pure intro virtual"); + } + return formatUnknownEnum(Kind); +} + +static std::string pointerKind(PointerKind Kind) { + switch (Kind) { + RETURN_CASE(PointerKind, Near16, "ptr16"); + RETURN_CASE(PointerKind, Far16, "far ptr16"); + RETURN_CASE(PointerKind, Huge16, "huge ptr16"); + RETURN_CASE(PointerKind, BasedOnSegment, "segment based"); + RETURN_CASE(PointerKind, BasedOnValue, "value based"); + RETURN_CASE(PointerKind, BasedOnSegmentValue, "segment value based"); + RETURN_CASE(PointerKind, BasedOnAddress, "address based"); + RETURN_CASE(PointerKind, BasedOnSegmentAddress, "segment address based"); + RETURN_CASE(PointerKind, BasedOnType, "type based"); + RETURN_CASE(PointerKind, BasedOnSelf, "self based"); + RETURN_CASE(PointerKind, Near32, "ptr32"); + RETURN_CASE(PointerKind, Far32, "far ptr32"); + RETURN_CASE(PointerKind, Near64, "ptr64"); + } + return formatUnknownEnum(Kind); +} + +static std::string memberAttributes(const MemberAttributes &Attrs) { + std::vector Opts; + std::string Access = memberAccess(Attrs.getAccess()); + std::string Kind = methodKind(Attrs.getMethodKind()); + if (!Access.empty()) + Opts.push_back(Access); + if (!Kind.empty()) + Opts.push_back(Kind); + MethodOptions Flags = Attrs.getFlags(); + PUSH_FLAG(MethodOptions, Pseudo, Flags, "pseudo"); + PUSH_FLAG(MethodOptions, NoInherit, Flags, "noinherit"); + PUSH_FLAG(MethodOptions, NoConstruct, Flags, "noconstruct"); + PUSH_FLAG(MethodOptions, CompilerGenerated, Flags, "compiler-generated"); + PUSH_FLAG(MethodOptions, Sealed, Flags, "sealed"); + return join(Opts, " "); +} + +static std::string formatPointerAttrs(const PointerRecord &Record) { + PointerMode Mode = Record.getMode(); + PointerOptions Opts = Record.getOptions(); + PointerKind Kind = Record.getPointerKind(); + return formatv("mode = {0}, opts = {1}, kind = {2}", formatPointerMode(Mode), + pointerOptions(Opts), pointerKind(Kind)); +} + +static std::string formatFunctionOptions(FunctionOptions Options) { + std::vector Opts; + + PUSH_FLAG(FunctionOptions, CxxReturnUdt, Options, "returns cxx udt"); + PUSH_FLAG(FunctionOptions, ConstructorWithVirtualBases, Options, + "constructor with virtual bases"); + PUSH_FLAG(FunctionOptions, Constructor, Options, "constructor"); + if (Opts.empty()) + return "None"; + return join(Opts, " | "); +} + +Error MinimalTypeDumpVisitor::visitTypeBegin(CVType &Record, TypeIndex Index) { + // formatLine puts the newline at the beginning, so we use formatLine here + // to start a new line, and then individual visit methods use format to + // append to the existing line. + if (!Hashes) { + P.formatLine("{0} | {1} [size = {2}]", + fmt_align(Index, AlignStyle::Right, Width), + formatTypeLeafKind(Record.Type), Record.length()); + } else { + std::string H; + if (Index.toArrayIndex() >= HashValues.size()) { + H = "(not present)"; + } else { + uint32_t Hash = HashValues[Index.toArrayIndex()]; + Expected MaybeHash = hashTypeRecord(Record); + if (!MaybeHash) + return MaybeHash.takeError(); + uint32_t OurHash = *MaybeHash; + OurHash %= NumHashBuckets; + if (Hash == OurHash) + H = "0x" + utohexstr(Hash); + else + H = "0x" + utohexstr(Hash) + ", our hash = 0x" + utohexstr(OurHash); + } + P.formatLine("{0} | {1} [size = {2}, hash = {3}]", + fmt_align(Index, AlignStyle::Right, Width), + formatTypeLeafKind(Record.Type), Record.length(), H); + } + P.Indent(Width + 3); + return Error::success(); +} +Error MinimalTypeDumpVisitor::visitTypeEnd(CVType &Record) { + P.Unindent(Width + 3); + if (RecordBytes) { + AutoIndent Indent(P, 9); + P.formatBinary("Bytes", Record.RecordData, 0); + } + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitMemberBegin(CVMemberRecord &Record) { + P.formatLine("- {0}", formatTypeLeafKind(Record.Kind)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitMemberEnd(CVMemberRecord &Record) { + if (RecordBytes) { + AutoIndent Indent(P, 2); + P.formatBinary("Bytes", Record.Data, 0); + } + return Error::success(); +} + +StringRef MinimalTypeDumpVisitor::getTypeName(TypeIndex TI) const { + if (TI.isNoneType()) + return ""; + return Types.getTypeName(TI); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + FieldListRecord &FieldList) { + if (auto EC = codeview::visitMemberRecordStream(FieldList.Data, *this)) + return EC; + + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + StringIdRecord &String) { + P.format(" ID: {0}, String: {1}", String.getId(), String.getString()); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + ArgListRecord &Args) { + auto Indices = Args.getIndices(); + if (Indices.empty()) + return Error::success(); + + auto Max = std::max_element(Indices.begin(), Indices.end()); + uint32_t W = NumDigits(Max->getIndex()) + 2; + + for (auto I : Indices) + P.formatLine("{0}: `{1}`", fmt_align(I, AlignStyle::Right, W), + getTypeName(I)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + StringListRecord &Strings) { + auto Indices = Strings.getIndices(); + if (Indices.empty()) + return Error::success(); + + auto Max = std::max_element(Indices.begin(), Indices.end()); + uint32_t W = NumDigits(Max->getIndex()) + 2; + + for (auto I : Indices) + P.formatLine("{0}: `{1}`", fmt_align(I, AlignStyle::Right, W), + getTypeName(I)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + ClassRecord &Class) { + P.format(" `{0}`", Class.Name); + if (Class.hasUniqueName()) + P.formatLine("unique name: `{0}`", Class.UniqueName); + P.formatLine("vtable: {0}, base list: {1}, field list: {2}", + Class.VTableShape, Class.DerivationList, Class.FieldList); + P.formatLine("options: {0}", + formatClassOptions(P.getIndentLevel(), Class.Options)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + UnionRecord &Union) { + P.format(" `{0}`", Union.Name); + if (Union.hasUniqueName()) + P.formatLine("unique name: `{0}`", Union.UniqueName); + P.formatLine("field list: {0}", Union.FieldList); + P.formatLine("options: {0}", + formatClassOptions(P.getIndentLevel(), Union.Options)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, EnumRecord &Enum) { + P.format(" `{0}`", Enum.Name); + if (Enum.hasUniqueName()) + P.formatLine("unique name: `{0}`", Enum.UniqueName); + P.formatLine("field list: {0}, underlying type: {1}", Enum.FieldList, + Enum.UnderlyingType); + P.formatLine("options: {0}", + formatClassOptions(P.getIndentLevel(), Enum.Options)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, ArrayRecord &AT) { + if (AT.Name.empty()) { + P.formatLine("size: {0}, index type: {1}, element type: {2}", AT.Size, + AT.IndexType, AT.ElementType); + } else { + P.formatLine("name: {0}, size: {1}, index type: {2}, element type: {3}", + AT.Name, AT.Size, AT.IndexType, AT.ElementType); + } + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + VFTableRecord &VFT) { + P.formatLine("offset: {0}, complete class: {1}, overridden vftable: {2}", + VFT.VFPtrOffset, VFT.CompleteClass, VFT.OverriddenVFTable); + P.formatLine("method names: "); + if (!VFT.MethodNames.empty()) { + std::string Sep = + formatv("\n{0}", + fmt_repeat(' ', P.getIndentLevel() + strlen("method names: "))) + .str(); + P.print(join(VFT.MethodNames, Sep)); + } + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + MemberFuncIdRecord &Id) { + P.formatLine("name = {0}, type = {1}, class type = {2}", Id.Name, + Id.FunctionType, Id.ClassType); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + ProcedureRecord &Proc) { + P.formatLine("return type = {0}, # args = {1}, param list = {2}", + Proc.ReturnType, Proc.ParameterCount, Proc.ArgumentList); + P.formatLine("calling conv = {0}, options = {1}", + formatCallingConvention(Proc.CallConv), + formatFunctionOptions(Proc.Options)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + MemberFunctionRecord &MF) { + P.formatLine("return type = {0}, # args = {1}, param list = {2}", + MF.ReturnType, MF.ParameterCount, MF.ArgumentList); + P.formatLine("class type = {0}, this type = {1}, this adjust = {2}", + MF.ClassType, MF.ThisType, MF.ThisPointerAdjustment); + P.formatLine("calling conv = {0}, options = {1}", + formatCallingConvention(MF.CallConv), + formatFunctionOptions(MF.Options)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + FuncIdRecord &Func) { + P.formatLine("name = {0}, type = {1}, parent scope = {2}", Func.Name, + Func.FunctionType, Func.ParentScope); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + TypeServer2Record &TS) { + P.formatLine("name = {0}, age = {1}, guid = {2}", TS.Name, TS.Age, TS.Guid); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + PointerRecord &Ptr) { + P.formatLine("referent = {0}, {1}", Ptr.ReferentType, + formatPointerAttrs(Ptr)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + ModifierRecord &Mod) { + P.formatLine("referent = {0}, modifiers = {1}", Mod.ModifiedType, + modifierOptions(Mod.Modifiers)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + VFTableShapeRecord &Shape) { + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + UdtModSourceLineRecord &U) { + P.formatLine("udt = {0}, mod = {1}, file = {2}, line = {3}", U.UDT, U.Module, + U.SourceFile.getIndex(), U.LineNumber); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + UdtSourceLineRecord &U) { + P.formatLine("udt = {0}, file = {1}, line = {2}", U.UDT, + U.SourceFile.getIndex(), U.LineNumber); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + BitFieldRecord &BF) { + P.formatLine("type = {0}, bit offset = {1}, # bits = {2}", BF.Type, + BF.BitOffset, BF.BitSize); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord( + CVType &CVR, MethodOverloadListRecord &Overloads) { + for (auto &M : Overloads.Methods) + P.formatLine("- Method [type = {0}, vftable offset = {1}, attrs = {2}]", + M.Type, M.VFTableOffset, memberAttributes(M.Attrs)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + BuildInfoRecord &BI) { + auto Indices = BI.ArgIndices; + if (Indices.empty()) + return Error::success(); + + auto Max = std::max_element(Indices.begin(), Indices.end()); + uint32_t W = NumDigits(Max->getIndex()) + 2; + + for (auto I : Indices) + P.formatLine("{0}: `{1}`", fmt_align(I, AlignStyle::Right, W), + getTypeName(I)); + return Error::success(); +} + +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) { + P.format(" start index = {0:X+}, types count = {1:X+}, signature = {2:X+}," + " precomp path = {3}", + Precomp.StartTypeIndex, Precomp.TypesCount, Precomp.Signature, + Precomp.PrecompFilePath); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownRecord(CVType &CVR, + EndPrecompRecord &EP) { + P.format(" signature = {0:X+}", EP.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, + OneMethodRecord &Method) { + P.format(" [name = `{0}`]", Method.Name); + AutoIndent Indent(P); + P.formatLine("type = {0}, vftable offset = {1}, attrs = {2}", Method.Type, + Method.VFTableOffset, memberAttributes(Method.Attrs)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + OverloadedMethodRecord &Method) { + P.format(" [name = `{0}`, # overloads = {1}, overload list = {2}]", + Method.Name, Method.NumOverloads, Method.MethodList); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + DataMemberRecord &Field) { + P.format(" [name = `{0}`, Type = {1}, offset = {2}, attrs = {3}]", Field.Name, + Field.Type, Field.FieldOffset, memberAttributes(Field.Attrs)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + StaticDataMemberRecord &Field) { + P.format(" [name = `{0}`, type = {1}, attrs = {2}]", Field.Name, Field.Type, + memberAttributes(Field.Attrs)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + EnumeratorRecord &Enum) { + P.format(" [{0} = {1}]", Enum.Name, + Enum.Value.toString(10, Enum.Value.isSigned())); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + BaseClassRecord &Base) { + AutoIndent Indent(P); + P.formatLine("type = {0}, offset = {1}, attrs = {2}", Base.Type, Base.Offset, + memberAttributes(Base.Attrs)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + VirtualBaseClassRecord &Base) { + AutoIndent Indent(P); + P.formatLine( + "base = {0}, vbptr = {1}, vbptr offset = {2}, vtable index = {3}", + Base.BaseType, Base.VBPtrType, Base.VBPtrOffset, Base.VTableIndex); + P.formatLine("attrs = {0}", memberAttributes(Base.Attrs)); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + ListContinuationRecord &Cont) { + P.format(" continuation = {0}", Cont.ContinuationIndex); + return Error::success(); +} + +Error MinimalTypeDumpVisitor::visitKnownMember(CVMemberRecord &CVR, + VFPtrRecord &VFP) { + P.format(" type = {0}", VFP.Type); + return Error::success(); +} diff --git a/llvm/tools/obj2yaml/coff2yaml.cpp b/llvm/tools/obj2yaml/coff2yaml.cpp index 6c4f843..1c59c5c 100644 --- a/llvm/tools/obj2yaml/coff2yaml.cpp +++ b/llvm/tools/obj2yaml/coff2yaml.cpp @@ -170,7 +170,11 @@ void COFFDumper::dumpSections(unsigned NumSections) { 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); diff --git a/llvm/tools/yaml2obj/yaml2coff.cpp b/llvm/tools/yaml2obj/yaml2coff.cpp index 648317e..88af85d 100644 --- a/llvm/tools/yaml2obj/yaml2coff.cpp +++ b/llvm/tools/yaml2obj/yaml2coff.cpp @@ -233,7 +233,10 @@ static bool layoutCOFF(COFFParser &CP) { } } 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); diff --git a/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp b/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp index c51b9e7..64ee3e2 100644 --- a/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp +++ b/llvm/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); +} -- 2.7.4