Index: include/llvm/DebugInfo/CodeView/EnumTables.h =================================================================== --- /dev/null +++ include/llvm/DebugInfo/CodeView/EnumTables.h @@ -0,0 +1,40 @@ +//===- EnumTables.h Enum to string conversion tables ------------*- 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_ENUMTABLES_H +#define LLVM_DEBUGINFO_CODEVIEW_ENUMTABLES_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/Support/COFF.h" +#include "llvm/Support/ScopedPrinter.h" + +#include + +namespace llvm { +namespace codeview { +ArrayRef> getSymbolTypeNames(); +ArrayRef> getRegisterNames(); +ArrayRef> getProcSymFlagNames(); +ArrayRef> getLocalFlagNames(); +ArrayRef> getFrameCookieKindNames(); +ArrayRef> getSourceLanguageNames(); +ArrayRef> getCompileSym2FlagNames(); +ArrayRef> getCompileSym3FlagNames(); +ArrayRef> getCPUTypeNames(); +ArrayRef> getFrameProcSymFlagNames(); +ArrayRef> getExportSymFlagNames(); +ArrayRef> getThunkOrdinalNames(); +ArrayRef> getTrampolineNames(); +ArrayRef> +getImageSectionCharacteristicNames(); +} // namespace codeview +} // namespace llvm + +#endif // LLVM_DEBUGINFO_CODEVIEW_ENUMTABLES_H Index: include/llvm/DebugInfo/CodeView/StreamReader.h =================================================================== --- include/llvm/DebugInfo/CodeView/StreamReader.h +++ include/llvm/DebugInfo/CodeView/StreamReader.h @@ -36,6 +36,14 @@ Error readStreamRef(StreamRef &Ref); Error readStreamRef(StreamRef &Ref, uint32_t Length); + template Error readEnum(T &Dest) { + typename std::underlying_type::type N; + if (auto EC = readInteger(N)) + return EC; + Dest = static_cast(N); + return Error::success(); + } + template Error readObject(const T *&Dest) { ArrayRef Buffer; if (auto EC = readBytes(Buffer, sizeof(T))) Index: include/llvm/DebugInfo/PDB/Raw/DbiStream.h =================================================================== --- include/llvm/DebugInfo/PDB/Raw/DbiStream.h +++ include/llvm/DebugInfo/PDB/Raw/DbiStream.h @@ -17,12 +17,14 @@ #include "llvm/DebugInfo/PDB/Raw/ModInfo.h" #include "llvm/DebugInfo/PDB/Raw/NameHashTable.h" #include "llvm/DebugInfo/PDB/Raw/RawConstants.h" +#include "llvm/DebugInfo/PDB/Raw/RawTypes.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" namespace llvm { namespace pdb { class PDBFile; +class ISectionContribVisitor; class DbiStream { struct HeaderInfo; @@ -50,11 +52,16 @@ PDB_Machine getMachineType() const; + uint32_t getDebugStreamIndex(DbgHeaderType Type) const; + ArrayRef modules() const; - uint32_t getDebugStreamIndex(DbgHeaderType Type) const; + codeview::FixedStreamArray getSectionMap() const; + void visitSectionContributions(ISectionContribVisitor &Visitor) const; private: + Error initializeSectionContributionData(); + Error initializeSectionMapData(); Error initializeFileInfo(); PDBFile &Pdb; @@ -72,6 +79,11 @@ codeview::FixedStreamArray DbgStreams; + PdbRaw_DbiSecContribVer SectionContribVersion; + codeview::FixedStreamArray SectionContribs; + codeview::FixedStreamArray SectionContribs2; + codeview::FixedStreamArray SectionMap; + const HeaderInfo *Header; }; } Index: include/llvm/DebugInfo/PDB/Raw/EnumTables.h =================================================================== --- /dev/null +++ include/llvm/DebugInfo/PDB/Raw/EnumTables.h @@ -0,0 +1,22 @@ +//===- EnumTables.h - Enum to string conversion tables ----------*- 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_PDB_RAW_ENUMTABLES_H +#define LLVM_DEBUGINFO_PDB_RAW_ENUMTABLES_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/Support/ScopedPrinter.h" + +namespace llvm { +namespace pdb { +ArrayRef> getOMFSegMapDescFlagNames(); +} +} + +#endif // LLVM_DEBUGINFO_PDB_RAW_ENUMTABLES_H Index: include/llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h =================================================================== --- /dev/null +++ include/llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h @@ -0,0 +1,28 @@ +//===- ISectionContribVisitor.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_PDB_RAW_ISECTIONCONTRIBVISITOR_H +#define LLVM_DEBUGINFO_PDB_RAW_ISECTIONCONTRIBVISITOR_H + +namespace llvm { +namespace pdb { +struct SectionContrib; +struct SectionContrib2; + +class ISectionContribVisitor { +public: + virtual ~ISectionContribVisitor() {} + + virtual void visit(const SectionContrib &C) = 0; + virtual void visit(const SectionContrib2 &C) = 0; +}; +} // namespace pdb +} // namespace llvm + +#endif // LLVM_DEBUGINFO_PDB_RAW_ISECTIONCONTRIBVISITOR_H Index: include/llvm/DebugInfo/PDB/Raw/PublicsStream.h =================================================================== --- include/llvm/DebugInfo/PDB/Raw/PublicsStream.h +++ include/llvm/DebugInfo/PDB/Raw/PublicsStream.h @@ -15,6 +15,7 @@ #include "llvm/DebugInfo/PDB/PDBTypes.h" #include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Raw/RawConstants.h" +#include "llvm/DebugInfo/PDB/Raw/RawTypes.h" #include "llvm/Support/Error.h" Index: include/llvm/DebugInfo/PDB/Raw/RawConstants.h =================================================================== --- include/llvm/DebugInfo/PDB/Raw/RawConstants.h +++ include/llvm/DebugInfo/PDB/Raw/RawConstants.h @@ -1,4 +1,4 @@ -//===- PDBRawConstants.h ----------------------------------------*- C++ -*-===// +//===- RawConstants.h -------------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -10,7 +10,7 @@ #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H #define LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H -#include "llvm/Support/Endian.h" +#include "llvm/DebugInfo/CodeView/CodeView.h" #include @@ -46,6 +46,11 @@ PdbTpiV80 = 20040203, }; +enum PdbRaw_DbiSecContribVer : uint32_t { + DbiSecContribVer60 = 0xeffe0000 + 19970605, + DbiSecContribV2 = 0xeffe0000 + 20140516 +}; + enum SpecialStream : uint32_t { // Stream 0 contains the copy of previous version of the MSF directory. // We are not currently using it, but technically if we find the main @@ -73,17 +78,14 @@ Max }; -// This struct is defined as "SO" in langapi/include/pdb.h. -struct SectionOffset { - support::ulittle32_t Off; - support::ulittle16_t Isect; - char Padding[2]; -}; - -// This is HRFile. -struct PSHashRecord { - support::ulittle32_t Off; // Offset in the symbol record stream - support::ulittle32_t CRef; +enum class OMFSegDescFlags : uint16_t { + Read = 1 << 0, // Segment is readable. + Write = 1 << 1, // Segment is writable. + Execute = 1 << 2, // Segment is executable. + AddressIs32Bit = 1 << 3, // Descriptor describes a 32-bit linear address. + IsSelector = 1 << 8, // Frame represents a selector. + IsAbsoluteAddress = 1 << 9, // Frame represents an absolute address. + IsGroup = 1 << 10 // If set, descriptor represents a group. }; } // end namespace pdb Index: include/llvm/DebugInfo/PDB/Raw/RawTypes.h =================================================================== --- /dev/null +++ include/llvm/DebugInfo/PDB/Raw/RawTypes.h @@ -0,0 +1,78 @@ +//===- RawTypes.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_PDB_RAW_RAWTYPES_H +#define LLVM_DEBUGINFO_PDB_RAW_RAWTYPES_H + +#include "llvm/Support/Endian.h" + +namespace llvm { +namespace pdb { +// This struct is defined as "SO" in langapi/include/pdb.h. +struct SectionOffset { + support::ulittle32_t Off; + support::ulittle16_t Isect; + char Padding[2]; +}; + +// This is HRFile. +struct PSHashRecord { + support::ulittle32_t Off; // Offset in the symbol record stream + support::ulittle32_t CRef; +}; + +// This struct is defined as `SC` in include/dbicommon.h +struct SectionContrib { + support::ulittle16_t ISect; + char Padding[2]; + support::little32_t Off; + support::little32_t Size; + support::ulittle32_t Characteristics; + support::ulittle16_t Imod; + char Padding2[2]; + support::ulittle32_t DataCrc; + support::ulittle32_t RelocCrc; +}; + +// This struct is defined as `SC2` in include/dbicommon.h +struct SectionContrib2 { + // To guarantee SectionContrib2 is standard layout, we cannot use inheritance. + SectionContrib Base; + support::ulittle32_t ISectCoff; +}; + +// This corresponds to the `OMFSegMap` structure. +struct SecMapHeader { + support::ulittle16_t SecCount; // Number of segment descriptors in table + support::ulittle16_t SecCountLog; // Number of logical segment descriptors +}; + +// This corresponds to the `OMFSegMapDesc` structure. The definition is not +// present in the reference implementation, but the layout is derived from +// code that accesses the fields. +struct SecMapEntry { + support::ulittle16_t Flags; // Descriptor flags. See OMFSegDescFlags + support::ulittle16_t Ovl; // Logical overlay number. + support::ulittle16_t Group; // Group index into descriptor array. + support::ulittle16_t Frame; + support::ulittle16_t SecName; // Byte index of the segment or group name + // in the sstSegName table, or 0xFFFF. + support::ulittle16_t ClassName; // Byte index of the class name in the + // sstSegName table, or 0xFFFF. + support::ulittle32_t Offset; // Byte offset of the logical segment + // within the specified physical segment. + // If group is set in flags, offset is the + // offset of the group. + support::ulittle32_t SecByteLength; // Byte count of the segment or group. +}; + +} // namespace pdb +} // namespace llvm + +#endif Index: lib/DebugInfo/CodeView/CMakeLists.txt =================================================================== --- lib/DebugInfo/CodeView/CMakeLists.txt +++ lib/DebugInfo/CodeView/CMakeLists.txt @@ -1,6 +1,7 @@ add_llvm_library(LLVMDebugInfoCodeView ByteStream.cpp CodeViewError.cpp + EnumTables.cpp FieldListRecordBuilder.cpp Line.cpp ListRecordBuilder.cpp Index: lib/DebugInfo/CodeView/EnumTables.cpp =================================================================== --- /dev/null +++ lib/DebugInfo/CodeView/EnumTables.cpp @@ -0,0 +1,345 @@ +//===- EnumTables.cpp - Enum to string conversion tables --------*- 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/EnumTables.h" + +using namespace llvm; +using namespace codeview; + +#define CV_ENUM_CLASS_ENT(enum_class, enum) \ + { #enum, std::underlying_type < enum_class > ::type(enum_class::enum) } + +#define CV_ENUM_ENT(ns, enum) \ + { #enum, ns::enum } + +static const EnumEntry SymbolTypeNames[] = { +#define CV_SYMBOL(enum, val) {#enum, enum}, +#include "llvm/DebugInfo/CodeView/CVSymbolTypes.def" +#undef CV_SYMBOL +}; + +static const EnumEntry RegisterNames[] = { + CV_ENUM_CLASS_ENT(RegisterId, Unknown), + CV_ENUM_CLASS_ENT(RegisterId, VFrame), + CV_ENUM_CLASS_ENT(RegisterId, AL), + CV_ENUM_CLASS_ENT(RegisterId, CL), + CV_ENUM_CLASS_ENT(RegisterId, DL), + CV_ENUM_CLASS_ENT(RegisterId, BL), + CV_ENUM_CLASS_ENT(RegisterId, AH), + CV_ENUM_CLASS_ENT(RegisterId, CH), + CV_ENUM_CLASS_ENT(RegisterId, DH), + CV_ENUM_CLASS_ENT(RegisterId, BH), + CV_ENUM_CLASS_ENT(RegisterId, AX), + CV_ENUM_CLASS_ENT(RegisterId, CX), + CV_ENUM_CLASS_ENT(RegisterId, DX), + CV_ENUM_CLASS_ENT(RegisterId, BX), + CV_ENUM_CLASS_ENT(RegisterId, SP), + CV_ENUM_CLASS_ENT(RegisterId, BP), + CV_ENUM_CLASS_ENT(RegisterId, SI), + CV_ENUM_CLASS_ENT(RegisterId, DI), + CV_ENUM_CLASS_ENT(RegisterId, EAX), + CV_ENUM_CLASS_ENT(RegisterId, ECX), + CV_ENUM_CLASS_ENT(RegisterId, EDX), + CV_ENUM_CLASS_ENT(RegisterId, EBX), + CV_ENUM_CLASS_ENT(RegisterId, ESP), + CV_ENUM_CLASS_ENT(RegisterId, EBP), + CV_ENUM_CLASS_ENT(RegisterId, ESI), + CV_ENUM_CLASS_ENT(RegisterId, EDI), + CV_ENUM_CLASS_ENT(RegisterId, ES), + CV_ENUM_CLASS_ENT(RegisterId, CS), + CV_ENUM_CLASS_ENT(RegisterId, SS), + CV_ENUM_CLASS_ENT(RegisterId, DS), + CV_ENUM_CLASS_ENT(RegisterId, FS), + CV_ENUM_CLASS_ENT(RegisterId, GS), + CV_ENUM_CLASS_ENT(RegisterId, IP), + CV_ENUM_CLASS_ENT(RegisterId, RAX), + CV_ENUM_CLASS_ENT(RegisterId, RBX), + CV_ENUM_CLASS_ENT(RegisterId, RCX), + CV_ENUM_CLASS_ENT(RegisterId, RDX), + CV_ENUM_CLASS_ENT(RegisterId, RSI), + CV_ENUM_CLASS_ENT(RegisterId, RDI), + CV_ENUM_CLASS_ENT(RegisterId, RBP), + CV_ENUM_CLASS_ENT(RegisterId, RSP), + CV_ENUM_CLASS_ENT(RegisterId, R8), + CV_ENUM_CLASS_ENT(RegisterId, R9), + CV_ENUM_CLASS_ENT(RegisterId, R10), + CV_ENUM_CLASS_ENT(RegisterId, R11), + CV_ENUM_CLASS_ENT(RegisterId, R12), + CV_ENUM_CLASS_ENT(RegisterId, R13), + CV_ENUM_CLASS_ENT(RegisterId, R14), + CV_ENUM_CLASS_ENT(RegisterId, R15), +}; + +static const EnumEntry ProcSymFlagNames[] = { + CV_ENUM_CLASS_ENT(ProcSymFlags, HasFP), + CV_ENUM_CLASS_ENT(ProcSymFlags, HasIRET), + CV_ENUM_CLASS_ENT(ProcSymFlags, HasFRET), + CV_ENUM_CLASS_ENT(ProcSymFlags, IsNoReturn), + CV_ENUM_CLASS_ENT(ProcSymFlags, IsUnreachable), + CV_ENUM_CLASS_ENT(ProcSymFlags, HasCustomCallingConv), + CV_ENUM_CLASS_ENT(ProcSymFlags, IsNoInline), + CV_ENUM_CLASS_ENT(ProcSymFlags, HasOptimizedDebugInfo), +}; + +static const EnumEntry LocalFlags[] = { + CV_ENUM_CLASS_ENT(LocalSymFlags, IsParameter), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsAddressTaken), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsCompilerGenerated), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsAggregate), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsAggregated), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsAliased), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsAlias), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsReturnValue), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsOptimizedOut), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsEnregisteredGlobal), + CV_ENUM_CLASS_ENT(LocalSymFlags, IsEnregisteredStatic), +}; + +static const EnumEntry FrameCookieKinds[] = { + CV_ENUM_CLASS_ENT(FrameCookieKind, Copy), + CV_ENUM_CLASS_ENT(FrameCookieKind, XorStackPointer), + CV_ENUM_CLASS_ENT(FrameCookieKind, XorFramePointer), + CV_ENUM_CLASS_ENT(FrameCookieKind, XorR13), +}; + +static const EnumEntry SourceLanguages[] = { + CV_ENUM_ENT(SourceLanguage, C), CV_ENUM_ENT(SourceLanguage, Cpp), + CV_ENUM_ENT(SourceLanguage, Fortran), CV_ENUM_ENT(SourceLanguage, Masm), + CV_ENUM_ENT(SourceLanguage, Pascal), CV_ENUM_ENT(SourceLanguage, Basic), + CV_ENUM_ENT(SourceLanguage, Cobol), CV_ENUM_ENT(SourceLanguage, Link), + CV_ENUM_ENT(SourceLanguage, Cvtres), CV_ENUM_ENT(SourceLanguage, Cvtpgd), + CV_ENUM_ENT(SourceLanguage, CSharp), CV_ENUM_ENT(SourceLanguage, VB), + CV_ENUM_ENT(SourceLanguage, ILAsm), CV_ENUM_ENT(SourceLanguage, Java), + CV_ENUM_ENT(SourceLanguage, JScript), CV_ENUM_ENT(SourceLanguage, MSIL), + CV_ENUM_ENT(SourceLanguage, HLSL), +}; + +static const EnumEntry CompileSym2FlagNames[] = { + CV_ENUM_CLASS_ENT(CompileSym2Flags, EC), + CV_ENUM_CLASS_ENT(CompileSym2Flags, NoDbgInfo), + CV_ENUM_CLASS_ENT(CompileSym2Flags, LTCG), + CV_ENUM_CLASS_ENT(CompileSym2Flags, NoDataAlign), + CV_ENUM_CLASS_ENT(CompileSym2Flags, ManagedPresent), + CV_ENUM_CLASS_ENT(CompileSym2Flags, SecurityChecks), + CV_ENUM_CLASS_ENT(CompileSym2Flags, HotPatch), + CV_ENUM_CLASS_ENT(CompileSym2Flags, CVTCIL), + CV_ENUM_CLASS_ENT(CompileSym2Flags, MSILModule), +}; + +static const EnumEntry CompileSym3FlagNames[] = { + CV_ENUM_CLASS_ENT(CompileSym3Flags, EC), + CV_ENUM_CLASS_ENT(CompileSym3Flags, NoDbgInfo), + CV_ENUM_CLASS_ENT(CompileSym3Flags, LTCG), + CV_ENUM_CLASS_ENT(CompileSym3Flags, NoDataAlign), + CV_ENUM_CLASS_ENT(CompileSym3Flags, ManagedPresent), + CV_ENUM_CLASS_ENT(CompileSym3Flags, SecurityChecks), + CV_ENUM_CLASS_ENT(CompileSym3Flags, HotPatch), + CV_ENUM_CLASS_ENT(CompileSym3Flags, CVTCIL), + CV_ENUM_CLASS_ENT(CompileSym3Flags, MSILModule), + CV_ENUM_CLASS_ENT(CompileSym3Flags, Sdl), + CV_ENUM_CLASS_ENT(CompileSym3Flags, PGO), + CV_ENUM_CLASS_ENT(CompileSym3Flags, Exp), +}; + +static const EnumEntry CPUTypeNames[] = { + CV_ENUM_CLASS_ENT(CPUType, Intel8080), + CV_ENUM_CLASS_ENT(CPUType, Intel8086), + CV_ENUM_CLASS_ENT(CPUType, Intel80286), + CV_ENUM_CLASS_ENT(CPUType, Intel80386), + CV_ENUM_CLASS_ENT(CPUType, Intel80486), + CV_ENUM_CLASS_ENT(CPUType, Pentium), + CV_ENUM_CLASS_ENT(CPUType, PentiumPro), + CV_ENUM_CLASS_ENT(CPUType, Pentium3), + CV_ENUM_CLASS_ENT(CPUType, MIPS), + CV_ENUM_CLASS_ENT(CPUType, MIPS16), + CV_ENUM_CLASS_ENT(CPUType, MIPS32), + CV_ENUM_CLASS_ENT(CPUType, MIPS64), + CV_ENUM_CLASS_ENT(CPUType, MIPSI), + CV_ENUM_CLASS_ENT(CPUType, MIPSII), + CV_ENUM_CLASS_ENT(CPUType, MIPSIII), + CV_ENUM_CLASS_ENT(CPUType, MIPSIV), + CV_ENUM_CLASS_ENT(CPUType, MIPSV), + CV_ENUM_CLASS_ENT(CPUType, M68000), + CV_ENUM_CLASS_ENT(CPUType, M68010), + CV_ENUM_CLASS_ENT(CPUType, M68020), + CV_ENUM_CLASS_ENT(CPUType, M68030), + CV_ENUM_CLASS_ENT(CPUType, M68040), + CV_ENUM_CLASS_ENT(CPUType, Alpha), + CV_ENUM_CLASS_ENT(CPUType, Alpha21164), + CV_ENUM_CLASS_ENT(CPUType, Alpha21164A), + CV_ENUM_CLASS_ENT(CPUType, Alpha21264), + CV_ENUM_CLASS_ENT(CPUType, Alpha21364), + CV_ENUM_CLASS_ENT(CPUType, PPC601), + CV_ENUM_CLASS_ENT(CPUType, PPC603), + CV_ENUM_CLASS_ENT(CPUType, PPC604), + CV_ENUM_CLASS_ENT(CPUType, PPC620), + CV_ENUM_CLASS_ENT(CPUType, PPCFP), + CV_ENUM_CLASS_ENT(CPUType, PPCBE), + CV_ENUM_CLASS_ENT(CPUType, SH3), + CV_ENUM_CLASS_ENT(CPUType, SH3E), + CV_ENUM_CLASS_ENT(CPUType, SH3DSP), + CV_ENUM_CLASS_ENT(CPUType, SH4), + CV_ENUM_CLASS_ENT(CPUType, SHMedia), + CV_ENUM_CLASS_ENT(CPUType, ARM3), + CV_ENUM_CLASS_ENT(CPUType, ARM4), + CV_ENUM_CLASS_ENT(CPUType, ARM4T), + CV_ENUM_CLASS_ENT(CPUType, ARM5), + CV_ENUM_CLASS_ENT(CPUType, ARM5T), + CV_ENUM_CLASS_ENT(CPUType, ARM6), + CV_ENUM_CLASS_ENT(CPUType, ARM_XMAC), + CV_ENUM_CLASS_ENT(CPUType, ARM_WMMX), + CV_ENUM_CLASS_ENT(CPUType, ARM7), + CV_ENUM_CLASS_ENT(CPUType, Omni), + CV_ENUM_CLASS_ENT(CPUType, Ia64), + CV_ENUM_CLASS_ENT(CPUType, Ia64_2), + CV_ENUM_CLASS_ENT(CPUType, CEE), + CV_ENUM_CLASS_ENT(CPUType, AM33), + CV_ENUM_CLASS_ENT(CPUType, M32R), + CV_ENUM_CLASS_ENT(CPUType, TriCore), + CV_ENUM_CLASS_ENT(CPUType, X64), + CV_ENUM_CLASS_ENT(CPUType, EBC), + CV_ENUM_CLASS_ENT(CPUType, Thumb), + CV_ENUM_CLASS_ENT(CPUType, ARMNT), + CV_ENUM_CLASS_ENT(CPUType, D3D11_Shader), +}; + +static const EnumEntry FrameProcSymFlagNames[] = { + CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasAlloca), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasSetJmp), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasLongJmp), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasInlineAssembly), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasExceptionHandling), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, MarkedInline), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasStructuredExceptionHandling), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, Naked), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, SecurityChecks), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, AsynchronousExceptionHandling), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, NoStackOrderingForSecurityChecks), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, Inlined), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, StrictSecurityChecks), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, SafeBuffers), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, ProfileGuidedOptimization), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, ValidProfileCounts), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, OptimizedForSpeed), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, GuardCfg), + CV_ENUM_CLASS_ENT(FrameProcedureOptions, GuardCfw), +}; + +static const EnumEntry ExportSymFlagNames[] = { + CV_ENUM_CLASS_ENT(ExportFlags, IsConstant), + CV_ENUM_CLASS_ENT(ExportFlags, IsData), + CV_ENUM_CLASS_ENT(ExportFlags, IsPrivate), + CV_ENUM_CLASS_ENT(ExportFlags, HasNoName), + CV_ENUM_CLASS_ENT(ExportFlags, HasExplicitOrdinal), + CV_ENUM_CLASS_ENT(ExportFlags, IsForwarder), +}; + +static const EnumEntry ThunkOrdinalNames[] = { + CV_ENUM_CLASS_ENT(ThunkOrdinal, Standard), + CV_ENUM_CLASS_ENT(ThunkOrdinal, ThisAdjustor), + CV_ENUM_CLASS_ENT(ThunkOrdinal, Vcall), + CV_ENUM_CLASS_ENT(ThunkOrdinal, Pcode), + CV_ENUM_CLASS_ENT(ThunkOrdinal, UnknownLoad), + CV_ENUM_CLASS_ENT(ThunkOrdinal, TrampIncremental), + CV_ENUM_CLASS_ENT(ThunkOrdinal, BranchIsland), +}; + +static const EnumEntry TrampolineNames[] = { + CV_ENUM_CLASS_ENT(TrampolineType, TrampIncremental), + CV_ENUM_CLASS_ENT(TrampolineType, BranchIsland), +}; + +static const EnumEntry + ImageSectionCharacteristicNames[] = { + CV_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NOLOAD), + CV_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NO_PAD), + CV_ENUM_ENT(COFF, IMAGE_SCN_CNT_CODE), + CV_ENUM_ENT(COFF, IMAGE_SCN_CNT_INITIALIZED_DATA), + CV_ENUM_ENT(COFF, IMAGE_SCN_CNT_UNINITIALIZED_DATA), + CV_ENUM_ENT(COFF, IMAGE_SCN_LNK_OTHER), + CV_ENUM_ENT(COFF, IMAGE_SCN_LNK_INFO), + CV_ENUM_ENT(COFF, IMAGE_SCN_LNK_REMOVE), + CV_ENUM_ENT(COFF, IMAGE_SCN_LNK_COMDAT), + CV_ENUM_ENT(COFF, IMAGE_SCN_GPREL), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_PURGEABLE), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_16BIT), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_LOCKED), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_PRELOAD), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_1BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_2BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_4BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_8BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_16BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_32BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_64BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_128BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_256BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_512BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_1024BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_2048BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_4096BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_ALIGN_8192BYTES), + CV_ENUM_ENT(COFF, IMAGE_SCN_LNK_NRELOC_OVFL), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_DISCARDABLE), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_NOT_CACHED), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_NOT_PAGED), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_SHARED), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_EXECUTE), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_READ), + CV_ENUM_ENT(COFF, IMAGE_SCN_MEM_WRITE)}; + +namespace llvm { +namespace codeview { +ArrayRef> getSymbolTypeNames() { + return makeArrayRef(SymbolTypeNames); +} + +ArrayRef> getRegisterNames() { + return makeArrayRef(RegisterNames); +} + +ArrayRef> getProcSymFlagNames() { + return makeArrayRef(ProcSymFlagNames); +} +ArrayRef> getLocalFlagNames() { + return makeArrayRef(LocalFlags); +} +ArrayRef> getFrameCookieKindNames() { + return makeArrayRef(FrameCookieKinds); +} +ArrayRef> getSourceLanguageNames() { + return makeArrayRef(SourceLanguages); +} +ArrayRef> getCompileSym2FlagNames() { + return makeArrayRef(CompileSym2FlagNames); +} +ArrayRef> getCompileSym3FlagNames() { + return makeArrayRef(CompileSym3FlagNames); +} +ArrayRef> getCPUTypeNames() { + return makeArrayRef(CPUTypeNames); +} +ArrayRef> getFrameProcSymFlagNames() { + return makeArrayRef(FrameProcSymFlagNames); +} +ArrayRef> getExportSymFlagNames() { + return makeArrayRef(ExportSymFlagNames); +} +ArrayRef> getThunkOrdinalNames() { + return makeArrayRef(ThunkOrdinalNames); +} +ArrayRef> getTrampolineNames() { + return makeArrayRef(TrampolineNames); +} +ArrayRef> +getImageSectionCharacteristicNames() { + return makeArrayRef(ImageSectionCharacteristicNames); +} +} +} Index: lib/DebugInfo/CodeView/SymbolDumper.cpp =================================================================== --- lib/DebugInfo/CodeView/SymbolDumper.cpp +++ lib/DebugInfo/CodeView/SymbolDumper.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallString.h" #include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h" +#include "llvm/DebugInfo/CodeView/EnumTables.h" #include "llvm/DebugInfo/CodeView/SymbolDumpDelegate.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/DebugInfo/CodeView/TypeDumper.h" @@ -22,249 +23,7 @@ using namespace llvm; using namespace llvm::codeview; -static const EnumEntry SymbolTypeNames[] = { -#define CV_SYMBOL(enum, val) {#enum, enum}, -#include "llvm/DebugInfo/CodeView/CVSymbolTypes.def" -}; - namespace { -#define CV_ENUM_CLASS_ENT(enum_class, enum) \ - { #enum, std::underlying_type < enum_class > ::type(enum_class::enum) } - -#define CV_ENUM_ENT(ns, enum) \ - { #enum, ns::enum } - -static const EnumEntry RegisterNames[] = { - CV_ENUM_CLASS_ENT(RegisterId, Unknown), - CV_ENUM_CLASS_ENT(RegisterId, VFrame), - CV_ENUM_CLASS_ENT(RegisterId, AL), - CV_ENUM_CLASS_ENT(RegisterId, CL), - CV_ENUM_CLASS_ENT(RegisterId, DL), - CV_ENUM_CLASS_ENT(RegisterId, BL), - CV_ENUM_CLASS_ENT(RegisterId, AH), - CV_ENUM_CLASS_ENT(RegisterId, CH), - CV_ENUM_CLASS_ENT(RegisterId, DH), - CV_ENUM_CLASS_ENT(RegisterId, BH), - CV_ENUM_CLASS_ENT(RegisterId, AX), - CV_ENUM_CLASS_ENT(RegisterId, CX), - CV_ENUM_CLASS_ENT(RegisterId, DX), - CV_ENUM_CLASS_ENT(RegisterId, BX), - CV_ENUM_CLASS_ENT(RegisterId, SP), - CV_ENUM_CLASS_ENT(RegisterId, BP), - CV_ENUM_CLASS_ENT(RegisterId, SI), - CV_ENUM_CLASS_ENT(RegisterId, DI), - CV_ENUM_CLASS_ENT(RegisterId, EAX), - CV_ENUM_CLASS_ENT(RegisterId, ECX), - CV_ENUM_CLASS_ENT(RegisterId, EDX), - CV_ENUM_CLASS_ENT(RegisterId, EBX), - CV_ENUM_CLASS_ENT(RegisterId, ESP), - CV_ENUM_CLASS_ENT(RegisterId, EBP), - CV_ENUM_CLASS_ENT(RegisterId, ESI), - CV_ENUM_CLASS_ENT(RegisterId, EDI), - CV_ENUM_CLASS_ENT(RegisterId, ES), - CV_ENUM_CLASS_ENT(RegisterId, CS), - CV_ENUM_CLASS_ENT(RegisterId, SS), - CV_ENUM_CLASS_ENT(RegisterId, DS), - CV_ENUM_CLASS_ENT(RegisterId, FS), - CV_ENUM_CLASS_ENT(RegisterId, GS), - CV_ENUM_CLASS_ENT(RegisterId, IP), - CV_ENUM_CLASS_ENT(RegisterId, RAX), - CV_ENUM_CLASS_ENT(RegisterId, RBX), - CV_ENUM_CLASS_ENT(RegisterId, RCX), - CV_ENUM_CLASS_ENT(RegisterId, RDX), - CV_ENUM_CLASS_ENT(RegisterId, RSI), - CV_ENUM_CLASS_ENT(RegisterId, RDI), - CV_ENUM_CLASS_ENT(RegisterId, RBP), - CV_ENUM_CLASS_ENT(RegisterId, RSP), - CV_ENUM_CLASS_ENT(RegisterId, R8), - CV_ENUM_CLASS_ENT(RegisterId, R9), - CV_ENUM_CLASS_ENT(RegisterId, R10), - CV_ENUM_CLASS_ENT(RegisterId, R11), - CV_ENUM_CLASS_ENT(RegisterId, R12), - CV_ENUM_CLASS_ENT(RegisterId, R13), - CV_ENUM_CLASS_ENT(RegisterId, R14), - CV_ENUM_CLASS_ENT(RegisterId, R15), -}; - -static const EnumEntry ProcSymFlagNames[] = { - CV_ENUM_CLASS_ENT(ProcSymFlags, HasFP), - CV_ENUM_CLASS_ENT(ProcSymFlags, HasIRET), - CV_ENUM_CLASS_ENT(ProcSymFlags, HasFRET), - CV_ENUM_CLASS_ENT(ProcSymFlags, IsNoReturn), - CV_ENUM_CLASS_ENT(ProcSymFlags, IsUnreachable), - CV_ENUM_CLASS_ENT(ProcSymFlags, HasCustomCallingConv), - CV_ENUM_CLASS_ENT(ProcSymFlags, IsNoInline), - CV_ENUM_CLASS_ENT(ProcSymFlags, HasOptimizedDebugInfo), -}; - -static const EnumEntry LocalFlags[] = { - CV_ENUM_CLASS_ENT(LocalSymFlags, IsParameter), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsAddressTaken), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsCompilerGenerated), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsAggregate), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsAggregated), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsAliased), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsAlias), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsReturnValue), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsOptimizedOut), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsEnregisteredGlobal), - CV_ENUM_CLASS_ENT(LocalSymFlags, IsEnregisteredStatic), -}; - -static const EnumEntry FrameCookieKinds[] = { - CV_ENUM_CLASS_ENT(FrameCookieKind, Copy), - CV_ENUM_CLASS_ENT(FrameCookieKind, XorStackPointer), - CV_ENUM_CLASS_ENT(FrameCookieKind, XorFramePointer), - CV_ENUM_CLASS_ENT(FrameCookieKind, XorR13), -}; - -static const EnumEntry SourceLanguages[] = { - CV_ENUM_ENT(SourceLanguage, C), CV_ENUM_ENT(SourceLanguage, Cpp), - CV_ENUM_ENT(SourceLanguage, Fortran), CV_ENUM_ENT(SourceLanguage, Masm), - CV_ENUM_ENT(SourceLanguage, Pascal), CV_ENUM_ENT(SourceLanguage, Basic), - CV_ENUM_ENT(SourceLanguage, Cobol), CV_ENUM_ENT(SourceLanguage, Link), - CV_ENUM_ENT(SourceLanguage, Cvtres), CV_ENUM_ENT(SourceLanguage, Cvtpgd), - CV_ENUM_ENT(SourceLanguage, CSharp), CV_ENUM_ENT(SourceLanguage, VB), - CV_ENUM_ENT(SourceLanguage, ILAsm), CV_ENUM_ENT(SourceLanguage, Java), - CV_ENUM_ENT(SourceLanguage, JScript), CV_ENUM_ENT(SourceLanguage, MSIL), - CV_ENUM_ENT(SourceLanguage, HLSL), -}; - -static const EnumEntry CompileSym2FlagNames[] = { - CV_ENUM_CLASS_ENT(CompileSym2Flags, EC), - CV_ENUM_CLASS_ENT(CompileSym2Flags, NoDbgInfo), - CV_ENUM_CLASS_ENT(CompileSym2Flags, LTCG), - CV_ENUM_CLASS_ENT(CompileSym2Flags, NoDataAlign), - CV_ENUM_CLASS_ENT(CompileSym2Flags, ManagedPresent), - CV_ENUM_CLASS_ENT(CompileSym2Flags, SecurityChecks), - CV_ENUM_CLASS_ENT(CompileSym2Flags, HotPatch), - CV_ENUM_CLASS_ENT(CompileSym2Flags, CVTCIL), - CV_ENUM_CLASS_ENT(CompileSym2Flags, MSILModule), -}; - -static const EnumEntry CompileSym3FlagNames[] = { - CV_ENUM_CLASS_ENT(CompileSym3Flags, EC), - CV_ENUM_CLASS_ENT(CompileSym3Flags, NoDbgInfo), - CV_ENUM_CLASS_ENT(CompileSym3Flags, LTCG), - CV_ENUM_CLASS_ENT(CompileSym3Flags, NoDataAlign), - CV_ENUM_CLASS_ENT(CompileSym3Flags, ManagedPresent), - CV_ENUM_CLASS_ENT(CompileSym3Flags, SecurityChecks), - CV_ENUM_CLASS_ENT(CompileSym3Flags, HotPatch), - CV_ENUM_CLASS_ENT(CompileSym3Flags, CVTCIL), - CV_ENUM_CLASS_ENT(CompileSym3Flags, MSILModule), - CV_ENUM_CLASS_ENT(CompileSym3Flags, Sdl), - CV_ENUM_CLASS_ENT(CompileSym3Flags, PGO), - CV_ENUM_CLASS_ENT(CompileSym3Flags, Exp), -}; - -static const EnumEntry CPUTypeNames[] = { - CV_ENUM_CLASS_ENT(CPUType, Intel8080), - CV_ENUM_CLASS_ENT(CPUType, Intel8086), - CV_ENUM_CLASS_ENT(CPUType, Intel80286), - CV_ENUM_CLASS_ENT(CPUType, Intel80386), - CV_ENUM_CLASS_ENT(CPUType, Intel80486), - CV_ENUM_CLASS_ENT(CPUType, Pentium), - CV_ENUM_CLASS_ENT(CPUType, PentiumPro), - CV_ENUM_CLASS_ENT(CPUType, Pentium3), - CV_ENUM_CLASS_ENT(CPUType, MIPS), - CV_ENUM_CLASS_ENT(CPUType, MIPS16), - CV_ENUM_CLASS_ENT(CPUType, MIPS32), - CV_ENUM_CLASS_ENT(CPUType, MIPS64), - CV_ENUM_CLASS_ENT(CPUType, MIPSI), - CV_ENUM_CLASS_ENT(CPUType, MIPSII), - CV_ENUM_CLASS_ENT(CPUType, MIPSIII), - CV_ENUM_CLASS_ENT(CPUType, MIPSIV), - CV_ENUM_CLASS_ENT(CPUType, MIPSV), - CV_ENUM_CLASS_ENT(CPUType, M68000), - CV_ENUM_CLASS_ENT(CPUType, M68010), - CV_ENUM_CLASS_ENT(CPUType, M68020), - CV_ENUM_CLASS_ENT(CPUType, M68030), - CV_ENUM_CLASS_ENT(CPUType, M68040), - CV_ENUM_CLASS_ENT(CPUType, Alpha), - CV_ENUM_CLASS_ENT(CPUType, Alpha21164), - CV_ENUM_CLASS_ENT(CPUType, Alpha21164A), - CV_ENUM_CLASS_ENT(CPUType, Alpha21264), - CV_ENUM_CLASS_ENT(CPUType, Alpha21364), - CV_ENUM_CLASS_ENT(CPUType, PPC601), - CV_ENUM_CLASS_ENT(CPUType, PPC603), - CV_ENUM_CLASS_ENT(CPUType, PPC604), - CV_ENUM_CLASS_ENT(CPUType, PPC620), - CV_ENUM_CLASS_ENT(CPUType, PPCFP), - CV_ENUM_CLASS_ENT(CPUType, PPCBE), - CV_ENUM_CLASS_ENT(CPUType, SH3), - CV_ENUM_CLASS_ENT(CPUType, SH3E), - CV_ENUM_CLASS_ENT(CPUType, SH3DSP), - CV_ENUM_CLASS_ENT(CPUType, SH4), - CV_ENUM_CLASS_ENT(CPUType, SHMedia), - CV_ENUM_CLASS_ENT(CPUType, ARM3), - CV_ENUM_CLASS_ENT(CPUType, ARM4), - CV_ENUM_CLASS_ENT(CPUType, ARM4T), - CV_ENUM_CLASS_ENT(CPUType, ARM5), - CV_ENUM_CLASS_ENT(CPUType, ARM5T), - CV_ENUM_CLASS_ENT(CPUType, ARM6), - CV_ENUM_CLASS_ENT(CPUType, ARM_XMAC), - CV_ENUM_CLASS_ENT(CPUType, ARM_WMMX), - CV_ENUM_CLASS_ENT(CPUType, ARM7), - CV_ENUM_CLASS_ENT(CPUType, Omni), - CV_ENUM_CLASS_ENT(CPUType, Ia64), - CV_ENUM_CLASS_ENT(CPUType, Ia64_2), - CV_ENUM_CLASS_ENT(CPUType, CEE), - CV_ENUM_CLASS_ENT(CPUType, AM33), - CV_ENUM_CLASS_ENT(CPUType, M32R), - CV_ENUM_CLASS_ENT(CPUType, TriCore), - CV_ENUM_CLASS_ENT(CPUType, X64), - CV_ENUM_CLASS_ENT(CPUType, EBC), - CV_ENUM_CLASS_ENT(CPUType, Thumb), - CV_ENUM_CLASS_ENT(CPUType, ARMNT), - CV_ENUM_CLASS_ENT(CPUType, D3D11_Shader), -}; - -static const EnumEntry FrameProcSymFlags[] = { - CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasAlloca), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasSetJmp), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasLongJmp), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasInlineAssembly), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasExceptionHandling), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, MarkedInline), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, HasStructuredExceptionHandling), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, Naked), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, SecurityChecks), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, AsynchronousExceptionHandling), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, NoStackOrderingForSecurityChecks), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, Inlined), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, StrictSecurityChecks), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, SafeBuffers), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, ProfileGuidedOptimization), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, ValidProfileCounts), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, OptimizedForSpeed), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, GuardCfg), - CV_ENUM_CLASS_ENT(FrameProcedureOptions, GuardCfw), -}; - -static const EnumEntry ExportSymFlags[] = { - CV_ENUM_CLASS_ENT(ExportFlags, IsConstant), - CV_ENUM_CLASS_ENT(ExportFlags, IsData), - CV_ENUM_CLASS_ENT(ExportFlags, IsPrivate), - CV_ENUM_CLASS_ENT(ExportFlags, HasNoName), - CV_ENUM_CLASS_ENT(ExportFlags, HasExplicitOrdinal), - CV_ENUM_CLASS_ENT(ExportFlags, IsForwarder), -}; - -static const EnumEntry ThunkOrdinalNames[] = { - CV_ENUM_CLASS_ENT(ThunkOrdinal, Standard), - CV_ENUM_CLASS_ENT(ThunkOrdinal, ThisAdjustor), - CV_ENUM_CLASS_ENT(ThunkOrdinal, Vcall), - CV_ENUM_CLASS_ENT(ThunkOrdinal, Pcode), - CV_ENUM_CLASS_ENT(ThunkOrdinal, UnknownLoad), - CV_ENUM_CLASS_ENT(ThunkOrdinal, TrampIncremental), - CV_ENUM_CLASS_ENT(ThunkOrdinal, BranchIsland), -}; - -static const EnumEntry TrampolineNames[] = { - CV_ENUM_CLASS_ENT(TrampolineType, TrampIncremental), - CV_ENUM_CLASS_ENT(TrampolineType, BranchIsland), -}; - /// Use this private dumper implementation to keep implementation details about /// the visitor out of SymbolDumper.h. class CVSymbolDumperImpl : public CVSymbolVisitor { @@ -350,13 +109,13 @@ W.printNumber("Off", Thunk.Header.Off); W.printNumber("Seg", Thunk.Header.Seg); W.printNumber("Len", Thunk.Header.Len); - W.printEnum("Ordinal", Thunk.Header.Ord, makeArrayRef(ThunkOrdinalNames)); + W.printEnum("Ordinal", Thunk.Header.Ord, getThunkOrdinalNames()); } void CVSymbolDumperImpl::visitTrampolineSym(SymbolKind Kind, TrampolineSym &Tramp) { DictScope S(W, "Trampoline"); - W.printEnum("Type", Tramp.Header.Type, makeArrayRef(TrampolineNames)); + W.printEnum("Type", Tramp.Header.Type, getTrampolineNames()); W.printNumber("Size", Tramp.Header.Size); W.printNumber("ThunkOff", Tramp.Header.ThunkOff); W.printNumber("TargetOff", Tramp.Header.TargetOff); @@ -371,7 +130,10 @@ W.printNumber("Reserved", Section.Header.Reserved); W.printNumber("Rva", Section.Header.Rva); W.printNumber("Length", Section.Header.Length); - W.printHex("Characteristics", Section.Header.Characteristics); + W.printFlags("Characteristics", Section.Header.Characteristics, + getImageSectionCharacteristicNames(), + COFF::SectionCharacteristics(0x00F00000)); + W.printString("Name", Section.Name); } @@ -379,7 +141,9 @@ CoffGroupSym &CoffGroup) { DictScope S(W, "COFF Group"); W.printNumber("Size", CoffGroup.Header.Size); - W.printHex("Characteristics", CoffGroup.Header.Characteristics); + W.printFlags("Characteristics", CoffGroup.Header.Characteristics, + getImageSectionCharacteristicNames(), + COFF::SectionCharacteristics(0x00F00000)); W.printNumber("Offset", CoffGroup.Header.Offset); W.printNumber("Segment", CoffGroup.Header.Segment); W.printString("Name", CoffGroup.Name); @@ -434,15 +198,14 @@ DictScope S(W, "FileStatic"); W.printNumber("Index", FileStatic.Header.Index); W.printNumber("ModFilenameOffset", FileStatic.Header.ModFilenameOffset); - W.printFlags("Flags", uint16_t(FileStatic.Header.Flags), - makeArrayRef(LocalFlags)); + W.printFlags("Flags", uint16_t(FileStatic.Header.Flags), getLocalFlagNames()); W.printString("Name", FileStatic.Name); } void CVSymbolDumperImpl::visitExportSym(SymbolKind Kind, ExportSym &Export) { DictScope S(W, "Export"); W.printNumber("Ordinal", Export.Header.Ordinal); - W.printFlags("Flags", Export.Header.Flags, makeArrayRef(ExportSymFlags)); + W.printFlags("Flags", Export.Header.Flags, getExportSymFlagNames()); W.printString("Name", Export.Name); } @@ -451,11 +214,10 @@ DictScope S(W, "CompilerFlags2"); W.printEnum("Language", Compile2.Header.getLanguage(), - makeArrayRef(SourceLanguages)); + getSourceLanguageNames()); W.printFlags("Flags", Compile2.Header.flags & ~0xff, - makeArrayRef(CompileSym2FlagNames)); - W.printEnum("Machine", unsigned(Compile2.Header.Machine), - makeArrayRef(CPUTypeNames)); + getCompileSym2FlagNames()); + W.printEnum("Machine", unsigned(Compile2.Header.Machine), getCPUTypeNames()); std::string FrontendVersion; { raw_string_ostream Out(FrontendVersion); @@ -480,11 +242,10 @@ DictScope S(W, "CompilerFlags3"); W.printEnum("Language", Compile3.Header.getLanguage(), - makeArrayRef(SourceLanguages)); + getSourceLanguageNames()); W.printFlags("Flags", Compile3.Header.flags & ~0xff, - makeArrayRef(CompileSym3FlagNames)); - W.printEnum("Machine", unsigned(Compile3.Header.Machine), - makeArrayRef(CPUTypeNames)); + getCompileSym3FlagNames()); + W.printEnum("Machine", unsigned(Compile3.Header.Machine), getCPUTypeNames()); std::string FrontendVersion; { raw_string_ostream Out(FrontendVersion); @@ -634,7 +395,7 @@ } W.printHex("Register", FrameCookie.Header.Register); W.printEnum("CookieKind", uint16_t(FrameCookie.Header.CookieKind), - makeArrayRef(FrameCookieKinds)); + getFrameCookieKindNames()); } void CVSymbolDumperImpl::visitFrameProcSym(SymbolKind Kind, @@ -650,8 +411,7 @@ FrameProc.Header.OffsetOfExceptionHandler); W.printHex("SectionIdOfExceptionHandler", FrameProc.Header.SectionIdOfExceptionHandler); - W.printFlags("Flags", FrameProc.Header.Flags, - makeArrayRef(FrameProcSymFlags)); + W.printFlags("Flags", FrameProc.Header.Flags, getFrameProcSymFlagNames()); } void CVSymbolDumperImpl::visitHeapAllocationSiteSym( @@ -730,8 +490,7 @@ RegisterSym &Register) { DictScope S(W, "RegisterSym"); W.printNumber("Type", Register.Header.Index); - W.printEnum("Seg", uint16_t(Register.Header.Register), - makeArrayRef(RegisterNames)); + W.printEnum("Seg", uint16_t(Register.Header.Register), getRegisterNames()); W.printString("Name", Register.Name); } @@ -762,7 +521,7 @@ } W.printHex("Segment", Label.Header.Segment); W.printHex("Flags", Label.Header.Flags); - W.printFlags("Flags", Label.Header.Flags, makeArrayRef(ProcSymFlagNames)); + W.printFlags("Flags", Label.Header.Flags, getProcSymFlagNames()); W.printString("DisplayName", Label.Name); if (!LinkageName.empty()) W.printString("LinkageName", LinkageName); @@ -772,7 +531,7 @@ DictScope S(W, "Local"); CVTD.printTypeIndex("Type", Local.Header.Type); - W.printFlags("Flags", uint16_t(Local.Header.Flags), makeArrayRef(LocalFlags)); + W.printFlags("Flags", uint16_t(Local.Header.Flags), getLocalFlagNames()); W.printString("VarName", Local.Name); } @@ -805,7 +564,7 @@ } W.printHex("Segment", Proc.Header.Segment); W.printFlags("Flags", static_cast(Proc.Header.Flags), - makeArrayRef(ProcSymFlagNames)); + getProcSymFlagNames()); W.printString("DisplayName", Proc.Name); if (!LinkageName.empty()) W.printString("LinkageName", LinkageName); @@ -863,7 +622,7 @@ void CVSymbolDumperImpl::visitUnknownSymbol(SymbolKind Kind, ArrayRef Data) { DictScope S(W, "UnknownSym"); - W.printEnum("Kind", uint16_t(Kind), makeArrayRef(SymbolTypeNames)); + W.printEnum("Kind", uint16_t(Kind), getSymbolTypeNames()); W.printNumber("Length", uint32_t(Data.size())); } Index: lib/DebugInfo/PDB/CMakeLists.txt =================================================================== --- lib/DebugInfo/PDB/CMakeLists.txt +++ lib/DebugInfo/PDB/CMakeLists.txt @@ -29,6 +29,7 @@ add_pdb_impl_folder(Raw Raw/DbiStream.cpp + Raw/EnumTables.cpp Raw/InfoStream.cpp Raw/MappedBlockStream.cpp Raw/ModInfo.cpp Index: lib/DebugInfo/PDB/Raw/DbiStream.cpp =================================================================== --- lib/DebugInfo/PDB/Raw/DbiStream.cpp +++ lib/DebugInfo/PDB/Raw/DbiStream.cpp @@ -10,14 +10,17 @@ #include "llvm/DebugInfo/CodeView/StreamArray.h" #include "llvm/DebugInfo/CodeView/StreamReader.h" +#include "llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h" #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" #include "llvm/DebugInfo/PDB/Raw/ModInfo.h" #include "llvm/DebugInfo/PDB/Raw/NameHashTable.h" #include "llvm/DebugInfo/PDB/Raw/PDBFile.h" #include "llvm/DebugInfo/PDB/Raw/RawConstants.h" #include "llvm/DebugInfo/PDB/Raw/RawError.h" +#include "llvm/DebugInfo/PDB/Raw/RawTypes.h" using namespace llvm; +using namespace llvm::codeview; using namespace llvm::pdb; using namespace llvm::support; @@ -73,6 +76,20 @@ ulittle32_t Reserved; // Pad to 64 bytes }; +template +Error loadSectionContribs(FixedStreamArray &Output, + StreamReader &Reader) { + if (Reader.bytesRemaining() % sizeof(ContribType) != 0) + return make_error( + raw_error_code::corrupt_file, + "Invalid number of bytes of section contributions"); + + uint32_t Count = Reader.bytesRemaining() / sizeof(ContribType); + if (auto EC = Reader.readArray(Output, Count)) + return EC; + return Error::success(); +} + DbiStream::DbiStream(PDBFile &File) : Pdb(File), Stream(StreamDBI, File), Header(nullptr) { static_assert(sizeof(HeaderInfo) == 64, "Invalid HeaderInfo size!"); @@ -81,7 +98,7 @@ DbiStream::~DbiStream() {} Error DbiStream::reload() { - codeview::StreamReader Reader(Stream); + StreamReader Reader(Stream); if (Stream.getLength() < sizeof(HeaderInfo)) return make_error(raw_error_code::corrupt_file, @@ -98,7 +115,7 @@ // produced in the last decade and allows us to avoid having to // special case all kinds of complicated arcane formats. if (Header->VersionHeader < PdbDbiV70) - return make_error(raw_error_code::corrupt_file, + return make_error(raw_error_code::feature_unsupported, "Unsupported DBI version."); auto InfoStream = Pdb.getPDBInfoStream(); @@ -138,7 +155,7 @@ // Since each ModInfo in the stream is a variable length, we have to iterate // them to know how many there actually are. - codeview::VarStreamArray ModInfoArray; + VarStreamArray ModInfoArray; if (auto EC = Reader.readArray(ModInfoArray, Header->ModiSubstreamSize)) return EC; for (auto &Info : ModInfoArray) { @@ -161,6 +178,12 @@ sizeof(ulittle16_t))) return EC; + if (auto EC = initializeSectionContributionData()) + return EC; + + if (auto EC = initializeSectionMapData()) + return EC; + if (auto EC = initializeFileInfo()) return EC; @@ -168,7 +191,7 @@ return make_error(raw_error_code::corrupt_file, "Found unexpected bytes in DBI Stream."); - codeview::StreamReader ECReader(ECSubstream); + StreamReader ECReader(ECSubstream); if (auto EC = ECNames.load(ECReader)) return EC; @@ -222,6 +245,44 @@ } ArrayRef DbiStream::modules() const { return ModuleInfos; } +codeview::FixedStreamArray DbiStream::getSectionMap() const { + return SectionMap; +} + +void llvm::pdb::DbiStream::visitSectionContributions( + ISectionContribVisitor &Visitor) const { + if (SectionContribVersion == DbiSecContribVer60) { + for (auto &SC : SectionContribs) + Visitor.visit(SC); + } else if (SectionContribVersion == DbiSecContribV2) { + for (auto &SC : SectionContribs2) + Visitor.visit(SC); + } +} + +Error DbiStream::initializeSectionContributionData() { + StreamReader SCReader(SecContrSubstream); + if (auto EC = SCReader.readEnum(SectionContribVersion)) + return EC; + + if (SectionContribVersion == DbiSecContribVer60) + return loadSectionContribs(SectionContribs, SCReader); + if (SectionContribVersion == DbiSecContribV2) + return loadSectionContribs(SectionContribs2, SCReader); + + return make_error(raw_error_code::feature_unsupported, + "Unsupported DBI Section Contribution version"); +} + +Error DbiStream::initializeSectionMapData() { + StreamReader SMReader(SecMapSubstream); + const SecMapHeader *Header; + if (auto EC = SMReader.readObject(Header)) + return EC; + if (auto EC = SMReader.readArray(SectionMap, Header->SecCount)) + return EC; + return Error::success(); +} Error DbiStream::initializeFileInfo() { struct FileInfoSubstreamHeader { @@ -246,7 +307,7 @@ // it is computed by summing `ModFileCounts`. // const FileInfoSubstreamHeader *FH; - codeview::StreamReader FISR(FileInfoSubstream); + StreamReader FISR(FileInfoSubstream); if (auto EC = FISR.readObject(FH)) return EC; @@ -256,9 +317,9 @@ return make_error(raw_error_code::corrupt_file, "FileInfo substream count doesn't match DBI."); - codeview::FixedStreamArray ModIndexArray; - codeview::FixedStreamArray ModFileCountArray; - codeview::FixedStreamArray FileNameOffsets; + FixedStreamArray ModIndexArray; + FixedStreamArray ModFileCountArray; + FixedStreamArray FileNameOffsets; // First is an array of `NumModules` module indices. This is not used for the // same reason that `NumSourceFiles` is not used. It's an array of uint16's, @@ -286,10 +347,10 @@ if (auto EC = FISR.readArray(FileNameOffsets, NumSourceFiles)) return EC; - codeview::StreamRef NamesBufferRef; + StreamRef NamesBufferRef; if (auto EC = FISR.readStreamRef(NamesBufferRef)) return EC; - codeview::StreamReader Names(NamesBufferRef); + StreamReader Names(NamesBufferRef); // We go through each ModuleInfo, determine the number N of source files for // that module, and then get the next N offsets from the Offsets array, using Index: lib/DebugInfo/PDB/Raw/EnumTables.cpp =================================================================== --- /dev/null +++ lib/DebugInfo/PDB/Raw/EnumTables.cpp @@ -0,0 +1,38 @@ +//===- EnumTables.cpp - Enum to string conversion tables --------*- 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/PDB/Raw/EnumTables.h" +#include "llvm/DebugInfo/PDB/Raw/RawConstants.h" + +using namespace llvm; +using namespace llvm::pdb; + +#define PDB_ENUM_CLASS_ENT(enum_class, enum) \ + { #enum, std::underlying_type < enum_class > ::type(enum_class::enum) } + +#define PDB_ENUM_ENT(ns, enum) \ + { #enum, ns::enum } + +static const EnumEntry OMFSegMapDescFlagNames[] = { + PDB_ENUM_CLASS_ENT(OMFSegDescFlags, Read), + PDB_ENUM_CLASS_ENT(OMFSegDescFlags, Write), + PDB_ENUM_CLASS_ENT(OMFSegDescFlags, Execute), + PDB_ENUM_CLASS_ENT(OMFSegDescFlags, AddressIs32Bit), + PDB_ENUM_CLASS_ENT(OMFSegDescFlags, IsSelector), + PDB_ENUM_CLASS_ENT(OMFSegDescFlags, IsAbsoluteAddress), + PDB_ENUM_CLASS_ENT(OMFSegDescFlags, IsGroup), +}; + +namespace llvm { +namespace pdb { +ArrayRef> getOMFSegMapDescFlagNames() { + return makeArrayRef(OMFSegMapDescFlagNames); +} +} +} \ No newline at end of file Index: lib/DebugInfo/PDB/Raw/ModStream.cpp =================================================================== --- lib/DebugInfo/PDB/Raw/ModStream.cpp +++ lib/DebugInfo/PDB/Raw/ModStream.cpp @@ -45,6 +45,10 @@ return EC; if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size)) return EC; + ArrayRef LineBytes; + codeview::StreamReader LinesReader(C13LinesSubstream); + if (auto EC = LinesReader.readBytes(LineBytes, C13LinesSubstream.getLength())) + return EC; uint32_t GlobalRefsSize; if (auto EC = Reader.readInteger(GlobalRefsSize)) Index: test/DebugInfo/PDB/pdbdump-headers.test =================================================================== --- test/DebugInfo/PDB/pdbdump-headers.test +++ test/DebugInfo/PDB/pdbdump-headers.test @@ -417,7 +417,11 @@ ; EMPTY-NEXT: Reserved: 0 ; EMPTY-NEXT: Rva: 4096 ; EMPTY-NEXT: Length: 4122 -; EMPTY-NEXT: Characteristics: 0x60000020 +; EMPTY-NEXT: Characteristics [ (0x60000020) +; EMPTY-NEXT: IMAGE_SCN_CNT_CODE (0x20) +; EMPTY-NEXT: IMAGE_SCN_MEM_EXECUTE (0x20000000) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Name: .text ; EMPTY-NEXT: } ; EMPTY-NEXT: Bytes ( @@ -428,7 +432,11 @@ ; EMPTY-NEXT: { ; EMPTY-NEXT: COFF Group { ; EMPTY-NEXT: Size: 4122 -; EMPTY-NEXT: Characteristics: 0x60000020 +; EMPTY-NEXT: Characteristics [ (0x60000020) +; EMPTY-NEXT: IMAGE_SCN_CNT_CODE (0x20) +; EMPTY-NEXT: IMAGE_SCN_MEM_EXECUTE (0x20000000) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Offset: 0 ; EMPTY-NEXT: Segment: 1 ; EMPTY-NEXT: Name: .text$mn @@ -445,7 +453,10 @@ ; EMPTY-NEXT: Reserved: 0 ; EMPTY-NEXT: Rva: 12288 ; EMPTY-NEXT: Length: 690 -; EMPTY-NEXT: Characteristics: 0x40000040 +; EMPTY-NEXT: Characteristics [ (0x40000040) +; EMPTY-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Name: .rdata ; EMPTY-NEXT: } ; EMPTY-NEXT: Bytes ( @@ -456,7 +467,10 @@ ; EMPTY-NEXT: { ; EMPTY-NEXT: COFF Group { ; EMPTY-NEXT: Size: 323 -; EMPTY-NEXT: Characteristics: 0x40000040 +; EMPTY-NEXT: Characteristics [ (0x40000040) +; EMPTY-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Offset: 0 ; EMPTY-NEXT: Segment: 2 ; EMPTY-NEXT: Name: .rdata @@ -469,7 +483,10 @@ ; EMPTY-NEXT: { ; EMPTY-NEXT: COFF Group { ; EMPTY-NEXT: Size: 0 -; EMPTY-NEXT: Characteristics: 0x40000040 +; EMPTY-NEXT: Characteristics [ (0x40000040) +; EMPTY-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Offset: 323 ; EMPTY-NEXT: Segment: 2 ; EMPTY-NEXT: Name: .edata @@ -482,7 +499,10 @@ ; EMPTY-NEXT: { ; EMPTY-NEXT: COFF Group { ; EMPTY-NEXT: Size: 366 -; EMPTY-NEXT: Characteristics: 0x40000040 +; EMPTY-NEXT: Characteristics [ (0x40000040) +; EMPTY-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Offset: 324 ; EMPTY-NEXT: Segment: 2 ; EMPTY-NEXT: Name: .rdata$debug @@ -499,7 +519,11 @@ ; EMPTY-NEXT: Reserved: 0 ; EMPTY-NEXT: Rva: 16384 ; EMPTY-NEXT: Length: 4 -; EMPTY-NEXT: Characteristics: 0xC0000040 +; EMPTY-NEXT: Characteristics [ (0xC0000040) +; EMPTY-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Name: .data ; EMPTY-NEXT: } ; EMPTY-NEXT: Bytes ( @@ -510,7 +534,11 @@ ; EMPTY-NEXT: { ; EMPTY-NEXT: COFF Group { ; EMPTY-NEXT: Size: 4 -; EMPTY-NEXT: Characteristics: 0xC0000080 +; EMPTY-NEXT: Characteristics [ (0xC0000080) +; EMPTY-NEXT: IMAGE_SCN_CNT_UNINITIALIZED_DATA (0x80) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Offset: 0 ; EMPTY-NEXT: Segment: 3 ; EMPTY-NEXT: Name: .bss @@ -527,7 +555,11 @@ ; EMPTY-NEXT: Reserved: 0 ; EMPTY-NEXT: Rva: 20480 ; EMPTY-NEXT: Length: 8 -; EMPTY-NEXT: Characteristics: 0x42000040 +; EMPTY-NEXT: Characteristics [ (0x42000040) +; EMPTY-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; EMPTY-NEXT: IMAGE_SCN_MEM_DISCARDABLE (0x2000000) +; EMPTY-NEXT: IMAGE_SCN_MEM_READ (0x40000000) +; EMPTY-NEXT: ] ; EMPTY-NEXT: Name: .reloc ; EMPTY-NEXT: } ; EMPTY-NEXT: Bytes ( @@ -935,14 +967,22 @@ ; ALL: Reserved: 0 ; ALL: Rva: 4096 ; ALL: Length: 4122 -; ALL: Characteristics: 0x60000020 +; ALL: Characteristics [ (0x60000020) +; ALL: IMAGE_SCN_CNT_CODE (0x20) +; ALL: IMAGE_SCN_MEM_EXECUTE (0x20000000) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] ; ALL: Name: .text ; ALL: } ; ALL: } ; ALL: { ; ALL: COFF Group { ; ALL: Size: 4122 -; ALL: Characteristics: 0x60000020 +; ALL: Characteristics [ (0x60000020) +; ALL: IMAGE_SCN_CNT_CODE (0x20) +; ALL: IMAGE_SCN_MEM_EXECUTE (0x20000000) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] ; ALL: Offset: 0 ; ALL: Segment: 1 ; ALL: Name: .text$mn @@ -955,14 +995,20 @@ ; ALL: Reserved: 0 ; ALL: Rva: 12288 ; ALL: Length: 690 -; ALL: Characteristics: 0x40000040 +; ALL: Characteristics [ (0x40000040) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] ; ALL: Name: .rdata ; ALL: } ; ALL: } ; ALL: { ; ALL: COFF Group { ; ALL: Size: 323 -; ALL: Characteristics: 0x40000040 +; ALL: Characteristics [ (0x40000040) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] ; ALL: Offset: 0 ; ALL: Segment: 2 ; ALL: Name: .rdata @@ -971,7 +1017,10 @@ ; ALL: { ; ALL: COFF Group { ; ALL: Size: 0 -; ALL: Characteristics: 0x40000040 +; ALL: Characteristics [ (0x40000040) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] ; ALL: Offset: 323 ; ALL: Segment: 2 ; ALL: Name: .edata @@ -980,7 +1029,10 @@ ; ALL: { ; ALL: COFF Group { ; ALL: Size: 366 -; ALL: Characteristics: 0x40000040 +; ALL: Characteristics [ (0x40000040) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] ; ALL: Offset: 324 ; ALL: Segment: 2 ; ALL: Name: .rdata$debug @@ -993,14 +1045,22 @@ ; ALL: Reserved: 0 ; ALL: Rva: 16384 ; ALL: Length: 4 -; ALL: Characteristics: 0xC0000040 +; ALL: Characteristics [ (0xC0000040) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: IMAGE_SCN_MEM_WRITE (0x80000000) +; ALL: ] ; ALL: Name: .data ; ALL: } ; ALL: } ; ALL: { ; ALL: COFF Group { ; ALL: Size: 4 -; ALL: Characteristics: 0xC0000080 +; ALL: Characteristics [ (0xC0000080) +; ALL: IMAGE_SCN_CNT_UNINITIALIZED_DATA (0x80) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: IMAGE_SCN_MEM_WRITE (0x80000000) +; ALL: ] ; ALL: Offset: 0 ; ALL: Segment: 3 ; ALL: Name: .bss @@ -1013,7 +1073,11 @@ ; ALL: Reserved: 0 ; ALL: Rva: 20480 ; ALL: Length: 8 -; ALL: Characteristics: 0x42000040 +; ALL: Characteristics [ (0x42000040) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_DISCARDABLE (0x2000000) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] ; ALL: Name: .reloc ; ALL: } ; ALL: } @@ -1021,6 +1085,157 @@ ; ALL: } ; ALL: ] ; ALL: } +; ALL: Section Contributions [ +; ALL: Contribution { +; ALL: ISect: 1 +; ALL: Off: 0 +; ALL: Size: 10 +; ALL: Characteristics [ (0x60000020) +; ALL: IMAGE_SCN_CNT_CODE (0x20) +; ALL: IMAGE_SCN_MEM_EXECUTE (0x20000000) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] +; ALL: Module { +; ALL: Index: 1 +; ALL: Name: * Linker * +; ALL: } +; ALL: Data CRC: 0 +; ALL: Reloc CRC: 0 +; ALL: } +; ALL: Contribution { +; ALL: ISect: 1 +; ALL: Off: 16 +; ALL: Size: 10 +; ALL: Characteristics [ (0x60500020) +; ALL: IMAGE_SCN_ALIGN_16BYTES (0x500000) +; ALL: IMAGE_SCN_CNT_CODE (0x20) +; ALL: IMAGE_SCN_MEM_EXECUTE (0x20000000) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] +; ALL: Module { +; ALL: Index: 0 +; ALL: Name: d:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj +; ALL: } +; ALL: Data CRC: 3617027124 +; ALL: Reloc CRC: 0 +; ALL: } +; ALL: Contribution { +; ALL: ISect: 2 +; ALL: Off: 0 +; ALL: Size: 56 +; ALL: Characteristics [ (0x40000040) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] +; ALL: Module { +; ALL: Index: 1 +; ALL: Name: * Linker * +; ALL: } +; ALL: Data CRC: 0 +; ALL: Reloc CRC: 0 +; ALL: } +; ALL: Contribution { +; ALL: ISect: 2 +; ALL: Off: 324 +; ALL: Size: 72 +; ALL: Characteristics [ (0x40300040) +; ALL: IMAGE_SCN_ALIGN_4BYTES (0x300000) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] +; ALL: Module { +; ALL: Index: 1 +; ALL: Name: * Linker * +; ALL: } +; ALL: Data CRC: 0 +; ALL: Reloc CRC: 0 +; ALL: } +; ALL: Contribution { +; ALL: ISect: 2 +; ALL: Off: 396 +; ALL: Size: 20 +; ALL: Characteristics [ (0x40300040) +; ALL: IMAGE_SCN_ALIGN_4BYTES (0x300000) +; ALL: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: ] +; ALL: Module { +; ALL: Index: 1 +; ALL: Name: * Linker * +; ALL: } +; ALL: Data CRC: 0 +; ALL: Reloc CRC: 0 +; ALL: } +; ALL: Contribution { +; ALL: ISect: 3 +; ALL: Off: 0 +; ALL: Size: 4 +; ALL: Characteristics [ (0xC0300080) +; ALL: IMAGE_SCN_ALIGN_4BYTES (0x300000) +; ALL: IMAGE_SCN_CNT_UNINITIALIZED_DATA (0x80) +; ALL: IMAGE_SCN_MEM_READ (0x40000000) +; ALL: IMAGE_SCN_MEM_WRITE (0x80000000) +; ALL: ] +; ALL: Module { +; ALL: Index: 0 +; ALL: Name: d:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj +; ALL: } +; ALL: Data CRC: 0 +; ALL: Reloc CRC: 0 +; ALL: } +; ALL: ] +; ALL: Section Map [ +; ALL: Entry { +; ALL: Flags: 269 +; ALL: Ovl: 0 +; ALL: Group: 0 +; ALL: Frame: 1 +; ALL: SecName: 65535 +; ALL: ClassName: 65535 +; ALL: Offset: 0 +; ALL: SecByteLength: 4122 +; ALL: } +; ALL: Entry { +; ALL: Flags: 265 +; ALL: Ovl: 0 +; ALL: Group: 0 +; ALL: Frame: 2 +; ALL: SecName: 65535 +; ALL: ClassName: 65535 +; ALL: Offset: 0 +; ALL: SecByteLength: 690 +; ALL: } +; ALL: Entry { +; ALL: Flags: 267 +; ALL: Ovl: 0 +; ALL: Group: 0 +; ALL: Frame: 3 +; ALL: SecName: 65535 +; ALL: ClassName: 65535 +; ALL: Offset: 0 +; ALL: SecByteLength: 4 +; ALL: } +; ALL: Entry { +; ALL: Flags: 265 +; ALL: Ovl: 0 +; ALL: Group: 0 +; ALL: Frame: 4 +; ALL: SecName: 65535 +; ALL: ClassName: 65535 +; ALL: Offset: 0 +; ALL: SecByteLength: 8 +; ALL: } +; ALL: Entry { +; ALL: Flags: 520 +; ALL: Ovl: 0 +; ALL: Group: 0 +; ALL: Frame: 0 +; ALL: SecName: 65535 +; ALL: ClassName: 65535 +; ALL: Offset: 0 +; ALL: SecByteLength: 4294967295 +; ALL: } +; ALL: ] ; ALL: Publics Stream { ; ALL: Stream number: 7 ; ALL: SymHash: 556 Index: tools/llvm-pdbdump/llvm-pdbdump.cpp =================================================================== --- tools/llvm-pdbdump/llvm-pdbdump.cpp +++ tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -26,6 +26,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" +#include "llvm/DebugInfo/CodeView/EnumTables.h" #include "llvm/DebugInfo/CodeView/StreamReader.h" #include "llvm/DebugInfo/CodeView/SymbolDumper.h" #include "llvm/DebugInfo/CodeView/TypeDumper.h" @@ -40,6 +41,8 @@ #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" #include "llvm/DebugInfo/PDB/Raw/DbiStream.h" +#include "llvm/DebugInfo/PDB/Raw/EnumTables.h" +#include "llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h" #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" #include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Raw/ModInfo.h" @@ -50,6 +53,7 @@ #include "llvm/DebugInfo/PDB/Raw/RawError.h" #include "llvm/DebugInfo/PDB/Raw/RawSession.h" #include "llvm/DebugInfo/PDB/Raw/TpiStream.h" +#include "llvm/Support/COM.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/FileSystem.h" @@ -62,13 +66,6 @@ #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" -#if defined(HAVE_DIA_SDK) -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include -#endif - using namespace llvm; using namespace llvm::pdb; @@ -143,6 +140,11 @@ cl::cat(NativeOptions)); cl::opt DumpPublics("raw-publics", cl::desc("dump Publics stream data"), cl::cat(NativeOptions)); +cl::opt DumpSectionContribs("raw-section-contribs", + cl::desc("dump section contributions"), + cl::cat(NativeOptions)); +cl::opt DumpSectionMap("raw-section-map", cl::desc("dump section map"), + cl::cat(NativeOptions)); cl::opt DumpSymRecordBytes("raw-sym-record-bytes", cl::desc("dump CodeView symbol record raw bytes"), @@ -505,6 +507,78 @@ return Error::success(); } +static Error dumpSectionContribs(ScopedPrinter &P, PDBFile &File) { + if (!opts::DumpSectionContribs) + return Error::success(); + + auto DbiS = File.getPDBDbiStream(); + if (auto EC = DbiS.takeError()) + return EC; + DbiStream &DS = DbiS.get(); + ListScope L(P, "Section Contributions"); + class Visitor : public ISectionContribVisitor { + public: + Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {} + void visit(const SectionContrib &SC) override { + DictScope D(P, "Contribution"); + P.printNumber("ISect", SC.ISect); + P.printNumber("Off", SC.Off); + P.printNumber("Size", SC.Size); + P.printFlags("Characteristics", SC.Characteristics, + codeview::getImageSectionCharacteristicNames(), + COFF::SectionCharacteristics(0x00F00000)); + { + DictScope DD(P, "Module"); + P.printNumber("Index", SC.Imod); + auto M = DS.modules(); + if (M.size() > SC.Imod) { + P.printString("Name", M[SC.Imod].Info.getModuleName()); + } + } + P.printNumber("Data CRC", SC.DataCrc); + P.printNumber("Reloc CRC", SC.RelocCrc); + P.flush(); + } + void visit(const SectionContrib2 &SC) override { + visit(SC.Base); + P.printNumber("ISect Coff", SC.ISectCoff); + P.flush(); + } + + private: + ScopedPrinter &P; + DbiStream &DS; + }; + Visitor V(P, DS); + DS.visitSectionContributions(V); + return Error::success(); +} + +static Error dumpSectionMap(ScopedPrinter &P, PDBFile &File) { + if (!opts::DumpSectionMap) + return Error::success(); + + auto DbiS = File.getPDBDbiStream(); + if (auto EC = DbiS.takeError()) + return EC; + DbiStream &DS = DbiS.get(); + ListScope L(P, "Section Map"); + for (auto &M : DS.getSectionMap()) { + DictScope D(P, "Entry"); + P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames()); + P.printNumber("Flags", M.Flags); + P.printNumber("Ovl", M.Ovl); + P.printNumber("Group", M.Group); + P.printNumber("Frame", M.Frame); + P.printNumber("SecName", M.SecName); + P.printNumber("ClassName", M.ClassName); + P.printNumber("Offset", M.Offset); + P.printNumber("SecByteLength", M.SecByteLength); + P.flush(); + } + return Error::success(); +} + static Error dumpTpiStream(ScopedPrinter &P, PDBFile &File, codeview::CVTypeDumper &TD, uint32_t StreamIdx) { assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI); @@ -648,8 +722,15 @@ if (auto EC = dumpDbiStream(P, File, TD)) return EC; + if (auto EC = dumpSectionContribs(P, File)) + return EC; + + if (auto EC = dumpSectionMap(P, File)) + return EC; + if (auto EC = dumpPublicsStream(P, File, TD)) return EC; + return Error::success(); } @@ -682,6 +763,10 @@ return true; if (opts::DumpIpiRecordBytes) return true; + if (opts::DumpSectionContribs) + return true; + if (opts::DumpSectionMap) + return true; return false; } @@ -846,6 +931,8 @@ opts::DumpStreamBlocks = true; opts::DumpTpiRecords = true; opts::DumpIpiRecords = true; + opts::DumpSectionMap = true; + opts::DumpSectionContribs = true; } // When adding filters for excluded compilands and types, we need to remember @@ -864,16 +951,11 @@ opts::ExcludeCompilands.push_back("d:\\\\th.obj.x86fre\\\\minkernel"); } -#if defined(HAVE_DIA_SDK) - CoInitializeEx(nullptr, COINIT_MULTITHREADED); -#endif + llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded); std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(), dumpInput); -#if defined(HAVE_DIA_SDK) - CoUninitialize(); -#endif outs().flush(); return 0; }