diff options
Diffstat (limited to 'llvm')
19 files changed, 297 insertions, 1 deletions
diff --git a/llvm/include/llvm/DebugInfo/PDB/DIA/DIAEnumTables.h b/llvm/include/llvm/DebugInfo/PDB/DIA/DIAEnumTables.h new file mode 100644 index 00000000000..926fcfe6964 --- /dev/null +++ b/llvm/include/llvm/DebugInfo/PDB/DIA/DIAEnumTables.h @@ -0,0 +1,37 @@ +//===- DIAEnumTables.h - DIA Tables Enumerator Impl -------------*- 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_DIA_DIAENUMTABLES_H +#define LLVM_DEBUGINFO_PDB_DIA_DIAENUMTABLES_H + +#include "DIASupport.h" +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/IPDBTable.h" + +namespace llvm { +namespace pdb { +class IPDBTable; + +class DIAEnumTables : public IPDBEnumChildren<IPDBTable> { +public: + explicit DIAEnumTables(CComPtr<IDiaEnumTables> DiaEnumerator); + + uint32_t getChildCount() const override; + std::unique_ptr<IPDBTable> getChildAtIndex(uint32_t Index) const override; + std::unique_ptr<IPDBTable> getNext() override; + void reset() override; + DIAEnumTables *clone() const override; + +private: + CComPtr<IDiaEnumTables> Enumerator; +}; +} +} + +#endif // LLVM_DEBUGINFO_PDB_DIA_DIAENUMTABLES_H diff --git a/llvm/include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h b/llvm/include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h index d37b48540ff..2d6c44905ce 100644 --- a/llvm/include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h +++ b/llvm/include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h @@ -96,6 +96,7 @@ public: uint32_t getTypeId() const override; uint32_t getUavSlot() const override; std::string getUndecoratedName() const override; + std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override; uint32_t getUnmodifiedTypeId() const override; uint32_t getUpperBoundId() const override; Variant getValue() const override; diff --git a/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h b/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h index 350442556be..66bd7a7e9c4 100644 --- a/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h +++ b/llvm/include/llvm/DebugInfo/PDB/DIA/DIASession.h @@ -64,6 +64,7 @@ public: std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override; + std::unique_ptr<IPDBEnumTables> getEnumTables() const override; private: CComPtr<IDiaSession> Session; }; diff --git a/llvm/include/llvm/DebugInfo/PDB/DIA/DIATable.h b/llvm/include/llvm/DebugInfo/PDB/DIA/DIATable.h new file mode 100644 index 00000000000..ce93fa0b86c --- /dev/null +++ b/llvm/include/llvm/DebugInfo/PDB/DIA/DIATable.h @@ -0,0 +1,32 @@ +//===- DIATable.h - DIA implementation of IPDBTable -------------*- 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_DIA_DIATABLE_H +#define LLVM_DEBUGINFO_PDB_DIA_DIATABLE_H + +#include "DIASupport.h" +#include "llvm/DebugInfo/PDB/IPDBTable.h" + +namespace llvm { +namespace pdb { +class DIATable : public IPDBTable { +public: + explicit DIATable(CComPtr<IDiaTable> DiaTable); + + uint32_t getItemCount() const override; + std::string getName() const override; + PDB_TableType getTableType() const override; + +private: + CComPtr<IDiaTable> Table; +}; +} +} + +#endif // LLVM_DEBUGINFO_PDB_DIA_DIATABLE_H diff --git a/llvm/include/llvm/DebugInfo/PDB/IPDBRawSymbol.h b/llvm/include/llvm/DebugInfo/PDB/IPDBRawSymbol.h index eefc3651872..18b9423378a 100644 --- a/llvm/include/llvm/DebugInfo/PDB/IPDBRawSymbol.h +++ b/llvm/include/llvm/DebugInfo/PDB/IPDBRawSymbol.h @@ -108,6 +108,7 @@ public: virtual uint32_t getTypeId() const = 0; virtual uint32_t getUavSlot() const = 0; virtual std::string getUndecoratedName() const = 0; + virtual std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const = 0; virtual uint32_t getUnmodifiedTypeId() const = 0; virtual uint32_t getUpperBoundId() const = 0; virtual Variant getValue() const = 0; diff --git a/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h b/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h index cf195095c8d..6291289de5b 100644 --- a/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h +++ b/llvm/include/llvm/DebugInfo/PDB/IPDBSession.h @@ -67,6 +67,8 @@ public: getSourceFileById(uint32_t FileId) const = 0; virtual std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const = 0; + + virtual std::unique_ptr<IPDBEnumTables> getEnumTables() const = 0; }; } } diff --git a/llvm/include/llvm/DebugInfo/PDB/IPDBTable.h b/llvm/include/llvm/DebugInfo/PDB/IPDBTable.h new file mode 100644 index 00000000000..4561c4e847b --- /dev/null +++ b/llvm/include/llvm/DebugInfo/PDB/IPDBTable.h @@ -0,0 +1,28 @@ +//===- IPDBTable.h - Base Interface for a PDB Symbol Context ----*- 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_IPDBTABLE_H +#define LLVM_DEBUGINFO_PDB_IPDBTABLE_H + +#include "PDBTypes.h" + +namespace llvm { +namespace pdb { +class IPDBTable { +public: + virtual ~IPDBTable(); + + virtual std::string getName() const = 0; + virtual uint32_t getItemCount() const = 0; + virtual PDB_TableType getTableType() const = 0; +}; +} +} + +#endif // LLVM_DEBUGINFO_PDB_IPDBTABLE_H diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h b/llvm/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h index 2c6548dcce2..931b93fb726 100644 --- a/llvm/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h +++ b/llvm/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h @@ -101,6 +101,7 @@ public: uint32_t getTypeId() const override; uint32_t getUavSlot() const override; std::string getUndecoratedName() const override; + std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override; uint32_t getUnmodifiedTypeId() const override; uint32_t getUpperBoundId() const override; Variant getValue() const override; diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h b/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h index c2344d5648e..f30e344a97f 100644 --- a/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h +++ b/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h @@ -82,6 +82,8 @@ public: std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override; + std::unique_ptr<IPDBEnumTables> getEnumTables() const override; + PDBFile &getPDBFile() { return *Pdb; } const PDBFile &getPDBFile() const { return *Pdb; } diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBTypes.h b/llvm/include/llvm/DebugInfo/PDB/PDBTypes.h index 79ec7ce906d..6d144a5b890 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBTypes.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBTypes.h @@ -24,6 +24,7 @@ namespace pdb { class IPDBDataStream; class IPDBLineNumber; class IPDBSourceFile; +class IPDBTable; class PDBSymDumper; class PDBSymbol; class PDBSymbolExe; @@ -62,6 +63,7 @@ using IPDBEnumSymbols = IPDBEnumChildren<PDBSymbol>; using IPDBEnumSourceFiles = IPDBEnumChildren<IPDBSourceFile>; using IPDBEnumDataStreams = IPDBEnumChildren<IPDBDataStream>; using IPDBEnumLineNumbers = IPDBEnumChildren<IPDBLineNumber>; +using IPDBEnumTables = IPDBEnumChildren<IPDBTable>; /// Specifies which PDB reader implementation is to be used. Only a value /// of PDB_ReaderType::DIA is currently supported, but Native is in the works. @@ -72,13 +74,16 @@ enum class PDB_ReaderType { /// An enumeration indicating the type of data contained in this table. enum class PDB_TableType { + TableInvalid = 0, Symbols, SourceFiles, LineNumbers, SectionContribs, Segments, InjectedSources, - FrameData + FrameData, + InputAssemblyFiles, + Dbg }; /// Defines flags used for enumerating child symbols. This corresponds to the @@ -241,6 +246,32 @@ enum class PDB_BuiltinType { HResult = 31 }; +/// These values correspond to the flags that can be combined to control the +/// return of an undecorated name for a C++ decorated name, and are documented +/// here: https://msdn.microsoft.com/en-us/library/kszfk0fs.aspx +enum PDB_UndnameFlags: uint32_t { + Undname_Complete = 0x0, + Undname_NoLeadingUnderscores = 0x1, + Undname_NoMsKeywords = 0x2, + Undname_NoFuncReturns = 0x4, + Undname_NoAllocModel = 0x8, + Undname_NoAllocLang = 0x10, + Undname_Reserved1 = 0x20, + Undname_Reserved2 = 0x40, + Undname_NoThisType = 0x60, + Undname_NoAccessSpec = 0x80, + Undname_NoThrowSig = 0x100, + Undname_NoMemberType = 0x200, + Undname_NoReturnUDTModel = 0x400, + Undname_32BitDecode = 0x800, + Undname_NameOnly = 0x1000, + Undname_TypeOnly = 0x2000, + Undname_HaveParams = 0x4000, + Undname_NoECSU = 0x8000, + Undname_NoIdentCharCheck = 0x10000, + Undname_NoPTR64 = 0x20000 +}; + enum class PDB_MemberAccess { Private = 1, Protected = 2, Public = 3 }; struct VersionInfo { diff --git a/llvm/lib/DebugInfo/PDB/CMakeLists.txt b/llvm/lib/DebugInfo/PDB/CMakeLists.txt index aad4bf31756..0be05e9bda5 100644 --- a/llvm/lib/DebugInfo/PDB/CMakeLists.txt +++ b/llvm/lib/DebugInfo/PDB/CMakeLists.txt @@ -17,11 +17,13 @@ if(LLVM_ENABLE_DIA_SDK) DIA/DIAEnumLineNumbers.cpp DIA/DIAEnumSourceFiles.cpp DIA/DIAEnumSymbols.cpp + DIA/DIAEnumTables.cpp DIA/DIAError.cpp DIA/DIALineNumber.cpp DIA/DIARawSymbol.cpp DIA/DIASession.cpp DIA/DIASourceFile.cpp + DIA/DIATable.cpp ) set(LIBPDB_ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/DebugInfo/PDB/DIA") diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIAEnumTables.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIAEnumTables.cpp new file mode 100644 index 00000000000..511b55585eb --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/DIA/DIAEnumTables.cpp @@ -0,0 +1,53 @@ +//===- DIAEnumTables.cpp - DIA Table Enumerator Impl ------------*- 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/DIA/DIAEnumTables.h" +#include "llvm/DebugInfo/PDB/DIA/DIATable.h" + +using namespace llvm; +using namespace llvm::pdb; + +DIAEnumTables::DIAEnumTables( + CComPtr<IDiaEnumTables> DiaEnumerator) + : Enumerator(DiaEnumerator) {} + +uint32_t DIAEnumTables::getChildCount() const { + LONG Count = 0; + return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0; +} + +std::unique_ptr<IPDBTable> +DIAEnumTables::getChildAtIndex(uint32_t Index) const { + CComPtr<IDiaTable> Item; + VARIANT Var; + Var.vt = VT_UINT; + Var.uintVal = Index; + if (S_OK != Enumerator->Item(Var, &Item)) + return nullptr; + + return std::unique_ptr<IPDBTable>(new DIATable(Item)); +} + +std::unique_ptr<IPDBTable> DIAEnumTables::getNext() { + CComPtr<IDiaTable> Item; + ULONG CeltFetched = 0; + if (S_OK != Enumerator->Next(1, &Item, &CeltFetched)) + return nullptr; + + return std::unique_ptr<IPDBTable>(new DIATable(Item)); +} + +void DIAEnumTables::reset() { Enumerator->Reset(); } + +DIAEnumTables *DIAEnumTables::clone() const { + CComPtr<IDiaEnumTables> EnumeratorClone; + if (S_OK != Enumerator->Clone(&EnumeratorClone)) + return nullptr; + return new DIAEnumTables(EnumeratorClone); +} diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp index 4c59d2f2a9d..8e4b1f8aa8c 100644 --- a/llvm/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp +++ b/llvm/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp @@ -439,6 +439,20 @@ void DIARawSymbol::getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const { Symbol->get_dataBytes(DataSize, &DataSize, bytes.data()); } +std::string +DIARawSymbol::getUndecoratedNameEx(PDB_UndnameFlags Flags) const { + CComBSTR Result16; + if (S_OK != Symbol->get_undecoratedNameEx((DWORD)Flags, &Result16)) + return std::string(); + + const char *SrcBytes = reinterpret_cast<const char *>(Result16.m_str); + llvm::ArrayRef<char> SrcByteArray(SrcBytes, Result16.ByteLength()); + std::string Result8; + if (!llvm::convertUTF16ToUTF8String(SrcByteArray, Result8)) + return std::string(); + return Result8; +} + PDB_MemberAccess DIARawSymbol::getAccess() const { return PrivateGetDIAValue<DWORD, PDB_MemberAccess>(Symbol, &IDiaSymbol::get_access); diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp index ef9390cda31..b8aaebbf738 100644 --- a/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp +++ b/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp @@ -11,6 +11,7 @@ #include "llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h" #include "llvm/DebugInfo/PDB/DIA/DIAEnumLineNumbers.h" #include "llvm/DebugInfo/PDB/DIA/DIAEnumSourceFiles.h" +#include "llvm/DebugInfo/PDB/DIA/DIAEnumTables.h" #include "llvm/DebugInfo/PDB/DIA/DIAError.h" #include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h" #include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h" @@ -301,3 +302,11 @@ std::unique_ptr<IPDBEnumDataStreams> DIASession::getDebugStreams() const { return llvm::make_unique<DIAEnumDebugStreams>(DiaEnumerator); } + +std::unique_ptr<IPDBEnumTables> DIASession::getEnumTables() const { + CComPtr<IDiaEnumTables> DiaEnumerator; + if (S_OK != Session->getEnumTables(&DiaEnumerator)) + return nullptr; + + return llvm::make_unique<DIAEnumTables>(DiaEnumerator); +} diff --git a/llvm/lib/DebugInfo/PDB/DIA/DIATable.cpp b/llvm/lib/DebugInfo/PDB/DIA/DIATable.cpp new file mode 100644 index 00000000000..7f4d06c9b8a --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/DIA/DIATable.cpp @@ -0,0 +1,61 @@ +//===- DIATable.cpp - DIA implementation of IPDBTable -----------*- 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/DIA/DIATable.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/Support/ConvertUTF.h" + +using namespace llvm; +using namespace llvm::pdb; + +DIATable::DIATable(CComPtr<IDiaTable> DiaTable) + : Table(DiaTable) {} + +uint32_t DIATable::getItemCount() const { + LONG Count = 0; + return (S_OK == Table->get_Count(&Count)) ? Count : 0; +} + +std::string DIATable::getName() const { + CComBSTR Name16; + if (S_OK != Table->get_name(&Name16)) + return std::string(); + + std::string Name8; + llvm::ArrayRef<char> Name16Bytes(reinterpret_cast<char *>(Name16.m_str), + Name16.ByteLength()); + if (!llvm::convertUTF16ToUTF8String(Name16Bytes, Name8)) + return std::string(); + return Name8; +} + +PDB_TableType DIATable::getTableType() const { + CComBSTR Name16; + if (S_OK != Table->get_name(&Name16)) + return PDB_TableType::TableInvalid; + + if (Name16 == DiaTable_Symbols) + return PDB_TableType::Symbols; + if (Name16 == DiaTable_SrcFiles) + return PDB_TableType::SourceFiles; + if (Name16 == DiaTable_Sections) + return PDB_TableType::SectionContribs; + if (Name16 == DiaTable_LineNums) + return PDB_TableType::LineNumbers; + if (Name16 == DiaTable_SegMap) + return PDB_TableType::Segments; + if (Name16 == DiaTable_InjSrc) + return PDB_TableType::InjectedSources; + if (Name16 == DiaTable_FrameData) + return PDB_TableType::FrameData; + if (Name16 == DiaTable_InputAssemblyFiles) + return PDB_TableType::InputAssemblyFiles; + if (Name16 == DiaTable_Dbg) + return PDB_TableType::Dbg; +} diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp index df3f418052a..d23ee0a0919 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp @@ -286,6 +286,11 @@ std::string NativeRawSymbol::getUndecoratedName() const { return {}; } +std::string NativeRawSymbol::getUndecoratedNameEx( + PDB_UndnameFlags Flags) const { + return {}; +} + uint32_t NativeRawSymbol::getUnmodifiedTypeId() const { return 0; } diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp index 7be4c762b02..b01c2b54796 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -245,3 +245,7 @@ NativeSession::getSourceFileById(uint32_t FileId) const { std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const { return nullptr; } + +std::unique_ptr<IPDBEnumTables> NativeSession::getEnumTables() const { + return nullptr; +} diff --git a/llvm/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp b/llvm/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp index 541fcda4517..b2b03fbe167 100644 --- a/llvm/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp @@ -15,6 +15,7 @@ #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/IPDBTable.h" using namespace llvm; using namespace llvm::pdb; @@ -26,3 +27,5 @@ IPDBDataStream::~IPDBDataStream() = default; IPDBRawSymbol::~IPDBRawSymbol() = default; IPDBLineNumber::~IPDBLineNumber() = default; + +IPDBTable::~IPDBTable() = default; diff --git a/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp b/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp index 257a8879e43..e998acf009e 100644 --- a/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp +++ b/llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp @@ -14,6 +14,7 @@ #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" +#include "llvm/DebugInfo/PDB/IPDBTable.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h" @@ -118,6 +119,10 @@ class MockSession : public IPDBSession { std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override { return nullptr; } + + std::unique_ptr<IPDBEnumTables> getEnumTables() const override { + return nullptr; + } }; class MockRawSymbol : public IPDBRawSymbol { @@ -152,6 +157,10 @@ public: PDB_SymType getSymTag() const override { return Type; } + std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override { + return {}; + } + MOCK_SYMBOL_ACCESSOR(getAccess) MOCK_SYMBOL_ACCESSOR(getAddressOffset) MOCK_SYMBOL_ACCESSOR(getAddressSection) |