Index: llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIAEnumTables.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIAEnumTables.h +++ llvm/trunk/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 { +public: + explicit DIAEnumTables(CComPtr DiaEnumerator); + + uint32_t getChildCount() const override; + std::unique_ptr getChildAtIndex(uint32_t Index) const override; + std::unique_ptr getNext() override; + void reset() override; + DIAEnumTables *clone() const override; + +private: + CComPtr Enumerator; +}; +} +} + +#endif // LLVM_DEBUGINFO_PDB_DIA_DIAENUMTABLES_H Index: llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h @@ -96,6 +96,7 @@ 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; Index: llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIASession.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIASession.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIASession.h @@ -64,6 +64,7 @@ std::unique_ptr getDebugStreams() const override; + std::unique_ptr getEnumTables() const override; private: CComPtr Session; }; Index: llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIATable.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/DIA/DIATable.h +++ llvm/trunk/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 DiaTable); + + uint32_t getItemCount() const override; + std::string getName() const override; + PDB_TableType getTableType() const override; + +private: + CComPtr Table; +}; +} +} + +#endif // LLVM_DEBUGINFO_PDB_DIA_DIATABLE_H Index: llvm/trunk/include/llvm/DebugInfo/PDB/IPDBRawSymbol.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/IPDBRawSymbol.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/IPDBRawSymbol.h @@ -108,6 +108,7 @@ 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; Index: llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/IPDBSession.h @@ -67,6 +67,8 @@ getSourceFileById(uint32_t FileId) const = 0; virtual std::unique_ptr getDebugStreams() const = 0; + + virtual std::unique_ptr getEnumTables() const = 0; }; } } Index: llvm/trunk/include/llvm/DebugInfo/PDB/IPDBTable.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/IPDBTable.h +++ llvm/trunk/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 Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h @@ -101,6 +101,7 @@ 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; Index: llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeSession.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeSession.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeSession.h @@ -82,6 +82,8 @@ std::unique_ptr getDebugStreams() const override; + std::unique_ptr getEnumTables() const override; + PDBFile &getPDBFile() { return *Pdb; } const PDBFile &getPDBFile() const { return *Pdb; } Index: llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/PDBTypes.h @@ -24,6 +24,7 @@ class IPDBDataStream; class IPDBLineNumber; class IPDBSourceFile; +class IPDBTable; class PDBSymDumper; class PDBSymbol; class PDBSymbolExe; @@ -62,6 +63,7 @@ using IPDBEnumSourceFiles = IPDBEnumChildren; using IPDBEnumDataStreams = IPDBEnumChildren; using IPDBEnumLineNumbers = IPDBEnumChildren; +using IPDBEnumTables = IPDBEnumChildren; /// 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 @@ /// 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 @@ 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 { Index: llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt +++ llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt @@ -17,11 +17,13 @@ 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") Index: llvm/trunk/lib/DebugInfo/PDB/DIA/DIAEnumTables.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/DIA/DIAEnumTables.cpp +++ llvm/trunk/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 DiaEnumerator) + : Enumerator(DiaEnumerator) {} + +uint32_t DIAEnumTables::getChildCount() const { + LONG Count = 0; + return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0; +} + +std::unique_ptr +DIAEnumTables::getChildAtIndex(uint32_t Index) const { + CComPtr Item; + VARIANT Var; + Var.vt = VT_UINT; + Var.uintVal = Index; + if (S_OK != Enumerator->Item(Var, &Item)) + return nullptr; + + return std::unique_ptr(new DIATable(Item)); +} + +std::unique_ptr DIAEnumTables::getNext() { + CComPtr Item; + ULONG CeltFetched = 0; + if (S_OK != Enumerator->Next(1, &Item, &CeltFetched)) + return nullptr; + + return std::unique_ptr(new DIATable(Item)); +} + +void DIAEnumTables::reset() { Enumerator->Reset(); } + +DIAEnumTables *DIAEnumTables::clone() const { + CComPtr EnumeratorClone; + if (S_OK != Enumerator->Clone(&EnumeratorClone)) + return nullptr; + return new DIAEnumTables(EnumeratorClone); +} Index: llvm/trunk/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp +++ llvm/trunk/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp @@ -439,6 +439,20 @@ 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(Result16.m_str); + llvm::ArrayRef SrcByteArray(SrcBytes, Result16.ByteLength()); + std::string Result8; + if (!llvm::convertUTF16ToUTF8String(SrcByteArray, Result8)) + return std::string(); + return Result8; +} + PDB_MemberAccess DIARawSymbol::getAccess() const { return PrivateGetDIAValue(Symbol, &IDiaSymbol::get_access); Index: llvm/trunk/lib/DebugInfo/PDB/DIA/DIASession.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/DIA/DIASession.cpp +++ llvm/trunk/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 @@ return llvm::make_unique(DiaEnumerator); } + +std::unique_ptr DIASession::getEnumTables() const { + CComPtr DiaEnumerator; + if (S_OK != Session->getEnumTables(&DiaEnumerator)) + return nullptr; + + return llvm::make_unique(DiaEnumerator); +} Index: llvm/trunk/lib/DebugInfo/PDB/DIA/DIATable.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/DIA/DIATable.cpp +++ llvm/trunk/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 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 Name16Bytes(reinterpret_cast(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; +} Index: llvm/trunk/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp @@ -286,6 +286,11 @@ return {}; } +std::string NativeRawSymbol::getUndecoratedNameEx( + PDB_UndnameFlags Flags) const { + return {}; +} + uint32_t NativeRawSymbol::getUnmodifiedTypeId() const { return 0; } Index: llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -245,3 +245,7 @@ std::unique_ptr NativeSession::getDebugStreams() const { return nullptr; } + +std::unique_ptr NativeSession::getEnumTables() const { + return nullptr; +} Index: llvm/trunk/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp +++ llvm/trunk/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 @@ IPDBRawSymbol::~IPDBRawSymbol() = default; IPDBLineNumber::~IPDBLineNumber() = default; + +IPDBTable::~IPDBTable() = default; Index: llvm/trunk/unittests/DebugInfo/PDB/PDBApiTest.cpp =================================================================== --- llvm/trunk/unittests/DebugInfo/PDB/PDBApiTest.cpp +++ llvm/trunk/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 @@ std::unique_ptr getDebugStreams() const override { return nullptr; } + + std::unique_ptr getEnumTables() const override { + return nullptr; + } }; class MockRawSymbol : public IPDBRawSymbol { @@ -152,6 +157,10 @@ 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)