From eb95a535aa521ee8ecf4e8979eb529a82c5d640f Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 13 Feb 2015 07:40:03 +0000 Subject: [PATCH] llvm-pdbdump: Add more comprehensive dumping of symbol types. In particular this patch adds the ability to dump complete function signature information including argument types as correctly formatted strings. A side effect of this is that almost all symbol and meta types are now formatted. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229076 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/PDB/IPDBSession.h | 13 ++ include/llvm/DebugInfo/PDB/PDBExtras.h | 2 + include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h | 1 - lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp | 6 +- lib/DebugInfo/PDB/PDBExtras.cpp | 60 +++++++++ lib/DebugInfo/PDB/PDBSymbolCompiland.cpp | 117 +++++++++--------- lib/DebugInfo/PDB/PDBSymbolData.cpp | 6 +- lib/DebugInfo/PDB/PDBSymbolExe.cpp | 15 +-- lib/DebugInfo/PDB/PDBSymbolFunc.cpp | 15 ++- lib/DebugInfo/PDB/PDBSymbolLabel.cpp | 8 +- lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp | 5 +- lib/DebugInfo/PDB/PDBSymbolThunk.cpp | 34 +++-- lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp | 10 +- lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp | 5 +- lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp | 8 +- lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp | 16 ++- .../PDB/PDBSymbolTypeFunctionArg.cpp | 9 +- .../PDB/PDBSymbolTypeFunctionSig.cpp | 38 +++++- lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp | 13 +- lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp | 17 ++- lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp | 21 +++- lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp | 21 +++- tools/llvm-pdbdump/llvm-pdbdump.cpp | 3 +- 23 files changed, 333 insertions(+), 110 deletions(-) diff --git a/include/llvm/DebugInfo/PDB/IPDBSession.h b/include/llvm/DebugInfo/PDB/IPDBSession.h index 0e0b2c5f68e..a36d65fd9ad 100644 --- a/include/llvm/DebugInfo/PDB/IPDBSession.h +++ b/include/llvm/DebugInfo/PDB/IPDBSession.h @@ -30,6 +30,19 @@ public: virtual std::unique_ptr getGlobalScope() const = 0; virtual std::unique_ptr getSymbolById(uint32_t SymbolId) const = 0; + template + std::unique_ptr getConcreteSymbolById(uint32_t SymbolId) const { + auto Symbol(getSymbolById(SymbolId)); + if (!Symbol) + return nullptr; + + T *ConcreteSymbol = dyn_cast(Symbol.get()); + if (!ConcreteSymbol) + return nullptr; + Symbol.release(); + return std::unique_ptr(ConcreteSymbol); + } + virtual std::unique_ptr getAllSourceFiles() const = 0; virtual std::unique_ptr getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const = 0; diff --git a/include/llvm/DebugInfo/PDB/PDBExtras.h b/include/llvm/DebugInfo/PDB/PDBExtras.h index 1dee6656ede..44c79a57fbf 100644 --- a/include/llvm/DebugInfo/PDB/PDBExtras.h +++ b/include/llvm/DebugInfo/PDB/PDBExtras.h @@ -26,6 +26,7 @@ struct stream_indent { raw_ostream &operator<<(raw_ostream &OS, const stream_indent &Indent); raw_ostream &operator<<(raw_ostream &OS, const PDB_VariantType &Value); +raw_ostream &operator<<(raw_ostream &OS, const PDB_CallingConv &Conv); raw_ostream &operator<<(raw_ostream &OS, const PDB_DataKind &Data); raw_ostream &operator<<(raw_ostream &OS, const PDB_RegisterId &Reg); raw_ostream &operator<<(raw_ostream &OS, const PDB_LocType &Loc); @@ -33,6 +34,7 @@ raw_ostream &operator<<(raw_ostream &OS, const PDB_ThunkOrdinal &Thunk); raw_ostream &operator<<(raw_ostream &OS, const PDB_Checksum &Checksum); raw_ostream &operator<<(raw_ostream &OS, const PDB_Lang &Lang); raw_ostream &operator<<(raw_ostream &OS, const PDB_SymType &Tag); +raw_ostream &operator<<(raw_ostream &OS, const PDB_BuiltinType &Type); raw_ostream &operator<<(raw_ostream &OS, const PDB_UniqueId &Id); raw_ostream &operator<<(raw_ostream &OS, const Variant &Value); diff --git a/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h b/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h index cc8ab370235..1fa358c3eae 100644 --- a/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h +++ b/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h @@ -11,7 +11,6 @@ #define LLVM_DEBUGINFO_PDB_PDBSYMBOLUNKNOWN_H #include "PDBSymbol.h" -#include "PDBTypes.h" namespace llvm { diff --git a/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp b/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp index e9e5ce2fc7b..32239c19da0 100644 --- a/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp +++ b/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp @@ -190,7 +190,7 @@ void DIARawSymbol::dump(raw_ostream &OS, int Indent, RAW_METHOD_DUMP(OS, get_baseDataOffset) RAW_METHOD_DUMP(OS, get_baseDataSlot) RAW_METHOD_DUMP(OS, get_baseSymbolId) - RAW_METHOD_DUMP(OS, get_builtInKind) + RAW_METHOD_DUMP(OS, get_baseType) RAW_METHOD_DUMP(OS, get_bitPosition) RAW_METHOD_DUMP(OS, get_callingConvention) RAW_METHOD_DUMP(OS, get_classParentId) @@ -457,8 +457,8 @@ uint32_t DIARawSymbol::getBaseSymbolId() const { } PDB_BuiltinType DIARawSymbol::getBuiltinType() const { - return PrivateGetDIAValue( - Symbol, &IDiaSymbol::get_builtInKind); + return PrivateGetDIAValue(Symbol, + &IDiaSymbol::get_baseType); } uint32_t DIARawSymbol::getBitPosition() const { diff --git a/lib/DebugInfo/PDB/PDBExtras.cpp b/lib/DebugInfo/PDB/PDBExtras.cpp index 9ead764ae76..8a813c859ff 100644 --- a/lib/DebugInfo/PDB/PDBExtras.cpp +++ b/lib/DebugInfo/PDB/PDBExtras.cpp @@ -44,6 +44,41 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_VariantType &Type) { return OS; } +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_CallingConv &Conv) { + OS << "__"; + switch (Conv) { + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearCdecl, "cdecl", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarCdecl, "cdecl", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearPascal, "pascal", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarPascal, "pascal", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearFastcall, "fastcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarFastcall, "fastcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Skipped, "skippedcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearStdcall, "stdcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarStdcall, "stdcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearSyscall, "syscall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, FarSyscall, "syscall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Thiscall, "thiscall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, MipsCall, "mipscall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Generic, "genericcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Alphacall, "alphacall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Ppccall, "ppccall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, SuperHCall, "superhcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Armcall, "armcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, AM33call, "am33call", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Tricall, "tricall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Sh5call, "sh5call", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, M32R, "m32rcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Clrcall, "clrcall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, Inline, "inlinecall", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_CallingConv, NearVectorcall, "vectorcall", + OS) + default: + OS << "unknowncall"; + } + return OS; +} + raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_DataKind &Data) { switch (Data) { CASE_OUTPUT_ENUM_CLASS_STR(PDB_DataKind, Unknown, "unknown", OS) @@ -216,6 +251,31 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_SymType &Tag) { return OS; } +raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_BuiltinType &Type) { + switch (Type) { + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Void, "void", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Char, "char", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, WCharT, "wchar_t", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Int, "int", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, UInt, "uint", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Float, "float", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, BCD, "BCD", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Bool, "bool", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Long, "long", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, ULong, "ulong", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Currency, "CURRENCY", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Date, "DATE", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Variant, "VARIANT", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Complex, "complex", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Bitfield, "bitfield", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, BSTR, "BSTR", OS) + CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, HResult, "HRESULT", OS) + default: + break; + } + return OS; +} + raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_UniqueId &Id) { static const char *Lookup = "0123456789ABCDEF"; diff --git a/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp b/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp index 39bb9bc90f1..03ebe2b4d4b 100644 --- a/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp @@ -29,70 +29,75 @@ PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession, void PDBSymbolCompiland::dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const { - std::string FullName = getName(); - StringRef Name = llvm::sys::path::filename(StringRef(FullName.c_str())); + if (Level == PDB_DumpLevel::Detailed) { + std::string FullName = getName(); + StringRef Name = llvm::sys::path::filename(StringRef(FullName.c_str())); - OS.indent(Indent); - OS << "Compiland: " << Name << "\n"; + OS.indent(Indent); + OS << "Compiland: " << Name << "\n"; - std::string Source = getSourceFileName(); - std::string Library = getLibraryName(); - if (!Source.empty()) - OS << stream_indent(Indent + 2) << "Source: " << this->getSourceFileName() - << "\n"; - if (!Library.empty()) - OS << stream_indent(Indent + 2) << "Library: " << this->getLibraryName() - << "\n"; + std::string Source = getSourceFileName(); + std::string Library = getLibraryName(); + if (!Source.empty()) + OS << stream_indent(Indent + 2) << "Source: " << this->getSourceFileName() + << "\n"; + if (!Library.empty()) + OS << stream_indent(Indent + 2) << "Library: " << this->getLibraryName() + << "\n"; - TagStats Stats; - auto ChildrenEnum = getChildStats(Stats); - OS << stream_indent(Indent + 2) << "Children: " << Stats << "\n"; - if (Level >= PDB_DumpLevel::Normal) { - while (auto Child = ChildrenEnum->getNext()) { - if (llvm::isa(*Child)) - continue; - if (llvm::isa(*Child)) - continue; - Child->dump(OS, Indent + 4, PDB_DumpLevel::Compact); + TagStats Stats; + auto ChildrenEnum = getChildStats(Stats); + OS << stream_indent(Indent + 2) << "Children: " << Stats << "\n"; + if (Level >= PDB_DumpLevel::Detailed) { + while (auto Child = ChildrenEnum->getNext()) { + if (llvm::isa(*Child)) + continue; + if (llvm::isa(*Child)) + continue; + PDB_DumpLevel ChildLevel = (Level == PDB_DumpLevel::Detailed) + ? PDB_DumpLevel::Normal + : PDB_DumpLevel::Compact; + Child->dump(OS, Indent + 4, ChildLevel); + OS << "\n"; + } } - } - auto DetailsEnum(findAllChildren()); - if (auto CD = DetailsEnum->getNext()) { - VersionInfo FE; - VersionInfo BE; - CD->getFrontEndVersion(FE); - CD->getBackEndVersion(BE); - OS << stream_indent(Indent + 2) << "Compiler: " << CD->getCompilerName() - << "\n"; - OS << stream_indent(Indent + 2) << "Version: " << FE << ", " << BE << "\n"; + auto DetailsEnum(findAllChildren()); + if (auto CD = DetailsEnum->getNext()) { + VersionInfo FE; + VersionInfo BE; + CD->getFrontEndVersion(FE); + CD->getBackEndVersion(BE); + OS << stream_indent(Indent + 2) << "Compiler: " << CD->getCompilerName() + << "\n"; + OS << stream_indent(Indent + 2) << "Version: " << FE << ", " << BE + << "\n"; - OS << stream_indent(Indent + 2) << "Lang: " << CD->getLanguage() << "\n"; - OS << stream_indent(Indent + 2) << "Attributes: "; - if (CD->hasDebugInfo()) - OS << "DebugInfo "; - if (CD->isDataAligned()) - OS << "DataAligned "; - if (CD->isLTCG()) - OS << "LTCG "; - if (CD->hasSecurityChecks()) - OS << "SecurityChecks "; - if (CD->isHotpatchable()) - OS << "HotPatchable"; + OS << stream_indent(Indent + 2) << "Lang: " << CD->getLanguage() << "\n"; + OS << stream_indent(Indent + 2) << "Attributes: "; + if (CD->hasDebugInfo()) + OS << "DebugInfo "; + if (CD->isDataAligned()) + OS << "DataAligned "; + if (CD->isLTCG()) + OS << "LTCG "; + if (CD->hasSecurityChecks()) + OS << "SecurityChecks "; + if (CD->isHotpatchable()) + OS << "HotPatchable"; - OS << "\n"; - auto Files(Session.getSourceFilesForCompiland(*this)); - if (Level >= PDB_DumpLevel::Detailed) { + auto Files(Session.getSourceFilesForCompiland(*this)); + OS << "\n"; OS << stream_indent(Indent + 2) << Files->getChildCount() - << " source files:\n"; - while (auto File = Files->getNext()) - File->dump(OS, Indent + 4, PDB_DumpLevel::Compact); - } else { - OS << stream_indent(Indent + 2) << Files->getChildCount() - << " source files\n"; + << " source files"; + } + uint32_t Count = DetailsEnum->getChildCount(); + if (Count > 1) { + OS << "\n"; + OS << stream_indent(Indent + 2) << "(" << Count - 1 << " more omitted)"; } + } else { + std::string FullName = getName(); + OS << stream_indent(Indent) << "Compiland: " << FullName; } - uint32_t Count = DetailsEnum->getChildCount(); - if (Count > 1) - OS << stream_indent(Indent + 2) << "(" << Count - 1 << " more omitted)\n"; } diff --git a/lib/DebugInfo/PDB/PDBSymbolData.cpp b/lib/DebugInfo/PDB/PDBSymbolData.cpp index 3c4be3ad2d0..9a1ca267131 100644 --- a/lib/DebugInfo/PDB/PDBSymbolData.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolData.cpp @@ -26,7 +26,7 @@ void PDBSymbolData::dump(raw_ostream &OS, int Indent, OS << stream_indent(Indent); PDB_LocType Loc = getLocationType(); PDB_DataKind Kind = getDataKind(); - if (Level == PDB_DumpLevel::Compact) { + if (Level >= PDB_DumpLevel::Normal) { switch (Loc) { case PDB_LocType::Static: { uint32_t RVA = getRelativeVirtualAddress(); @@ -75,6 +75,7 @@ void PDBSymbolData::dump(raw_ostream &OS, int Indent, OS << "???"; } } + OS << "] "; if (Kind == PDB_DataKind::Member || Kind == PDB_DataKind::StaticMember) { uint32_t ClassId = getClassParentId(); @@ -86,6 +87,5 @@ void PDBSymbolData::dump(raw_ostream &OS, int Indent, OS << "::"; } } - OS << getName() << "\n"; - OS.flush(); + OS << getName(); } \ No newline at end of file diff --git a/lib/DebugInfo/PDB/PDBSymbolExe.cpp b/lib/DebugInfo/PDB/PDBSymbolExe.cpp index 4f999d9138e..ddf6efc846f 100644 --- a/lib/DebugInfo/PDB/PDBSymbolExe.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolExe.cpp @@ -27,17 +27,17 @@ void PDBSymbolExe::dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const { std::string FileName(getSymbolsFileName()); - OS << "Summary for " << FileName << "\n"; + OS << stream_indent(Indent) << "Summary for " << FileName << "\n"; uint64_t FileSize = 0; if (!llvm::sys::fs::file_size(FileName, FileSize)) - OS << " Size: " << FileSize << " bytes\n"; + OS << stream_indent(Indent + 2) << "Size: " << FileSize << " bytes\n"; else - OS << " Size: (Unable to obtain file size)\n"; + OS << stream_indent(Indent + 2) << "Size: (Unable to obtain file size)\n"; PDB_UniqueId Guid = getGuid(); - OS << " Guid: " << Guid << "\n"; - OS << " Age: " << getAge() << "\n"; - OS << " Attributes: "; + OS << stream_indent(Indent + 2) << "Guid: " << Guid << "\n"; + OS << stream_indent(Indent + 2) << "Age: " << getAge() << "\n"; + OS << stream_indent(Indent + 2) << "Attributes: "; if (hasCTypes()) OS << "HasCTypes "; if (hasPrivateSymbols()) @@ -48,6 +48,7 @@ void PDBSymbolExe::dump(raw_ostream &OS, int Indent, auto ChildrenEnum = getChildStats(Stats); OS << stream_indent(Indent + 2) << "Children: " << Stats << "\n"; while (auto Child = ChildrenEnum->getNext()) { - Child->dump(OS, Indent+2, PDB_DumpLevel::Compact); + Child->dump(OS, Indent + 4, PDB_DumpLevel::Normal); + OS << "\n"; } } diff --git a/lib/DebugInfo/PDB/PDBSymbolFunc.cpp b/lib/DebugInfo/PDB/PDBSymbolFunc.cpp index 4bd96080c7f..4ae48df2e8c 100644 --- a/lib/DebugInfo/PDB/PDBSymbolFunc.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolFunc.cpp @@ -15,6 +15,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" #include "llvm/Support/Format.h" @@ -26,9 +27,8 @@ PDBSymbolFunc::PDBSymbolFunc(const IPDBSession &PDBSession, void PDBSymbolFunc::dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const { - if (Level == PDB_DumpLevel::Compact) { - OS << stream_indent(Indent); - + OS << stream_indent(Indent); + if (Level >= PDB_DumpLevel::Normal) { uint32_t FuncStart = getRelativeVirtualAddress(); uint32_t FuncEnd = FuncStart + getLength(); if (FuncStart == 0 && FuncEnd == 0) { @@ -53,6 +53,12 @@ void PDBSymbolFunc::dump(raw_ostream &OS, int Indent, OS << "(FPO)"; OS << " "; + uint32_t FuncSigId = getTypeId(); + if (auto FuncSig = Session.getConcreteSymbolById( + FuncSigId)) { + OS << "(" << FuncSig->getCallingConvention() << ") "; + } + uint32_t ClassId = getClassParentId(); if (ClassId != 0) { if (auto Class = Session.getSymbolById(ClassId)) { @@ -63,6 +69,7 @@ void PDBSymbolFunc::dump(raw_ostream &OS, int Indent, } } OS << getName(); - OS << "\n"; + } else { + OS << getName(); } } diff --git a/lib/DebugInfo/PDB/PDBSymbolLabel.cpp b/lib/DebugInfo/PDB/PDBSymbolLabel.cpp index 50d1e2a9b6b..6b2c36e5961 100644 --- a/lib/DebugInfo/PDB/PDBSymbolLabel.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolLabel.cpp @@ -12,6 +12,8 @@ #include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h" +#include "llvm/Support/Format.h" + using namespace llvm; PDBSymbolLabel::PDBSymbolLabel(const IPDBSession &PDBSession, @@ -19,4 +21,8 @@ PDBSymbolLabel::PDBSymbolLabel(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolLabel::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + OS << "label [" << format_hex(getRelativeVirtualAddress(), 10) << "] " + << getName(); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp b/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp index bb4400aeed1..271f52522b4 100644 --- a/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp @@ -19,4 +19,7 @@ PDBSymbolPublicSymbol::PDBSymbolPublicSymbol( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolPublicSymbol::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + OS << "public symbol: " << getName(); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolThunk.cpp b/lib/DebugInfo/PDB/PDBSymbolThunk.cpp index eac1a544d33..dc24507b1d1 100644 --- a/lib/DebugInfo/PDB/PDBSymbolThunk.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolThunk.cpp @@ -22,23 +22,21 @@ PDBSymbolThunk::PDBSymbolThunk(const IPDBSession &PDBSession, void PDBSymbolThunk::dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const { - if (Level == PDB_DumpLevel::Compact) { - OS.indent(Indent); - PDB_ThunkOrdinal Ordinal = getThunkOrdinal(); - uint32_t RVA = getRelativeVirtualAddress(); - if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) { - OS << format_hex(RVA, 10); - } else { - OS << "[" << format_hex(RVA, 10); - OS << " - " << format_hex(RVA + getLength(), 10) << "]"; - } - OS << " thunk(" << Ordinal << ")"; - if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) - OS << " -> " << format_hex(getTargetRelativeVirtualAddress(), 10); - OS << " "; - std::string Name = getName(); - if (!Name.empty()) - OS << Name; - OS << "\n"; + OS.indent(Indent); + OS << "thunk "; + PDB_ThunkOrdinal Ordinal = getThunkOrdinal(); + uint32_t RVA = getRelativeVirtualAddress(); + if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) { + OS << format_hex(RVA, 10); + } else { + OS << "[" << format_hex(RVA, 10); + OS << " - " << format_hex(RVA + getLength(), 10) << "]"; } + OS << " (" << Ordinal << ")"; + if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) + OS << " -> " << format_hex(getTargetRelativeVirtualAddress(), 10); + OS << " "; + std::string Name = getName(); + if (!Name.empty()) + OS << Name; } diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp index 856d3aabef8..3a3c6f1a004 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp @@ -9,6 +9,7 @@ #include +#include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" @@ -19,4 +20,11 @@ PDBSymbolTypeArray::PDBSymbolTypeArray(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeArray::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + if (auto ElementType = Session.getSymbolById(getTypeId())) + ElementType->dump(OS, 0, PDB_DumpLevel::Compact); + else + OS << ""; + OS << "[" << getLength() << "]"; +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp index 31a2e517f3f..5aa73e87a70 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp @@ -19,4 +19,7 @@ PDBSymbolTypeBaseClass::PDBSymbolTypeBaseClass( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeBaseClass::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + OS << " " << getName(); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp index 1a68f8c8ded..8297751a601 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp @@ -19,4 +19,10 @@ PDBSymbolTypeBuiltin::PDBSymbolTypeBuiltin( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeBuiltin::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + PDB_BuiltinType Type = getBuiltinType(); + OS << Type; + if (Type == PDB_BuiltinType::UInt || Type == PDB_BuiltinType::Int) + OS << (8 * getLength()) << "_t"; +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp index 4bc3b7b7860..cc84b1cbee0 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp @@ -9,6 +9,7 @@ #include +#include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" @@ -19,4 +20,17 @@ PDBSymbolTypeEnum::PDBSymbolTypeEnum(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeEnum::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + if (Level >= PDB_DumpLevel::Normal) + OS << "enum "; + + uint32_t ClassId = getClassParentId(); + if (ClassId != 0) { + if (auto ClassParent = Session.getSymbolById(ClassId)) { + ClassParent->dump(OS, 0, Level); + OS << "::"; + } + } + OS << getName(); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp index 86c337d1b04..2f5be7c4d4b 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp @@ -9,6 +9,7 @@ #include +#include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" @@ -19,4 +20,10 @@ PDBSymbolTypeFunctionArg::PDBSymbolTypeFunctionArg( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeFunctionArg::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + uint32_t TypeId = getTypeId(); + if (auto Type = Session.getSymbolById(TypeId)) { + Type->dump(OS, 0, Level); + } +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp index 99953ad21cb..90d009ae531 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp @@ -9,7 +9,11 @@ #include +#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" using namespace llvm; @@ -19,4 +23,36 @@ PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeFunctionSig::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + + uint32_t ReturnTypeId = getTypeId(); + if (auto ReturnType = Session.getSymbolById(ReturnTypeId)) { + ReturnType->dump(OS, 0, PDB_DumpLevel::Compact); + OS << " "; + } + // TODO: We need a way to detect if this is a pointer to function so that we + // can print the * between the return type and the argument list. The only + // way to do this is to pass the parent into this function, but that will + // require a larger interface change. + OS << getCallingConvention() << " "; + uint32_t ClassId = getClassParentId(); + if (ClassId != 0) { + if (auto ClassParent = Session.getSymbolById(ClassId)) { + OS << "("; + ClassParent->dump(OS, 0, PDB_DumpLevel::Compact); + OS << "::*)"; + } + } + OS.flush(); + OS << "("; + if (auto ChildEnum = findAllChildren()) { + uint32_t Index = 0; + while (auto Arg = ChildEnum->getNext()) { + Arg->dump(OS, 0, PDB_DumpLevel::Compact); + if (++Index < ChildEnum->getChildCount()) + OS << ", "; + } + } + OS << ")"; +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp b/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp index a6625b36f79..2fd4314e3e1 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp @@ -10,6 +10,7 @@ #include +#include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" @@ -20,4 +21,14 @@ PDBSymbolTypePointer::PDBSymbolTypePointer( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypePointer::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + if (isConstType()) + OS << "const "; + if (isVolatileType()) + OS << "volatile "; + uint32_t PointeeId = getTypeId(); + if (auto PointeeType = Session.getSymbolById(PointeeId)) + PointeeType->dump(OS, 0, PDB_DumpLevel::Compact); + OS << ((isReference()) ? "&" : "*"); +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp index 74cfeebbb05..c081a5c8c19 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp @@ -23,11 +23,16 @@ PDBSymbolTypeTypedef::PDBSymbolTypeTypedef( void PDBSymbolTypeTypedef::dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const { OS.indent(Indent); - OS << "typedef:" << getName() << " -> "; - std::string TargetTypeName; - auto TypeSymbol = Session.getSymbolById(getTypeId()); - if (PDBSymbolTypeUDT *UDT = dyn_cast(TypeSymbol.get())) { - TargetTypeName = UDT->getName(); + if (Level >= PDB_DumpLevel::Normal) { + std::string Name = getName(); + OS << "typedef:" << Name << " -> "; + std::string TargetTypeName; + uint32_t TargetId = getTypeId(); + if (auto TypeSymbol = Session.getSymbolById(TargetId)) { + TypeSymbol->dump(OS, 0, PDB_DumpLevel::Compact); + } + OS << TargetTypeName; + } else { + OS << getName(); } - OS << TargetTypeName << "\n"; } diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp index 13f6223bcb6..147045a0146 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp @@ -9,6 +9,7 @@ #include +#include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" @@ -19,4 +20,22 @@ PDBSymbolTypeUDT::PDBSymbolTypeUDT(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeUDT::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + if (Level >= PDB_DumpLevel::Normal) + OS << "class "; + + if (isNested()) { + uint32_t ClassId = getClassParentId(); + if (ClassId != 0) { + if (auto ClassParent = Session.getSymbolById(ClassId)) { + ClassParent->dump(OS, 0, Level); + OS << "::"; + } + } + } + OS << getName(); + + if (Level >= PDB_DumpLevel::Normal) + OS << " (" << getLength() << " bytes)"; +} diff --git a/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp b/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp index 31c41d1d268..6eee2ffe3fa 100644 --- a/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp +++ b/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp @@ -9,8 +9,11 @@ #include +#include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h" using namespace llvm; @@ -19,4 +22,20 @@ PDBSymbolTypeVTable::PDBSymbolTypeVTable(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeVTable::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level) const {} + PDB_DumpLevel Level) const { + OS << stream_indent(Indent); + uint32_t ClassId = getClassParentId(); + if (auto ClassParent = Session.getSymbolById(ClassId)) { + ClassParent->dump(OS, 0, PDB_DumpLevel::Compact); + OS << "::"; + } + OS << " "; + if (auto VtblPointer = + Session.getConcreteSymbolById(getTypeId())) { + if (auto VtblShape = + Session.getConcreteSymbolById( + VtblPointer->getTypeId())) + OS << "(" << VtblShape->getCount() << " entries)"; + } + OS.flush(); +} diff --git a/tools/llvm-pdbdump/llvm-pdbdump.cpp b/tools/llvm-pdbdump/llvm-pdbdump.cpp index 6f66a4cef6b..ce79c7933f2 100644 --- a/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -65,7 +65,8 @@ static void dumpInput(StringRef Path) { if (opts::Compilands) { auto Compilands = GlobalScope->findAllChildren(); while (auto Compiland = Compilands->getNext()) { - Compiland->dump(outs(), 0, PDB_DumpLevel::Normal); + Compiland->dump(outs(), 0, PDB_DumpLevel::Detailed); + outs() << "\n"; } } outs().flush(); -- 2.34.1