44#define CV_TYPE(enum, val) {#enum, enum},
45#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
50#define TYPE_RECORD(ename, value, name) \
53#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
65template <
typename T,
typename TFlag>
69 return std::string(
"");
73 for (
const auto &Flag : Flags) {
77 SetFlags.push_back(Flag);
83 std::string FlagLabel;
85 for (
const auto &Flag : SetFlags) {
94 if (!FlagLabel.empty()) {
95 std::string LabelWithBraces(
" ( ");
96 LabelWithBraces += FlagLabel +
" )";
97 return LabelWithBraces;
102template <
typename T,
typename TEnum>
108 for (
const auto &EnumItem : EnumValues) {
109 if (EnumItem.Value ==
Value) {
110 Name = EnumItem.Name;
123 std::string AccessSpecifier = std::string(
125 std::string MemberAttrs(AccessSpecifier);
139struct MapOneMethodRecord {
140 explicit MapOneMethodRecord(
bool IsFromOverloadList)
141 : IsFromOverloadList(IsFromOverloadList) {}
143 Error operator()(CodeViewRecordIO &IO, OneMethodRecord &Method)
const {
144 std::string
Attrs = getMemberAttributes(
147 if (IsFromOverloadList) {
152 if (
Method.isIntroducingVirtual()) {
155 Method.VFTableOffset = -1;
157 if (!IsFromOverloadList)
164 bool IsFromOverloadList;
187 size_t BytesNeeded = Name.size() + UniqueName.
size() + 2;
188 if (BytesNeeded > BytesLeft) {
195 std::string UniqueB =
Twine(
"??@" + Hash +
"@").
str();
196 assert(UniqueB.size() == 36);
200 const size_t MaxTakeN = 4096;
201 size_t TakeN = std::min(MaxTakeN, BytesLeft - UniqueB.size() - 2) - 32;
203 std::string NameB = (Name.take_front(TakeN) + Hash).str();
232 assert(!TypeKind &&
"Already in a type mapping!");
233 assert(!MemberKind &&
"Already in a member mapping!");
238 std::optional<uint32_t> MaxLen;
239 if (CVR.
kind() != TypeLeafKind::LF_FIELDLIST &&
240 CVR.
kind() != TypeLeafKind::LF_METHODLIST)
242 error(IO.beginRecord(MaxLen));
243 TypeKind = CVR.
kind();
245 if (IO.isStreaming()) {
246 auto RecordKind = CVR.
kind();
248 std::string RecordKindName = std::string(
250 error(IO.mapInteger(RecordLen,
"Record length"));
251 error(IO.mapEnum(RecordKind,
"Record kind: " + RecordKindName));
257 if (IO.isStreaming())
264 assert(TypeKind &&
"Not in a type mapping!");
265 assert(!MemberKind &&
"Still in a member mapping!");
267 error(IO.endRecord());
274 assert(TypeKind &&
"Not in a type mapping!");
275 assert(!MemberKind &&
"Already in a member mapping!");
287 if (IO.isStreaming()) {
294 error(IO.mapEnum(
Record.Kind,
"Member kind: " + MemberKindName));
300 assert(TypeKind &&
"Not in a type mapping!");
301 assert(MemberKind &&
"Not in a member mapping!");
303 if (IO.isReading()) {
304 if (
auto EC = IO.skipPadding())
309 error(IO.endRecord());
314 std::string ModifierNames =
322Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
324 std::string CallingConvName = std::string(getEnumName(
326 std::string FuncOptionNames =
338Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
340 std::string CallingConvName = std::string(getEnumName(
342 std::string FuncOptionNames =
358 error(IO.mapVectorN<uint32_t>(
360 [](CodeViewRecordIO &IO, TypeIndex &
N) {
361 return IO.mapInteger(N,
"Argument");
367Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
369 error(IO.mapVectorN<uint32_t>(
371 [](CodeViewRecordIO &IO, TypeIndex &
N) {
372 return IO.mapInteger(N,
"Strings");
381 SmallString<128> Attr(
"Attrs: ");
383 if (IO.isStreaming()) {
384 std::string PtrType = std::string(getEnumName(
386 Attr +=
"[ Type: " + PtrType;
388 std::string PtrMode = std::string(getEnumName(
390 Attr +=
", Mode: " + PtrMode;
392 auto PtrSizeOf =
Record.getSize();
393 Attr +=
", SizeOf: " +
itostr(PtrSizeOf);
400 Attr +=
", isVolatile";
402 Attr +=
", isUnaligned";
404 Attr +=
", isRestricted";
405 if (
Record.isLValueReferenceThisPtr())
406 Attr +=
", isThisPtr&";
407 if (
Record.isRValueReferenceThisPtr())
408 Attr +=
", isThisPtr&&";
412 error(IO.mapInteger(
Record.ReferentType,
"PointeeType"));
415 if (
Record.isPointerToMember()) {
417 Record.MemberInfo.emplace();
419 MemberPointerInfo &
M = *
Record.MemberInfo;
420 error(IO.mapInteger(
M.ContainingType,
"ClassType"));
421 std::string PtrMemberGetRepresentation = std::string(getEnumName(
423 error(IO.mapEnum(
M.Representation,
424 "Representation: " + PtrMemberGetRepresentation));
431 error(IO.mapInteger(
Record.ElementType,
"ElementType"));
432 error(IO.mapInteger(
Record.IndexType,
"IndexType"));
433 error(IO.mapEncodedInteger(
Record.Size,
"SizeOf"));
440 assert((CVR.
kind() == TypeLeafKind::LF_STRUCTURE) ||
441 (CVR.
kind() == TypeLeafKind::LF_CLASS) ||
442 (CVR.
kind() == TypeLeafKind::LF_INTERFACE));
444 std::string PropertiesNames =
445 getFlagNames(IO,
static_cast<uint16_t
>(
Record.Options),
447 error(IO.mapInteger(
Record.MemberCount,
"MemberCount"));
448 error(IO.mapEnum(
Record.Options,
"Properties" + PropertiesNames));
449 error(IO.mapInteger(
Record.FieldList,
"FieldList"));
450 error(IO.mapInteger(
Record.DerivationList,
"DerivedFrom"));
451 error(IO.mapInteger(
Record.VTableShape,
"VShape"));
452 error(IO.mapEncodedInteger(
Record.Size,
"SizeOf"));
460 std::string PropertiesNames =
461 getFlagNames(IO,
static_cast<uint16_t
>(
Record.Options),
463 error(IO.mapInteger(
Record.MemberCount,
"MemberCount"));
464 error(IO.mapEnum(
Record.Options,
"Properties" + PropertiesNames));
465 error(IO.mapInteger(
Record.FieldList,
"FieldList"));
466 error(IO.mapEncodedInteger(
Record.Size,
"SizeOf"));
474 std::string PropertiesNames =
475 getFlagNames(IO,
static_cast<uint16_t
>(
Record.Options),
477 error(IO.mapInteger(
Record.MemberCount,
"NumEnumerators"));
478 error(IO.mapEnum(
Record.Options,
"Properties" + PropertiesNames));
479 error(IO.mapInteger(
Record.UnderlyingType,
"UnderlyingType"));
480 error(IO.mapInteger(
Record.FieldList,
"FieldListType"));
490 error(IO.mapInteger(
Record.BitOffset,
"BitOffset"));
495Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
498 if (!IO.isReading()) {
499 ArrayRef<VFTableSlotKind> Slots =
Record.getSlots();
501 error(IO.mapInteger(
Size,
"VFEntryCount"));
503 for (
size_t SlotIndex = 0; SlotIndex < Slots.
size(); SlotIndex += 2) {
504 uint8_t
Byte =
static_cast<uint8_t
>(Slots[SlotIndex]) << 4;
505 if ((SlotIndex + 1) < Slots.
size()) {
506 Byte |=
static_cast<uint8_t
>(Slots[SlotIndex + 1]);
512 for (uint16_t
I = 0;
I <
Size;
I += 2) {
525 error(IO.mapInteger(
Record.CompleteClass,
"CompleteClass"));
526 error(IO.mapInteger(
Record.OverriddenVFTable,
"OverriddenVFTable"));
527 error(IO.mapInteger(
Record.VFPtrOffset,
"VFPtrOffset"));
528 uint32_t NamesLen = 0;
529 if (!IO.isReading()) {
530 for (
auto Name :
Record.MethodNames)
531 NamesLen +=
Name.size() + 1;
533 error(IO.mapInteger(NamesLen));
534 error(IO.mapVectorTail(
536 [](CodeViewRecordIO &IO, StringRef &S) {
537 return IO.mapStringZ(S,
"MethodName");
551Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
554 error(IO.mapInteger(
Record.SourceFile,
"SourceFile"));
555 error(IO.mapInteger(
Record.LineNumber,
"LineNumber"));
560Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
563 error(IO.mapInteger(
Record.SourceFile,
"SourceFile"));
564 error(IO.mapInteger(
Record.LineNumber,
"LineNumber"));
571 error(IO.mapInteger(
Record.ParentScope,
"ParentScope"));
572 error(IO.mapInteger(
Record.FunctionType,
"FunctionType"));
578Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
580 error(IO.mapInteger(
Record.ClassType,
"ClassType"));
581 error(IO.mapInteger(
Record.FunctionType,
"FunctionType"));
587Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
589 error(IO.mapVectorN<uint16_t>(
591 [](CodeViewRecordIO &IO, TypeIndex &
N) {
592 return IO.mapInteger(N,
"Argument");
599Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
603 error(IO.mapVectorTail(
Record.Methods, MapOneMethodRecord(
true),
"Method"));
608Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
610 if (IO.isStreaming()) {
619Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
628 std::string ModeName = std::string(
630 error(IO.mapEnum(
Record.Mode,
"Mode: " + ModeName));
636 std::string
Attrs = getMemberAttributes(
638 error(IO.mapInteger(
Record.Attrs.Attrs,
"Attrs: " + Attrs));
640 error(IO.mapEncodedInteger(
Record.Offset,
"BaseOffset"));
647 std::string
Attrs = getMemberAttributes(
649 error(IO.mapInteger(
Record.Attrs.Attrs,
"Attrs: " + Attrs));
652 error(IO.mapEncodedInteger(
Record.Value,
"EnumValue"));
660 std::string
Attrs = getMemberAttributes(
662 error(IO.mapInteger(
Record.Attrs.Attrs,
"Attrs: " + Attrs));
664 error(IO.mapEncodedInteger(
Record.FieldOffset,
"FieldOffset"));
672 error(IO.mapInteger(
Record.NumOverloads,
"MethodCount"));
673 error(IO.mapInteger(
Record.MethodList,
"MethodListIndex"));
681 const bool IsFromOverloadList = (TypeKind == LF_METHODLIST);
682 MapOneMethodRecord Mapper(IsFromOverloadList);
683 return Mapper(IO, Record);
689 error(IO.mapInteger(Padding,
"Padding"));
699 std::string
Attrs = getMemberAttributes(
701 error(IO.mapInteger(
Record.Attrs.Attrs,
"Attrs: " + Attrs));
711 std::string
Attrs = getMemberAttributes(
713 error(IO.mapInteger(
Record.Attrs.Attrs,
"Attrs: " + Attrs));
715 error(IO.mapInteger(
Record.VBPtrType,
"VBPtrType"));
716 error(IO.mapEncodedInteger(
Record.VBPtrOffset,
"VBPtrOffset"));
717 error(IO.mapEncodedInteger(
Record.VTableIndex,
"VBTableIndex"));
725 error(IO.mapInteger(Padding,
"Padding"));
734 error(IO.mapInteger(Padding,
"Padding"));
735 error(IO.mapInteger(
Record.ContinuationIndex,
"ContinuationIndex"));
740Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
749Error TypeRecordMapping::visitKnownRecord(
CVType &CVR,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static constexpr uint32_t ContinuationLength
This file defines the SmallString class.
This file defines the SmallVector class.
static StringRef getLeafTypeName(TypeLeafKind LT)
static const EnumEntry< TypeLeafKind > LeafTypeNames[]
static void computeHashString(StringRef Name, SmallString< 32 > &StringifiedHash)
static Error mapNameAndUniqueName(CodeViewRecordIO &IO, StringRef &Name, StringRef &UniqueName, bool HasUniqueName)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
static LLVM_ABI void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
LLVM Value Representation.
LLVM_ABI Error mapInteger(TypeIndex &TypeInd, const Twine &Comment="")
LLVM_ABI Error mapStringZ(StringRef &Value, const Twine &Comment="")
Error mapEnum(T &Value, const Twine &Comment="")
LLVM_ABI uint32_t maxFieldLength() const
LF_INDEX - Used to chain two large LF_FIELDLIST or LF_METHODLIST records together.
For method overload sets. LF_METHOD.
StringRef PrecompFilePath
Error visitTypeBegin(CVType &Record) override
Paired begin/end actions for all types.
Error visitMemberBegin(CVMemberRecord &Record) override
Error visitTypeEnd(CVType &Record) override
Error visitMemberEnd(CVMemberRecord &Record) override
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getMethodOptionNames()
MethodKind
Part of member attribute flags. (CV_methodprop_e)
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getCallingConventions()
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getMemberAccessNames()
CVRecord< TypeLeafKind > CVType
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getPtrKindNames()
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getPtrMemberRepNames()
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getLabelTypeEnum()
LLVM_ABI Error visitMemberRecordStream(ArrayRef< uint8_t > FieldList, TypeVisitorCallbacks &Callbacks)
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getTypeModifierNames()
MethodOptions
Equivalent to CV_fldattr_t bitfield.
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getMemberKindNames()
MemberAccess
Source-level access specifier. (CV_access_e)
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getPtrModeNames()
LLVM_ABI ArrayRef< EnumEntry< uint8_t > > getFunctionOptionEnum()
LLVM_ABI ArrayRef< EnumEntry< uint16_t > > getClassOptionNames()
This is an optimization pass for GlobalISel generic memory operations.
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
void sort(IteratorTy Start, IteratorTy End)
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string itostr(int64_t X)