Index: include/llvm/DebugInfo/PDB/DIA/DIAEnumTables.h =================================================================== --- /dev/null +++ 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 Index: include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h =================================================================== --- include/llvm/DebugInfo/PDB/DIA/DIARawSymbol.h +++ 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(uint32_t Options) const override; uint32_t getUnmodifiedTypeId() const override; uint32_t getUpperBoundId() const override; Variant getValue() const override; Index: include/llvm/DebugInfo/PDB/DIA/DIASession.h =================================================================== --- include/llvm/DebugInfo/PDB/DIA/DIASession.h +++ include/llvm/DebugInfo/PDB/DIA/DIASession.h @@ -64,6 +64,7 @@ std::unique_ptr getDebugStreams() const override; + std::unique_ptr getTables() const override; private: CComPtr Session; }; Index: include/llvm/DebugInfo/PDB/DIA/DIATable.h =================================================================== --- /dev/null +++ include/llvm/DebugInfo/PDB/DIA/DIATable.h @@ -0,0 +1,32 @@ +//===- DIATable.h - DIA implementation of IPDBDataStream --------*- 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 Index: include/llvm/DebugInfo/PDB/IPDBRawSymbol.h =================================================================== --- include/llvm/DebugInfo/PDB/IPDBRawSymbol.h +++ 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(uint32_t Options) const = 0; virtual uint32_t getUnmodifiedTypeId() const = 0; virtual uint32_t getUpperBoundId() const = 0; virtual Variant getValue() const = 0; Index: include/llvm/DebugInfo/PDB/IPDBSession.h =================================================================== --- include/llvm/DebugInfo/PDB/IPDBSession.h +++ 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 getTables() const = 0; }; } } Index: include/llvm/DebugInfo/PDB/IPDBTable.h =================================================================== --- /dev/null +++ include/llvm/DebugInfo/PDB/IPDBTable.h @@ -0,0 +1,28 @@ +//===- IPDBSession.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: include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h =================================================================== --- include/llvm/DebugInfo/PDB/Native/NativeRawSymbol.h +++ 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(uint32_t Options) const override; uint32_t getUnmodifiedTypeId() const override; uint32_t getUpperBoundId() const override; Variant getValue() const override; Index: include/llvm/DebugInfo/PDB/Native/NativeSession.h =================================================================== --- include/llvm/DebugInfo/PDB/Native/NativeSession.h +++ include/llvm/DebugInfo/PDB/Native/NativeSession.h @@ -82,6 +82,8 @@ std::unique_ptr getDebugStreams() const override; + std::unique_ptr getTables() const override; + PDBFile &getPDBFile() { return *Pdb; } const PDBFile &getPDBFile() const { return *Pdb; } Index: include/llvm/DebugInfo/PDB/PDBTypes.h =================================================================== --- include/llvm/DebugInfo/PDB/PDBTypes.h +++ 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, Symbols, SourceFiles, LineNumbers, SectionContribs, Segments, InjectedSources, - FrameData + FrameData, + InputAssemblyFiles, + Dbg }; /// Defines flags used for enumerating child symbols. This corresponds to the @@ -241,6 +246,28 @@ HResult = 31 }; +// https://msdn.microsoft.com/en-us/library/kszfk0fs.aspx +#define UND_COMPLETE 0x0 +#define UND_NO_LEADING_UNDERSCORES 0x1 +#define UND_NO_MS_KEYWORDS 0x2 +#define UND_NO_FUNC_RETURN 0x4 +#define UND_NO_ALLOC_MODEL 0x8 +#define UND_NO_ALLOC_LANG 0x10 +#define UND_RES1 0x20 +#define UND_RES2 0x40 +#define UND_NO_THISTYPE 0x60 +#define UND_NO_ACCESS_SPEC 0x80 +#define UND_NO_THROW_SIG 0x100 +#define UND_NO_MEMBER_TYPE 0x200 +#define UND_NO_RETURN_UDT 0x400 +#define UND_32_BIT_DECODE 0x800 +#define UND_NAME_ONLY 0x1000 +#define UND_TYPE_ONLY 0x2000 +#define UND_HAVE_PARAM 0x4000 +#define UND_NO_ESCU 0x8000 +#define UND_NO_INDENT_CHAR_CHECK 0x10000 +#define UND_NO_PTR64 0x20000 + enum class PDB_MemberAccess { Private = 1, Protected = 2, Public = 3 }; struct VersionInfo { Index: lib/DebugInfo/PDB/CMakeLists.txt =================================================================== --- lib/DebugInfo/PDB/CMakeLists.txt +++ 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: lib/DebugInfo/PDB/DIA/DIAEnumTables.cpp =================================================================== --- /dev/null +++ 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: lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp =================================================================== --- lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp +++ lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp @@ -439,6 +439,20 @@ Symbol->get_dataBytes(DataSize, &DataSize, bytes.data()); } +std::string +DIARawSymbol::getUndecoratedNameEx(uint32_t Options) const { + CComBSTR Result16; + if (S_OK != Symbol->get_undecoratedNameEx((DWORD)Options, &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: lib/DebugInfo/PDB/DIA/DIASession.cpp =================================================================== --- lib/DebugInfo/PDB/DIA/DIASession.cpp +++ 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::getTables() const { + CComPtr DiaEnumerator; + if (S_OK != Session->getEnumTables(&DiaEnumerator)) + return nullptr; + + return llvm::make_unique(DiaEnumerator); +} Index: lib/DebugInfo/PDB/DIA/DIATable.cpp =================================================================== --- /dev/null +++ lib/DebugInfo/PDB/DIA/DIATable.cpp @@ -0,0 +1,61 @@ +//===- DIATable.cpp - DIA implementation of IPDBDataStream ------*- 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)) { + if (Name16 == DiaTable_Symbols) + return PDB_TableType::Symbols; + else if (Name16 == DiaTable_SrcFiles) + return PDB_TableType::SourceFiles; + else if (Name16 == DiaTable_Sections) + return PDB_TableType::SectionContribs; + else if (Name16 == DiaTable_LineNums) + return PDB_TableType::LineNumbers; + else if (Name16 == DiaTable_SegMap) + return PDB_TableType::Segments; + else if (Name16 == DiaTable_InjSrc) + return PDB_TableType::InjectedSources; + else if (Name16 == DiaTable_FrameData) + return PDB_TableType::FrameData; + else if (Name16 == DiaTable_InputAssemblyFiles) + return PDB_TableType::InputAssemblyFiles; + else if (Name16 == DiaTable_Dbg) + return PDB_TableType::Dbg; + } + return PDB_TableType::TableInvalid; +} Index: lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp =================================================================== --- lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp +++ lib/DebugInfo/PDB/Native/NativeRawSymbol.cpp @@ -286,6 +286,10 @@ return {}; } +std::string NativeRawSymbol::getUndecoratedNameEx(uint32_t Options) const { + return {}; +} + uint32_t NativeRawSymbol::getUnmodifiedTypeId() const { return 0; } Index: lib/DebugInfo/PDB/Native/NativeSession.cpp =================================================================== --- lib/DebugInfo/PDB/Native/NativeSession.cpp +++ lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -245,3 +245,7 @@ std::unique_ptr NativeSession::getDebugStreams() const { return nullptr; } + +std::unique_ptr NativeSession::getTables() const { + return nullptr; +} Index: lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp =================================================================== --- lib/DebugInfo/PDB/PDBInterfaceAnchors.cpp +++ 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;