Path: blob/main/contrib/llvm-project/llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
35260 views
//===- MinimalSymbolDumper.cpp -------------------------------- *- C++ --*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "MinimalSymbolDumper.h"910#include "llvm/ADT/StringExtras.h"11#include "llvm/DebugInfo/CodeView/CVRecord.h"12#include "llvm/DebugInfo/CodeView/CodeView.h"13#include "llvm/DebugInfo/CodeView/Formatters.h"14#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"15#include "llvm/DebugInfo/CodeView/SymbolRecord.h"16#include "llvm/DebugInfo/CodeView/TypeRecord.h"17#include "llvm/DebugInfo/PDB/Native/FormatUtil.h"18#include "llvm/DebugInfo/PDB/Native/InputFile.h"19#include "llvm/DebugInfo/PDB/Native/LinePrinter.h"20#include "llvm/DebugInfo/PDB/Native/NativeSession.h"21#include "llvm/DebugInfo/PDB/Native/PDBFile.h"22#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"23#include "llvm/Object/COFF.h"24#include "llvm/Support/FormatVariadic.h"2526using namespace llvm;27using namespace llvm::codeview;28using namespace llvm::pdb;2930static std::string formatLocalSymFlags(uint32_t IndentLevel,31LocalSymFlags Flags) {32std::vector<std::string> Opts;33if (Flags == LocalSymFlags::None)34return "none";3536PUSH_FLAG(LocalSymFlags, IsParameter, Flags, "param");37PUSH_FLAG(LocalSymFlags, IsAddressTaken, Flags, "address is taken");38PUSH_FLAG(LocalSymFlags, IsCompilerGenerated, Flags, "compiler generated");39PUSH_FLAG(LocalSymFlags, IsAggregate, Flags, "aggregate");40PUSH_FLAG(LocalSymFlags, IsAggregated, Flags, "aggregated");41PUSH_FLAG(LocalSymFlags, IsAliased, Flags, "aliased");42PUSH_FLAG(LocalSymFlags, IsAlias, Flags, "alias");43PUSH_FLAG(LocalSymFlags, IsReturnValue, Flags, "return val");44PUSH_FLAG(LocalSymFlags, IsOptimizedOut, Flags, "optimized away");45PUSH_FLAG(LocalSymFlags, IsEnregisteredGlobal, Flags, "enreg global");46PUSH_FLAG(LocalSymFlags, IsEnregisteredStatic, Flags, "enreg static");47return typesetItemList(Opts, 4, IndentLevel, " | ");48}4950static std::string formatExportFlags(uint32_t IndentLevel, ExportFlags Flags) {51std::vector<std::string> Opts;52if (Flags == ExportFlags::None)53return "none";5455PUSH_FLAG(ExportFlags, IsConstant, Flags, "constant");56PUSH_FLAG(ExportFlags, IsData, Flags, "data");57PUSH_FLAG(ExportFlags, IsPrivate, Flags, "private");58PUSH_FLAG(ExportFlags, HasNoName, Flags, "no name");59PUSH_FLAG(ExportFlags, HasExplicitOrdinal, Flags, "explicit ord");60PUSH_FLAG(ExportFlags, IsForwarder, Flags, "forwarder");6162return typesetItemList(Opts, 4, IndentLevel, " | ");63}6465static std::string formatCompileSym2Flags(uint32_t IndentLevel,66CompileSym2Flags Flags) {67std::vector<std::string> Opts;68Flags &= ~CompileSym2Flags::SourceLanguageMask;69if (Flags == CompileSym2Flags::None)70return "none";7172PUSH_FLAG(CompileSym2Flags, EC, Flags, "edit and continue");73PUSH_FLAG(CompileSym2Flags, NoDbgInfo, Flags, "no dbg info");74PUSH_FLAG(CompileSym2Flags, LTCG, Flags, "ltcg");75PUSH_FLAG(CompileSym2Flags, NoDataAlign, Flags, "no data align");76PUSH_FLAG(CompileSym2Flags, ManagedPresent, Flags, "has managed code");77PUSH_FLAG(CompileSym2Flags, SecurityChecks, Flags, "security checks");78PUSH_FLAG(CompileSym2Flags, HotPatch, Flags, "hot patchable");79PUSH_FLAG(CompileSym2Flags, CVTCIL, Flags, "cvtcil");80PUSH_FLAG(CompileSym2Flags, MSILModule, Flags, "msil module");81return typesetItemList(Opts, 4, IndentLevel, " | ");82}8384static std::string formatCompileSym3Flags(uint32_t IndentLevel,85CompileSym3Flags Flags) {86std::vector<std::string> Opts;87Flags &= ~CompileSym3Flags::SourceLanguageMask;8889if (Flags == CompileSym3Flags::None)90return "none";9192PUSH_FLAG(CompileSym3Flags, EC, Flags, "edit and continue");93PUSH_FLAG(CompileSym3Flags, NoDbgInfo, Flags, "no dbg info");94PUSH_FLAG(CompileSym3Flags, LTCG, Flags, "ltcg");95PUSH_FLAG(CompileSym3Flags, NoDataAlign, Flags, "no data align");96PUSH_FLAG(CompileSym3Flags, ManagedPresent, Flags, "has managed code");97PUSH_FLAG(CompileSym3Flags, SecurityChecks, Flags, "security checks");98PUSH_FLAG(CompileSym3Flags, HotPatch, Flags, "hot patchable");99PUSH_FLAG(CompileSym3Flags, CVTCIL, Flags, "cvtcil");100PUSH_FLAG(CompileSym3Flags, MSILModule, Flags, "msil module");101PUSH_FLAG(CompileSym3Flags, Sdl, Flags, "sdl");102PUSH_FLAG(CompileSym3Flags, PGO, Flags, "pgo");103PUSH_FLAG(CompileSym3Flags, Exp, Flags, "exp");104return typesetItemList(Opts, 4, IndentLevel, " | ");105}106107static std::string formatFrameProcedureOptions(uint32_t IndentLevel,108FrameProcedureOptions FPO) {109std::vector<std::string> Opts;110if (FPO == FrameProcedureOptions::None)111return "none";112113PUSH_FLAG(FrameProcedureOptions, HasAlloca, FPO, "has alloca");114PUSH_FLAG(FrameProcedureOptions, HasSetJmp, FPO, "has setjmp");115PUSH_FLAG(FrameProcedureOptions, HasLongJmp, FPO, "has longjmp");116PUSH_FLAG(FrameProcedureOptions, HasInlineAssembly, FPO, "has inline asm");117PUSH_FLAG(FrameProcedureOptions, HasExceptionHandling, FPO, "has eh");118PUSH_FLAG(FrameProcedureOptions, MarkedInline, FPO, "marked inline");119PUSH_FLAG(FrameProcedureOptions, HasStructuredExceptionHandling, FPO,120"has seh");121PUSH_FLAG(FrameProcedureOptions, Naked, FPO, "naked");122PUSH_FLAG(FrameProcedureOptions, SecurityChecks, FPO, "secure checks");123PUSH_FLAG(FrameProcedureOptions, AsynchronousExceptionHandling, FPO,124"has async eh");125PUSH_FLAG(FrameProcedureOptions, NoStackOrderingForSecurityChecks, FPO,126"no stack order");127PUSH_FLAG(FrameProcedureOptions, Inlined, FPO, "inlined");128PUSH_FLAG(FrameProcedureOptions, StrictSecurityChecks, FPO,129"strict secure checks");130PUSH_FLAG(FrameProcedureOptions, SafeBuffers, FPO, "safe buffers");131PUSH_FLAG(FrameProcedureOptions, ProfileGuidedOptimization, FPO, "pgo");132PUSH_FLAG(FrameProcedureOptions, ValidProfileCounts, FPO,133"has profile counts");134PUSH_FLAG(FrameProcedureOptions, OptimizedForSpeed, FPO, "opt speed");135PUSH_FLAG(FrameProcedureOptions, GuardCfg, FPO, "guard cfg");136PUSH_FLAG(FrameProcedureOptions, GuardCfw, FPO, "guard cfw");137return typesetItemList(Opts, 4, IndentLevel, " | ");138}139140static std::string formatPublicSymFlags(uint32_t IndentLevel,141PublicSymFlags Flags) {142std::vector<std::string> Opts;143if (Flags == PublicSymFlags::None)144return "none";145146PUSH_FLAG(PublicSymFlags, Code, Flags, "code");147PUSH_FLAG(PublicSymFlags, Function, Flags, "function");148PUSH_FLAG(PublicSymFlags, Managed, Flags, "managed");149PUSH_FLAG(PublicSymFlags, MSIL, Flags, "msil");150return typesetItemList(Opts, 4, IndentLevel, " | ");151}152153static std::string formatProcSymFlags(uint32_t IndentLevel,154ProcSymFlags Flags) {155std::vector<std::string> Opts;156if (Flags == ProcSymFlags::None)157return "none";158159PUSH_FLAG(ProcSymFlags, HasFP, Flags, "has fp");160PUSH_FLAG(ProcSymFlags, HasIRET, Flags, "has iret");161PUSH_FLAG(ProcSymFlags, HasFRET, Flags, "has fret");162PUSH_FLAG(ProcSymFlags, IsNoReturn, Flags, "noreturn");163PUSH_FLAG(ProcSymFlags, IsUnreachable, Flags, "unreachable");164PUSH_FLAG(ProcSymFlags, HasCustomCallingConv, Flags, "custom calling conv");165PUSH_FLAG(ProcSymFlags, IsNoInline, Flags, "noinline");166PUSH_FLAG(ProcSymFlags, HasOptimizedDebugInfo, Flags, "opt debuginfo");167return typesetItemList(Opts, 4, IndentLevel, " | ");168}169170static std::string formatThunkOrdinal(ThunkOrdinal Ordinal) {171switch (Ordinal) {172RETURN_CASE(ThunkOrdinal, Standard, "thunk");173RETURN_CASE(ThunkOrdinal, ThisAdjustor, "this adjustor");174RETURN_CASE(ThunkOrdinal, Vcall, "vcall");175RETURN_CASE(ThunkOrdinal, Pcode, "pcode");176RETURN_CASE(ThunkOrdinal, UnknownLoad, "unknown load");177RETURN_CASE(ThunkOrdinal, TrampIncremental, "tramp incremental");178RETURN_CASE(ThunkOrdinal, BranchIsland, "branch island");179}180return formatUnknownEnum(Ordinal);181}182183static std::string formatTrampolineType(TrampolineType Tramp) {184switch (Tramp) {185RETURN_CASE(TrampolineType, TrampIncremental, "tramp incremental");186RETURN_CASE(TrampolineType, BranchIsland, "branch island");187}188return formatUnknownEnum(Tramp);189}190191static std::string formatSourceLanguage(SourceLanguage Lang) {192switch (Lang) {193RETURN_CASE(SourceLanguage, C, "c");194RETURN_CASE(SourceLanguage, Cpp, "c++");195RETURN_CASE(SourceLanguage, Fortran, "fortran");196RETURN_CASE(SourceLanguage, Masm, "masm");197RETURN_CASE(SourceLanguage, Pascal, "pascal");198RETURN_CASE(SourceLanguage, Basic, "basic");199RETURN_CASE(SourceLanguage, Cobol, "cobol");200RETURN_CASE(SourceLanguage, Link, "link");201RETURN_CASE(SourceLanguage, VB, "vb");202RETURN_CASE(SourceLanguage, Cvtres, "cvtres");203RETURN_CASE(SourceLanguage, Cvtpgd, "cvtpgd");204RETURN_CASE(SourceLanguage, CSharp, "c#");205RETURN_CASE(SourceLanguage, ILAsm, "il asm");206RETURN_CASE(SourceLanguage, Java, "java");207RETURN_CASE(SourceLanguage, JScript, "javascript");208RETURN_CASE(SourceLanguage, MSIL, "msil");209RETURN_CASE(SourceLanguage, HLSL, "hlsl");210RETURN_CASE(SourceLanguage, D, "d");211RETURN_CASE(SourceLanguage, Swift, "swift");212RETURN_CASE(SourceLanguage, Rust, "rust");213RETURN_CASE(SourceLanguage, ObjC, "objc");214RETURN_CASE(SourceLanguage, ObjCpp, "objc++");215RETURN_CASE(SourceLanguage, AliasObj, "aliasobj");216RETURN_CASE(SourceLanguage, Go, "go");217RETURN_CASE(SourceLanguage, OldSwift, "swift");218}219return formatUnknownEnum(Lang);220}221222static std::string formatMachineType(CPUType Cpu) {223switch (Cpu) {224RETURN_CASE(CPUType, Intel8080, "intel 8080");225RETURN_CASE(CPUType, Intel8086, "intel 8086");226RETURN_CASE(CPUType, Intel80286, "intel 80286");227RETURN_CASE(CPUType, Intel80386, "intel 80386");228RETURN_CASE(CPUType, Intel80486, "intel 80486");229RETURN_CASE(CPUType, Pentium, "intel pentium");230RETURN_CASE(CPUType, PentiumPro, "intel pentium pro");231RETURN_CASE(CPUType, Pentium3, "intel pentium 3");232RETURN_CASE(CPUType, MIPS, "mips");233RETURN_CASE(CPUType, MIPS16, "mips-16");234RETURN_CASE(CPUType, MIPS32, "mips-32");235RETURN_CASE(CPUType, MIPS64, "mips-64");236RETURN_CASE(CPUType, MIPSI, "mips i");237RETURN_CASE(CPUType, MIPSII, "mips ii");238RETURN_CASE(CPUType, MIPSIII, "mips iii");239RETURN_CASE(CPUType, MIPSIV, "mips iv");240RETURN_CASE(CPUType, MIPSV, "mips v");241RETURN_CASE(CPUType, M68000, "motorola 68000");242RETURN_CASE(CPUType, M68010, "motorola 68010");243RETURN_CASE(CPUType, M68020, "motorola 68020");244RETURN_CASE(CPUType, M68030, "motorola 68030");245RETURN_CASE(CPUType, M68040, "motorola 68040");246RETURN_CASE(CPUType, Alpha, "alpha");247RETURN_CASE(CPUType, Alpha21164, "alpha 21164");248RETURN_CASE(CPUType, Alpha21164A, "alpha 21164a");249RETURN_CASE(CPUType, Alpha21264, "alpha 21264");250RETURN_CASE(CPUType, Alpha21364, "alpha 21364");251RETURN_CASE(CPUType, PPC601, "powerpc 601");252RETURN_CASE(CPUType, PPC603, "powerpc 603");253RETURN_CASE(CPUType, PPC604, "powerpc 604");254RETURN_CASE(CPUType, PPC620, "powerpc 620");255RETURN_CASE(CPUType, PPCFP, "powerpc fp");256RETURN_CASE(CPUType, PPCBE, "powerpc be");257RETURN_CASE(CPUType, SH3, "sh3");258RETURN_CASE(CPUType, SH3E, "sh3e");259RETURN_CASE(CPUType, SH3DSP, "sh3 dsp");260RETURN_CASE(CPUType, SH4, "sh4");261RETURN_CASE(CPUType, SHMedia, "shmedia");262RETURN_CASE(CPUType, ARM3, "arm 3");263RETURN_CASE(CPUType, ARM4, "arm 4");264RETURN_CASE(CPUType, ARM4T, "arm 4t");265RETURN_CASE(CPUType, ARM5, "arm 5");266RETURN_CASE(CPUType, ARM5T, "arm 5t");267RETURN_CASE(CPUType, ARM6, "arm 6");268RETURN_CASE(CPUType, ARM_XMAC, "arm xmac");269RETURN_CASE(CPUType, ARM_WMMX, "arm wmmx");270RETURN_CASE(CPUType, ARM7, "arm 7");271RETURN_CASE(CPUType, ARM64, "arm64");272RETURN_CASE(CPUType, ARM64EC, "arm64ec");273RETURN_CASE(CPUType, ARM64X, "arm64x");274RETURN_CASE(CPUType, HybridX86ARM64, "hybrid x86 arm64");275RETURN_CASE(CPUType, Omni, "omni");276RETURN_CASE(CPUType, Ia64, "intel itanium ia64");277RETURN_CASE(CPUType, Ia64_2, "intel itanium ia64 2");278RETURN_CASE(CPUType, CEE, "cee");279RETURN_CASE(CPUType, AM33, "am33");280RETURN_CASE(CPUType, M32R, "m32r");281RETURN_CASE(CPUType, TriCore, "tri-core");282RETURN_CASE(CPUType, X64, "intel x86-x64");283RETURN_CASE(CPUType, EBC, "ebc");284RETURN_CASE(CPUType, Thumb, "thumb");285RETURN_CASE(CPUType, ARMNT, "arm nt");286RETURN_CASE(CPUType, D3D11_Shader, "d3d11 shader");287RETURN_CASE(CPUType, Unknown, "unknown");288}289return formatUnknownEnum(Cpu);290}291292static std::string formatCookieKind(FrameCookieKind Kind) {293switch (Kind) {294RETURN_CASE(FrameCookieKind, Copy, "copy");295RETURN_CASE(FrameCookieKind, XorStackPointer, "xor stack ptr");296RETURN_CASE(FrameCookieKind, XorFramePointer, "xor frame ptr");297RETURN_CASE(FrameCookieKind, XorR13, "xor rot13");298}299return formatUnknownEnum(Kind);300}301302static std::string formatRegisterId(RegisterId Id, CPUType Cpu) {303if (Cpu == CPUType::ARMNT) {304switch (Id) {305#define CV_REGISTERS_ARM306#define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)307#include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"308#undef CV_REGISTER309#undef CV_REGISTERS_ARM310311default:312break;313}314} else if (Cpu == CPUType::ARM64) {315switch (Id) {316#define CV_REGISTERS_ARM64317#define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)318#include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"319#undef CV_REGISTER320#undef CV_REGISTERS_ARM64321322default:323break;324}325} else {326switch (Id) {327#define CV_REGISTERS_X86328#define CV_REGISTER(name, val) RETURN_CASE(RegisterId, name, #name)329#include "llvm/DebugInfo/CodeView/CodeViewRegisters.def"330#undef CV_REGISTER331#undef CV_REGISTERS_X86332333default:334break;335}336}337return formatUnknownEnum(Id);338}339340static std::string formatRegisterId(uint16_t Reg16, CPUType Cpu) {341return formatRegisterId(RegisterId(Reg16), Cpu);342}343344static std::string formatRegisterId(ulittle16_t &Reg16, CPUType Cpu) {345return formatRegisterId(uint16_t(Reg16), Cpu);346}347348static std::string formatRange(LocalVariableAddrRange Range) {349return formatv("[{0},+{1})",350formatSegmentOffset(Range.ISectStart, Range.OffsetStart),351Range.Range)352.str();353}354355static std::string formatGaps(uint32_t IndentLevel,356ArrayRef<LocalVariableAddrGap> Gaps) {357std::vector<std::string> GapStrs;358for (const auto &G : Gaps) {359GapStrs.push_back(formatv("({0},{1})", G.GapStartOffset, G.Range).str());360}361return typesetItemList(GapStrs, 7, IndentLevel, ", ");362}363364static std::string formatJumpTableEntrySize(JumpTableEntrySize EntrySize) {365switch (EntrySize) {366RETURN_CASE(JumpTableEntrySize, Int8, "int8");367RETURN_CASE(JumpTableEntrySize, UInt8, "uin8");368RETURN_CASE(JumpTableEntrySize, Int16, "int16");369RETURN_CASE(JumpTableEntrySize, UInt16, "uint16");370RETURN_CASE(JumpTableEntrySize, Int32, "int32");371RETURN_CASE(JumpTableEntrySize, UInt32, "uint32");372RETURN_CASE(JumpTableEntrySize, Pointer, "pointer");373RETURN_CASE(JumpTableEntrySize, UInt8ShiftLeft, "uint8shl");374RETURN_CASE(JumpTableEntrySize, UInt16ShiftLeft, "uint16shl");375RETURN_CASE(JumpTableEntrySize, Int8ShiftLeft, "int8shl");376RETURN_CASE(JumpTableEntrySize, Int16ShiftLeft, "int16shl");377}378return formatUnknownEnum(EntrySize);379}380381Error MinimalSymbolDumper::visitSymbolBegin(codeview::CVSymbol &Record) {382return visitSymbolBegin(Record, 0);383}384385Error MinimalSymbolDumper::visitSymbolBegin(codeview::CVSymbol &Record,386uint32_t Offset) {387// formatLine puts the newline at the beginning, so we use formatLine here388// to start a new line, and then individual visit methods use format to389// append to the existing line.390P.formatLine("{0} | {1} [size = {2}]",391fmt_align(Offset, AlignStyle::Right, 6),392formatSymbolKind(Record.kind()), Record.length());393P.Indent();394return Error::success();395}396397Error MinimalSymbolDumper::visitSymbolEnd(CVSymbol &Record) {398if (RecordBytes) {399AutoIndent Indent(P, 7);400P.formatBinary("bytes", Record.content(), 0);401}402P.Unindent();403return Error::success();404}405406std::string MinimalSymbolDumper::typeOrIdIndex(codeview::TypeIndex TI,407bool IsType) const {408if (TI.isSimple() || TI.isDecoratedItemId())409return formatv("{0}", TI).str();410auto &Container = IsType ? Types : Ids;411StringRef Name = Container.getTypeName(TI);412if (Name.size() > 32) {413Name = Name.take_front(32);414return std::string(formatv("{0} ({1}...)", TI, Name));415} else416return std::string(formatv("{0} ({1})", TI, Name));417}418419std::string MinimalSymbolDumper::idIndex(codeview::TypeIndex TI) const {420return typeOrIdIndex(TI, false);421}422423std::string MinimalSymbolDumper::typeIndex(TypeIndex TI) const {424return typeOrIdIndex(TI, true);425}426427Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, BlockSym &Block) {428P.format(" `{0}`", Block.Name);429AutoIndent Indent(P, 7);430P.formatLine("parent = {0}, end = {1}", Block.Parent, Block.End);431P.formatLine("code size = {0}, addr = {1}", Block.CodeSize,432formatSegmentOffset(Block.Segment, Block.CodeOffset));433return Error::success();434}435436Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {437P.format(" `{0}`", Thunk.Name);438AutoIndent Indent(P, 7);439P.formatLine("parent = {0}, end = {1}, next = {2}", Thunk.Parent, Thunk.End,440Thunk.Next);441P.formatLine("kind = {0}, size = {1}, addr = {2}",442formatThunkOrdinal(Thunk.Thunk), Thunk.Length,443formatSegmentOffset(Thunk.Segment, Thunk.Offset));444445return Error::success();446}447448Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,449TrampolineSym &Tramp) {450AutoIndent Indent(P, 7);451P.formatLine("type = {0}, size = {1}, source = {2}, target = {3}",452formatTrampolineType(Tramp.Type), Tramp.Size,453formatSegmentOffset(Tramp.ThunkSection, Tramp.ThunkOffset),454formatSegmentOffset(Tramp.TargetSection, Tramp.ThunkOffset));455456return Error::success();457}458459Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,460SectionSym &Section) {461P.format(" `{0}`", Section.Name);462AutoIndent Indent(P, 7);463P.formatLine("length = {0}, alignment = {1}, rva = {2}, section # = {3}",464Section.Length, Section.Alignment, Section.Rva,465Section.SectionNumber);466P.printLine("characteristics =");467AutoIndent Indent2(P, 2);468P.printLine(formatSectionCharacteristics(P.getIndentLevel(),469Section.Characteristics, 1, "",470CharacteristicStyle::Descriptive));471return Error::success();472}473474Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, CoffGroupSym &CG) {475P.format(" `{0}`", CG.Name);476AutoIndent Indent(P, 7);477P.formatLine("length = {0}, addr = {1}", CG.Size,478formatSegmentOffset(CG.Segment, CG.Offset));479P.printLine("characteristics =");480AutoIndent Indent2(P, 2);481P.printLine(formatSectionCharacteristics(P.getIndentLevel(),482CG.Characteristics, 1, "",483CharacteristicStyle::Descriptive));484return Error::success();485}486487Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,488BPRelativeSym &BPRel) {489P.format(" `{0}`", BPRel.Name);490AutoIndent Indent(P, 7);491P.formatLine("type = {0}, offset = {1}", typeIndex(BPRel.Type), BPRel.Offset);492return Error::success();493}494495Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,496BuildInfoSym &BuildInfo) {497P.format(" BuildId = `{0}`", BuildInfo.BuildId);498return Error::success();499}500501Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,502CallSiteInfoSym &CSI) {503AutoIndent Indent(P, 7);504P.formatLine("type = {0}, addr = {1}", typeIndex(CSI.Type),505formatSegmentOffset(CSI.Segment, CSI.CodeOffset));506return Error::success();507}508509Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,510EnvBlockSym &EnvBlock) {511AutoIndent Indent(P, 7);512for (const auto &Entry : EnvBlock.Fields) {513P.formatLine("- {0}", Entry);514}515return Error::success();516}517518Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FileStaticSym &FS) {519P.format(" `{0}`", FS.Name);520AutoIndent Indent(P, 7);521if (SymGroup) {522Expected<StringRef> FileName =523SymGroup->getNameFromStringTable(FS.ModFilenameOffset);524if (FileName) {525P.formatLine("type = {0}, file name = {1} ({2}), flags = {3}",526typeIndex(FS.Index), FS.ModFilenameOffset, *FileName,527formatLocalSymFlags(P.getIndentLevel() + 9, FS.Flags));528}529return Error::success();530}531532P.formatLine("type = {0}, file name offset = {1}, flags = {2}",533typeIndex(FS.Index), FS.ModFilenameOffset,534formatLocalSymFlags(P.getIndentLevel() + 9, FS.Flags));535return Error::success();536}537538Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {539P.format(" `{0}`", Export.Name);540AutoIndent Indent(P, 7);541P.formatLine("ordinal = {0}, flags = {1}", Export.Ordinal,542formatExportFlags(P.getIndentLevel() + 9, Export.Flags));543return Error::success();544}545546Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,547Compile2Sym &Compile2) {548AutoIndent Indent(P, 7);549SourceLanguage Lang = static_cast<SourceLanguage>(550Compile2.Flags & CompileSym2Flags::SourceLanguageMask);551CompilationCPU = Compile2.Machine;552P.formatLine("machine = {0}, ver = {1}, language = {2}",553formatMachineType(Compile2.Machine), Compile2.Version,554formatSourceLanguage(Lang));555P.formatLine("frontend = {0}.{1}.{2}, backend = {3}.{4}.{5}",556Compile2.VersionFrontendMajor, Compile2.VersionFrontendMinor,557Compile2.VersionFrontendBuild, Compile2.VersionBackendMajor,558Compile2.VersionBackendMinor, Compile2.VersionBackendBuild);559P.formatLine("flags = {0}",560formatCompileSym2Flags(P.getIndentLevel() + 9, Compile2.Flags));561P.formatLine(562"extra strings = {0}",563typesetStringList(P.getIndentLevel() + 9 + 2, Compile2.ExtraStrings));564return Error::success();565}566567Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,568Compile3Sym &Compile3) {569AutoIndent Indent(P, 7);570SourceLanguage Lang = static_cast<SourceLanguage>(571Compile3.Flags & CompileSym3Flags::SourceLanguageMask);572CompilationCPU = Compile3.Machine;573P.formatLine("machine = {0}, Ver = {1}, language = {2}",574formatMachineType(Compile3.Machine), Compile3.Version,575formatSourceLanguage(Lang));576P.formatLine("frontend = {0}.{1}.{2}.{3}, backend = {4}.{5}.{6}.{7}",577Compile3.VersionFrontendMajor, Compile3.VersionFrontendMinor,578Compile3.VersionFrontendBuild, Compile3.VersionFrontendQFE,579Compile3.VersionBackendMajor, Compile3.VersionBackendMinor,580Compile3.VersionBackendBuild, Compile3.VersionBackendQFE);581P.formatLine("flags = {0}",582formatCompileSym3Flags(P.getIndentLevel() + 9, Compile3.Flags));583return Error::success();584}585586Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,587ConstantSym &Constant) {588P.format(" `{0}`", Constant.Name);589AutoIndent Indent(P, 7);590P.formatLine("type = {0}, value = {1}", typeIndex(Constant.Type),591toString(Constant.Value, 10));592return Error::success();593}594595Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {596P.format(" `{0}`", Data.Name);597AutoIndent Indent(P, 7);598P.formatLine("type = {0}, addr = {1}", typeIndex(Data.Type),599formatSegmentOffset(Data.Segment, Data.DataOffset));600return Error::success();601}602603Error MinimalSymbolDumper::visitKnownRecord(604CVSymbol &CVR, DefRangeFramePointerRelFullScopeSym &Def) {605P.format(" offset = {0}", Def.Offset);606return Error::success();607}608609Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,610DefRangeFramePointerRelSym &Def) {611AutoIndent Indent(P, 7);612P.formatLine("offset = {0}, range = {1}", Def.Hdr.Offset,613formatRange(Def.Range));614P.formatLine("gaps = [{0}]", formatGaps(P.getIndentLevel() + 9, Def.Gaps));615return Error::success();616}617618Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,619DefRangeRegisterRelSym &Def) {620AutoIndent Indent(P, 7);621P.formatLine("register = {0}, offset = {1}, offset in parent = {2}, has "622"spilled udt = {3}",623formatRegisterId(Def.Hdr.Register, CompilationCPU),624int32_t(Def.Hdr.BasePointerOffset), Def.offsetInParent(),625Def.hasSpilledUDTMember());626P.formatLine("range = {0}, gaps = [{1}]", formatRange(Def.Range),627formatGaps(P.getIndentLevel() + 9, Def.Gaps));628return Error::success();629}630631Error MinimalSymbolDumper::visitKnownRecord(632CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {633AutoIndent Indent(P, 7);634P.formatLine("register = {0}, may have no name = {1}, range start = "635"{2}, length = {3}",636formatRegisterId(DefRangeRegister.Hdr.Register, CompilationCPU),637bool(DefRangeRegister.Hdr.MayHaveNoName),638formatSegmentOffset(DefRangeRegister.Range.ISectStart,639DefRangeRegister.Range.OffsetStart),640DefRangeRegister.Range.Range);641P.formatLine("gaps = [{0}]",642formatGaps(P.getIndentLevel() + 9, DefRangeRegister.Gaps));643return Error::success();644}645646Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,647DefRangeSubfieldRegisterSym &Def) {648AutoIndent Indent(P, 7);649bool NoName = !!(Def.Hdr.MayHaveNoName == 0);650P.formatLine("register = {0}, may have no name = {1}, offset in parent = {2}",651formatRegisterId(Def.Hdr.Register, CompilationCPU), NoName,652uint32_t(Def.Hdr.OffsetInParent));653P.formatLine("range = {0}, gaps = [{1}]", formatRange(Def.Range),654formatGaps(P.getIndentLevel() + 9, Def.Gaps));655return Error::success();656}657658Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,659DefRangeSubfieldSym &Def) {660AutoIndent Indent(P, 7);661P.formatLine("program = {0}, offset in parent = {1}, range = {2}",662Def.Program, Def.OffsetInParent, formatRange(Def.Range));663P.formatLine("gaps = [{0}]", formatGaps(P.getIndentLevel() + 9, Def.Gaps));664return Error::success();665}666667Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, DefRangeSym &Def) {668AutoIndent Indent(P, 7);669P.formatLine("program = {0}, range = {1}", Def.Program,670formatRange(Def.Range));671P.formatLine("gaps = [{0}]", formatGaps(P.getIndentLevel() + 9, Def.Gaps));672return Error::success();673}674675Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FrameCookieSym &FC) {676AutoIndent Indent(P, 7);677P.formatLine("code offset = {0}, Register = {1}, kind = {2}, flags = {3}",678FC.CodeOffset, formatRegisterId(FC.Register, CompilationCPU),679formatCookieKind(FC.CookieKind), FC.Flags);680return Error::success();681}682683Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, FrameProcSym &FP) {684AutoIndent Indent(P, 7);685P.formatLine("size = {0}, padding size = {1}, offset to padding = {2}",686FP.TotalFrameBytes, FP.PaddingFrameBytes, FP.OffsetToPadding);687P.formatLine("bytes of callee saved registers = {0}, exception handler addr "688"= {1}",689FP.BytesOfCalleeSavedRegisters,690formatSegmentOffset(FP.SectionIdOfExceptionHandler,691FP.OffsetOfExceptionHandler));692P.formatLine(693"local fp reg = {0}, param fp reg = {1}",694formatRegisterId(FP.getLocalFramePtrReg(CompilationCPU), CompilationCPU),695formatRegisterId(FP.getParamFramePtrReg(CompilationCPU), CompilationCPU));696P.formatLine("flags = {0}",697formatFrameProcedureOptions(P.getIndentLevel() + 9, FP.Flags));698return Error::success();699}700701Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,702HeapAllocationSiteSym &HAS) {703AutoIndent Indent(P, 7);704P.formatLine("type = {0}, addr = {1} call size = {2}", typeIndex(HAS.Type),705formatSegmentOffset(HAS.Segment, HAS.CodeOffset),706HAS.CallInstructionSize);707return Error::success();708}709710Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, InlineSiteSym &IS) {711AutoIndent Indent(P, 7);712P.formatLine("inlinee = {0}, parent = {1}, end = {2}", idIndex(IS.Inlinee),713IS.Parent, IS.End);714715// Break down the annotation byte code and calculate code and line offsets.716// FIXME: It would be helpful if we could look up the initial file and inlinee717// lines offset using the inlinee index above.718uint32_t CodeOffset = 0;719int32_t LineOffset = 0;720for (auto &Annot : IS.annotations()) {721P.formatLine(" {0}", fmt_align(toHex(Annot.Bytes), AlignStyle::Left, 9));722723auto formatCodeOffset = [&](uint32_t Delta) {724CodeOffset += Delta;725P.format(" code 0x{0} (+0x{1})", utohexstr(CodeOffset), utohexstr(Delta));726};727auto formatCodeLength = [&](uint32_t Length) {728// Notably, changing the code length does not affect the code offset.729P.format(" code end 0x{0} (+0x{1})", utohexstr(CodeOffset + Length),730utohexstr(Length));731};732auto formatLineOffset = [&](int32_t Delta) {733LineOffset += Delta;734char Sign = Delta > 0 ? '+' : '-';735P.format(" line {0} ({1}{2})", LineOffset, Sign, std::abs(Delta));736};737738// Use the opcode to interpret the integer values.739switch (Annot.OpCode) {740case BinaryAnnotationsOpCode::Invalid:741break;742case BinaryAnnotationsOpCode::CodeOffset:743case BinaryAnnotationsOpCode::ChangeCodeOffset:744formatCodeOffset(Annot.U1);745break;746case BinaryAnnotationsOpCode::ChangeLineOffset:747formatLineOffset(Annot.S1);748break;749case BinaryAnnotationsOpCode::ChangeCodeLength:750formatCodeLength(Annot.U1);751// Apparently this annotation updates the code offset. It's hard to make752// MSVC produce this opcode, but clang uses it, and debuggers seem to use753// this interpretation.754CodeOffset += Annot.U1;755break;756case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:757formatCodeOffset(Annot.U1);758formatLineOffset(Annot.S1);759break;760case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:761formatCodeOffset(Annot.U2);762formatCodeLength(Annot.U1);763break;764765case BinaryAnnotationsOpCode::ChangeFile: {766uint32_t FileOffset = Annot.U1;767StringRef Filename = "<unknown>";768if (SymGroup) {769if (Expected<StringRef> MaybeFile =770SymGroup->getNameFromStringTable(FileOffset))771Filename = *MaybeFile;772else773return MaybeFile.takeError();774}775P.format(" setfile {0} 0x{1}", utohexstr(FileOffset));776break;777}778779// The rest of these are hard to convince MSVC to emit, so they are not as780// well understood.781case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:782formatCodeOffset(Annot.U1);783break;784case BinaryAnnotationsOpCode::ChangeLineEndDelta:785case BinaryAnnotationsOpCode::ChangeRangeKind:786case BinaryAnnotationsOpCode::ChangeColumnStart:787case BinaryAnnotationsOpCode::ChangeColumnEnd:788P.format(" {0} {1}", Annot.Name, Annot.U1);789break;790case BinaryAnnotationsOpCode::ChangeColumnEndDelta:791P.format(" {0} {1}", Annot.Name, Annot.S1);792break;793}794}795return Error::success();796}797798Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,799RegisterSym &Register) {800P.format(" `{0}`", Register.Name);801AutoIndent Indent(P, 7);802P.formatLine("register = {0}, type = {1}",803formatRegisterId(Register.Register, CompilationCPU),804typeIndex(Register.Index));805return Error::success();806}807808Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,809PublicSym32 &Public) {810P.format(" `{0}`", Public.Name);811AutoIndent Indent(P, 7);812P.formatLine("flags = {0}, addr = {1}",813formatPublicSymFlags(P.getIndentLevel() + 9, Public.Flags),814formatSegmentOffset(Public.Segment, Public.Offset));815return Error::success();816}817818Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ProcRefSym &PR) {819P.format(" `{0}`", PR.Name);820AutoIndent Indent(P, 7);821P.formatLine("module = {0}, sum name = {1}, offset = {2}", PR.Module,822PR.SumName, PR.SymOffset);823return Error::success();824}825826Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {827P.format(" `{0}` (addr = {1})", Label.Name,828formatSegmentOffset(Label.Segment, Label.CodeOffset));829AutoIndent Indent(P, 7);830P.formatLine("flags = {0}",831formatProcSymFlags(P.getIndentLevel() + 9, Label.Flags));832return Error::success();833}834835Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {836P.format(" `{0}`", Local.Name);837AutoIndent Indent(P, 7);838839std::string FlagStr =840formatLocalSymFlags(P.getIndentLevel() + 9, Local.Flags);841P.formatLine("type={0}, flags = {1}", typeIndex(Local.Type), FlagStr);842return Error::success();843}844845Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,846ObjNameSym &ObjName) {847P.format(" sig={0}, `{1}`", ObjName.Signature, ObjName.Name);848return Error::success();849}850851Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {852P.format(" `{0}`", Proc.Name);853AutoIndent Indent(P, 7);854P.formatLine("parent = {0}, end = {1}, addr = {2}, code size = {3}",855Proc.Parent, Proc.End,856formatSegmentOffset(Proc.Segment, Proc.CodeOffset),857Proc.CodeSize);858bool IsType = true;859switch (Proc.getKind()) {860case SymbolRecordKind::GlobalProcIdSym:861case SymbolRecordKind::ProcIdSym:862case SymbolRecordKind::DPCProcIdSym:863IsType = false;864break;865default:866break;867}868P.formatLine("type = `{0}`, debug start = {1}, debug end = {2}, flags = {3}",869typeOrIdIndex(Proc.FunctionType, IsType), Proc.DbgStart,870Proc.DbgEnd,871formatProcSymFlags(P.getIndentLevel() + 9, Proc.Flags));872return Error::success();873}874875Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,876ScopeEndSym &ScopeEnd) {877return Error::success();878}879880Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {881const char *Format;882switch (CVR.kind()) {883case S_CALLEES:884Format = "callee: {0}";885break;886case S_CALLERS:887Format = "caller: {0}";888break;889case S_INLINEES:890Format = "inlinee: {0}";891break;892default:893return llvm::make_error<CodeViewError>(894"Unknown CV Record type for a CallerSym object!");895}896AutoIndent Indent(P, 7);897for (const auto &I : Caller.Indices) {898P.formatLine(Format, idIndex(I));899}900return Error::success();901}902903Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,904RegRelativeSym &RegRel) {905P.format(" `{0}`", RegRel.Name);906AutoIndent Indent(P, 7);907P.formatLine(908"type = {0}, register = {1}, offset = {2}", typeIndex(RegRel.Type),909formatRegisterId(RegRel.Register, CompilationCPU), RegRel.Offset);910return Error::success();911}912913Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,914ThreadLocalDataSym &Data) {915P.format(" `{0}`", Data.Name);916AutoIndent Indent(P, 7);917P.formatLine("type = {0}, addr = {1}", typeIndex(Data.Type),918formatSegmentOffset(Data.Segment, Data.DataOffset));919return Error::success();920}921922Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {923P.format(" `{0}`", UDT.Name);924AutoIndent Indent(P, 7);925P.formatLine("original type = {0}", UDT.Type);926return Error::success();927}928929Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,930UsingNamespaceSym &UN) {931P.format(" `{0}`", UN.Name);932return Error::success();933}934935Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,936AnnotationSym &Annot) {937AutoIndent Indent(P, 7);938P.formatLine("addr = {0}", formatSegmentOffset(Annot.Segment, Annot.CodeOffset));939P.formatLine("strings = {0}", typesetStringList(P.getIndentLevel() + 9 + 2,940Annot.Strings));941return Error::success();942}943944Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR,945JumpTableSym &JumpTable) {946AutoIndent Indent(P, 7);947P.formatLine(948"base = {0}, switchtype = {1}, branch = {2}, table = {3}, entriescount = "949"{4}",950formatSegmentOffset(JumpTable.BaseSegment, JumpTable.BaseOffset),951formatJumpTableEntrySize(JumpTable.SwitchType),952formatSegmentOffset(JumpTable.BranchSegment, JumpTable.BranchOffset),953formatSegmentOffset(JumpTable.TableSegment, JumpTable.TableOffset),954JumpTable.EntriesCount);955return Error::success();956}957958959