1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[DebugInfo/PDB] Adding getUndecoratedNameEx and IPDB interfaces for IDiaEnumTables and IDiaTable.

Initial changes to support debugging PE/COFF files with LLDB on Windows through DIA SDK.
There is another set of changes required on the LLDB side before this does anything.

Differential Revision: https://reviews.llvm.org/D39517

llvm-svn: 318403
This commit is contained in:
Aaron Smith 2017-11-16 14:33:09 +00:00
parent 61b102a905
commit 9d7d2480c7
19 changed files with 297 additions and 1 deletions

View File

@ -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

View File

@ -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;

View File

@ -64,6 +64,7 @@ public:
std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override;
std::unique_ptr<IPDBEnumTables> getEnumTables() const override;
private:
CComPtr<IDiaSession> Session;
};

View File

@ -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

View File

@ -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;

View File

@ -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;
};
}
}

View File

@ -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

View File

@ -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;

View File

@ -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; }

View File

@ -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 {

View File

@ -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")

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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)