You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.167
Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
parent
e19d552987
commit
b084638f15
@ -1,75 +0,0 @@
|
||||
//===- DIADataStream.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/DIADataStream.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
DIADataStream::DIADataStream(CComPtr<IDiaEnumDebugStreamData> DiaStreamData)
|
||||
: StreamData(DiaStreamData) {}
|
||||
|
||||
uint32_t DIADataStream::getRecordCount() const {
|
||||
LONG Count = 0;
|
||||
return (S_OK == StreamData->get_Count(&Count)) ? Count : 0;
|
||||
}
|
||||
|
||||
std::string DIADataStream::getName() const {
|
||||
CComBSTR Name16;
|
||||
if (S_OK != StreamData->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;
|
||||
}
|
||||
|
||||
llvm::Optional<DIADataStream::RecordType>
|
||||
DIADataStream::getItemAtIndex(uint32_t Index) const {
|
||||
RecordType Record;
|
||||
DWORD RecordSize = 0;
|
||||
StreamData->Item(Index, 0, &RecordSize, nullptr);
|
||||
if (RecordSize == 0)
|
||||
return llvm::Optional<RecordType>();
|
||||
|
||||
Record.resize(RecordSize);
|
||||
if (S_OK != StreamData->Item(Index, RecordSize, &RecordSize, &Record[0]))
|
||||
return llvm::Optional<RecordType>();
|
||||
return Record;
|
||||
}
|
||||
|
||||
bool DIADataStream::getNext(RecordType &Record) {
|
||||
Record.clear();
|
||||
DWORD RecordSize = 0;
|
||||
ULONG CountFetched = 0;
|
||||
StreamData->Next(1, 0, &RecordSize, nullptr, &CountFetched);
|
||||
if (RecordSize == 0)
|
||||
return false;
|
||||
|
||||
Record.resize(RecordSize);
|
||||
if (S_OK ==
|
||||
StreamData->Next(1, RecordSize, &RecordSize, &Record[0], &CountFetched))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DIADataStream::reset() { StreamData->Reset(); }
|
||||
|
||||
DIADataStream *DIADataStream::clone() const {
|
||||
CComPtr<IDiaEnumDebugStreamData> EnumeratorClone;
|
||||
if (S_OK != StreamData->Clone(&EnumeratorClone))
|
||||
return nullptr;
|
||||
|
||||
return new DIADataStream(EnumeratorClone);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
//==- DIAEnumDebugStreams.cpp - DIA Debug Stream 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/DIAEnumDebugStreams.h"
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIADataStream.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
DIAEnumDebugStreams::DIAEnumDebugStreams(
|
||||
CComPtr<IDiaEnumDebugStreams> DiaEnumerator)
|
||||
: Enumerator(DiaEnumerator) {}
|
||||
|
||||
uint32_t DIAEnumDebugStreams::getChildCount() const {
|
||||
LONG Count = 0;
|
||||
return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBDataStream>
|
||||
DIAEnumDebugStreams::getChildAtIndex(uint32_t Index) const {
|
||||
CComPtr<IDiaEnumDebugStreamData> Item;
|
||||
VARIANT VarIndex;
|
||||
VarIndex.vt = VT_I4;
|
||||
VarIndex.lVal = Index;
|
||||
if (S_OK != Enumerator->Item(VarIndex, &Item))
|
||||
return nullptr;
|
||||
|
||||
return std::unique_ptr<IPDBDataStream>(new DIADataStream(Item));
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBDataStream> DIAEnumDebugStreams::getNext() {
|
||||
CComPtr<IDiaEnumDebugStreamData> Item;
|
||||
ULONG NumFetched = 0;
|
||||
if (S_OK != Enumerator->Next(1, &Item, &NumFetched))
|
||||
return nullptr;
|
||||
|
||||
return std::unique_ptr<IPDBDataStream>(new DIADataStream(Item));
|
||||
}
|
||||
|
||||
void DIAEnumDebugStreams::reset() { Enumerator->Reset(); }
|
||||
|
||||
DIAEnumDebugStreams *DIAEnumDebugStreams::clone() const {
|
||||
CComPtr<IDiaEnumDebugStreams> EnumeratorClone;
|
||||
if (S_OK != Enumerator->Clone(&EnumeratorClone))
|
||||
return nullptr;
|
||||
return new DIAEnumDebugStreams(EnumeratorClone);
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
//==- DIAEnumLineNumbers.cpp - DIA Line Number 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/DIAEnumLineNumbers.h"
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIALineNumber.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
DIAEnumLineNumbers::DIAEnumLineNumbers(
|
||||
CComPtr<IDiaEnumLineNumbers> DiaEnumerator)
|
||||
: Enumerator(DiaEnumerator) {}
|
||||
|
||||
uint32_t DIAEnumLineNumbers::getChildCount() const {
|
||||
LONG Count = 0;
|
||||
return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBLineNumber>
|
||||
DIAEnumLineNumbers::getChildAtIndex(uint32_t Index) const {
|
||||
CComPtr<IDiaLineNumber> Item;
|
||||
if (S_OK != Enumerator->Item(Index, &Item))
|
||||
return nullptr;
|
||||
|
||||
return std::unique_ptr<IPDBLineNumber>(new DIALineNumber(Item));
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBLineNumber> DIAEnumLineNumbers::getNext() {
|
||||
CComPtr<IDiaLineNumber> Item;
|
||||
ULONG NumFetched = 0;
|
||||
if (S_OK != Enumerator->Next(1, &Item, &NumFetched))
|
||||
return nullptr;
|
||||
|
||||
return std::unique_ptr<IPDBLineNumber>(new DIALineNumber(Item));
|
||||
}
|
||||
|
||||
void DIAEnumLineNumbers::reset() { Enumerator->Reset(); }
|
||||
|
||||
DIAEnumLineNumbers *DIAEnumLineNumbers::clone() const {
|
||||
CComPtr<IDiaEnumLineNumbers> EnumeratorClone;
|
||||
if (S_OK != Enumerator->Clone(&EnumeratorClone))
|
||||
return nullptr;
|
||||
return new DIAEnumLineNumbers(EnumeratorClone);
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
//==- DIAEnumSourceFiles.cpp - DIA Source File 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/DIAEnumSourceFiles.h"
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
DIAEnumSourceFiles::DIAEnumSourceFiles(
|
||||
const DIASession &PDBSession, CComPtr<IDiaEnumSourceFiles> DiaEnumerator)
|
||||
: Session(PDBSession), Enumerator(DiaEnumerator) {}
|
||||
|
||||
uint32_t DIAEnumSourceFiles::getChildCount() const {
|
||||
LONG Count = 0;
|
||||
return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBSourceFile>
|
||||
DIAEnumSourceFiles::getChildAtIndex(uint32_t Index) const {
|
||||
CComPtr<IDiaSourceFile> Item;
|
||||
if (S_OK != Enumerator->Item(Index, &Item))
|
||||
return nullptr;
|
||||
|
||||
return std::unique_ptr<IPDBSourceFile>(new DIASourceFile(Session, Item));
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBSourceFile> DIAEnumSourceFiles::getNext() {
|
||||
CComPtr<IDiaSourceFile> Item;
|
||||
ULONG NumFetched = 0;
|
||||
if (S_OK != Enumerator->Next(1, &Item, &NumFetched))
|
||||
return nullptr;
|
||||
|
||||
return std::unique_ptr<IPDBSourceFile>(new DIASourceFile(Session, Item));
|
||||
}
|
||||
|
||||
void DIAEnumSourceFiles::reset() { Enumerator->Reset(); }
|
||||
|
||||
DIAEnumSourceFiles *DIAEnumSourceFiles::clone() const {
|
||||
CComPtr<IDiaEnumSourceFiles> EnumeratorClone;
|
||||
if (S_OK != Enumerator->Clone(&EnumeratorClone))
|
||||
return nullptr;
|
||||
return new DIAEnumSourceFiles(Session, EnumeratorClone);
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
//==- DIAEnumSymbols.cpp - DIA Symbol 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/DIAEnumSymbols.h"
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h"
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbol.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
DIAEnumSymbols::DIAEnumSymbols(const DIASession &PDBSession,
|
||||
CComPtr<IDiaEnumSymbols> DiaEnumerator)
|
||||
: Session(PDBSession), Enumerator(DiaEnumerator) {}
|
||||
|
||||
uint32_t DIAEnumSymbols::getChildCount() const {
|
||||
LONG Count = 0;
|
||||
return (S_OK == Enumerator->get_Count(&Count)) ? Count : 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbol>
|
||||
DIAEnumSymbols::getChildAtIndex(uint32_t Index) const {
|
||||
CComPtr<IDiaSymbol> Item;
|
||||
if (S_OK != Enumerator->Item(Index, &Item))
|
||||
return nullptr;
|
||||
|
||||
std::unique_ptr<DIARawSymbol> RawSymbol(new DIARawSymbol(Session, Item));
|
||||
return std::unique_ptr<PDBSymbol>(PDBSymbol::create(Session, std::move(RawSymbol)));
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbol> DIAEnumSymbols::getNext() {
|
||||
CComPtr<IDiaSymbol> Item;
|
||||
ULONG NumFetched = 0;
|
||||
if (S_OK != Enumerator->Next(1, &Item, &NumFetched))
|
||||
return nullptr;
|
||||
|
||||
std::unique_ptr<DIARawSymbol> RawSymbol(new DIARawSymbol(Session, Item));
|
||||
return std::unique_ptr<PDBSymbol>(
|
||||
PDBSymbol::create(Session, std::move(RawSymbol)));
|
||||
}
|
||||
|
||||
void DIAEnumSymbols::reset() { Enumerator->Reset(); }
|
||||
|
||||
DIAEnumSymbols *DIAEnumSymbols::clone() const {
|
||||
CComPtr<IDiaEnumSymbols> EnumeratorClone;
|
||||
if (S_OK != Enumerator->Clone(&EnumeratorClone))
|
||||
return nullptr;
|
||||
return new DIAEnumSymbols(Session, EnumeratorClone);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
//===- 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);
|
||||
}
|
58
external/llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp
vendored
58
external/llvm/lib/DebugInfo/PDB/DIA/DIAError.cpp
vendored
@ -1,58 +0,0 @@
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIAError.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
// FIXME: This class is only here to support the transition to llvm::Error. It
|
||||
// will be removed once this transition is complete. Clients should prefer to
|
||||
// deal with the Error value directly, rather than converting to error_code.
|
||||
class DIAErrorCategory : public std::error_category {
|
||||
public:
|
||||
const char *name() const noexcept override { return "llvm.pdb.dia"; }
|
||||
|
||||
std::string message(int Condition) const override {
|
||||
switch (static_cast<dia_error_code>(Condition)) {
|
||||
case dia_error_code::could_not_create_impl:
|
||||
return "Failed to connect to DIA at runtime. Verify that Visual Studio "
|
||||
"is properly installed, or that msdiaXX.dll is in your PATH.";
|
||||
case dia_error_code::invalid_file_format:
|
||||
return "Unable to load PDB. The file has an unrecognized format.";
|
||||
case dia_error_code::invalid_parameter:
|
||||
return "The parameter is incorrect.";
|
||||
case dia_error_code::already_loaded:
|
||||
return "Unable to load the PDB or EXE, because it is already loaded.";
|
||||
case dia_error_code::debug_info_mismatch:
|
||||
return "The PDB file and the EXE file do not match.";
|
||||
case dia_error_code::unspecified:
|
||||
return "An unknown error has occurred.";
|
||||
}
|
||||
llvm_unreachable("Unrecognized DIAErrorCode");
|
||||
}
|
||||
};
|
||||
|
||||
static ManagedStatic<DIAErrorCategory> Category;
|
||||
|
||||
char DIAError::ID = 0;
|
||||
|
||||
DIAError::DIAError(dia_error_code C) : DIAError(C, "") {}
|
||||
|
||||
DIAError::DIAError(StringRef Context)
|
||||
: DIAError(dia_error_code::unspecified, Context) {}
|
||||
|
||||
DIAError::DIAError(dia_error_code C, StringRef Context) : Code(C) {
|
||||
ErrMsg = "DIA Error: ";
|
||||
std::error_code EC = convertToErrorCode();
|
||||
ErrMsg += EC.message() + " ";
|
||||
if (!Context.empty())
|
||||
ErrMsg += Context;
|
||||
}
|
||||
|
||||
void DIAError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
|
||||
|
||||
StringRef DIAError::getErrorMessage() const { return ErrMsg; }
|
||||
|
||||
std::error_code DIAError::convertToErrorCode() const {
|
||||
return std::error_code(static_cast<int>(Code), *Category);
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
//===- DIALineNumber.cpp - DIA implementation of IPDBLineNumber -*- 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/DIALineNumber.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
DIALineNumber::DIALineNumber(CComPtr<IDiaLineNumber> DiaLineNumber)
|
||||
: LineNumber(DiaLineNumber) {}
|
||||
|
||||
uint32_t DIALineNumber::getLineNumber() const {
|
||||
DWORD Line = 0;
|
||||
return (S_OK == LineNumber->get_lineNumber(&Line)) ? Line : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getLineNumberEnd() const {
|
||||
DWORD LineEnd = 0;
|
||||
return (S_OK == LineNumber->get_lineNumberEnd(&LineEnd)) ? LineEnd : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getColumnNumber() const {
|
||||
DWORD Column = 0;
|
||||
return (S_OK == LineNumber->get_columnNumber(&Column)) ? Column : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getColumnNumberEnd() const {
|
||||
DWORD ColumnEnd = 0;
|
||||
return (S_OK == LineNumber->get_columnNumberEnd(&ColumnEnd)) ? ColumnEnd : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getAddressSection() const {
|
||||
DWORD Section = 0;
|
||||
return (S_OK == LineNumber->get_addressSection(&Section)) ? Section : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getAddressOffset() const {
|
||||
DWORD Offset = 0;
|
||||
return (S_OK == LineNumber->get_addressOffset(&Offset)) ? Offset : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getRelativeVirtualAddress() const {
|
||||
DWORD RVA = 0;
|
||||
return (S_OK == LineNumber->get_relativeVirtualAddress(&RVA)) ? RVA : 0;
|
||||
}
|
||||
|
||||
uint64_t DIALineNumber::getVirtualAddress() const {
|
||||
ULONGLONG Addr = 0;
|
||||
return (S_OK == LineNumber->get_virtualAddress(&Addr)) ? Addr : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getLength() const {
|
||||
DWORD Length = 0;
|
||||
return (S_OK == LineNumber->get_length(&Length)) ? Length : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getSourceFileId() const {
|
||||
DWORD Id = 0;
|
||||
return (S_OK == LineNumber->get_sourceFileId(&Id)) ? Id : 0;
|
||||
}
|
||||
|
||||
uint32_t DIALineNumber::getCompilandId() const {
|
||||
DWORD Id = 0;
|
||||
return (S_OK == LineNumber->get_compilandId(&Id)) ? Id : 0;
|
||||
}
|
||||
|
||||
bool DIALineNumber::isStatement() const {
|
||||
BOOL Statement = 0;
|
||||
return (S_OK == LineNumber->get_statement(&Statement)) ? Statement : false;
|
||||
}
|
1143
external/llvm/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp
vendored
1143
external/llvm/lib/DebugInfo/PDB/DIA/DIARawSymbol.cpp
vendored
File diff suppressed because it is too large
Load Diff
312
external/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp
vendored
312
external/llvm/lib/DebugInfo/PDB/DIA/DIASession.cpp
vendored
@ -1,312 +0,0 @@
|
||||
//===- DIASession.cpp - DIA implementation of IPDBSession -------*- 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/DIASession.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#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"
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIASupport.h"
|
||||
#include "llvm/DebugInfo/PDB/GenericError.h"
|
||||
#include "llvm/DebugInfo/PDB/PDB.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
template <typename... Ts>
|
||||
static Error ErrorFromHResult(HRESULT Result, const char *Str, Ts &&... Args) {
|
||||
SmallString<64> MessageStorage;
|
||||
StringRef Context;
|
||||
if (sizeof...(Args) > 0) {
|
||||
MessageStorage = formatv(Str, std::forward<Ts>(Args)...).str();
|
||||
Context = MessageStorage;
|
||||
} else
|
||||
Context = Str;
|
||||
|
||||
switch (Result) {
|
||||
case E_PDB_NOT_FOUND:
|
||||
return make_error<GenericError>(generic_error_code::invalid_path, Context);
|
||||
case E_PDB_FORMAT:
|
||||
return make_error<DIAError>(dia_error_code::invalid_file_format, Context);
|
||||
case E_INVALIDARG:
|
||||
return make_error<DIAError>(dia_error_code::invalid_parameter, Context);
|
||||
case E_UNEXPECTED:
|
||||
return make_error<DIAError>(dia_error_code::already_loaded, Context);
|
||||
case E_PDB_INVALID_SIG:
|
||||
case E_PDB_INVALID_AGE:
|
||||
return make_error<DIAError>(dia_error_code::debug_info_mismatch, Context);
|
||||
default: {
|
||||
std::string S;
|
||||
raw_string_ostream OS(S);
|
||||
OS << "HRESULT: " << format_hex(static_cast<DWORD>(Result), 10, true)
|
||||
<< ": " << Context;
|
||||
return make_error<DIAError>(dia_error_code::unspecified, OS.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Error LoadDIA(CComPtr<IDiaDataSource> &DiaDataSource) {
|
||||
if (SUCCEEDED(CoCreateInstance(CLSID_DiaSource, nullptr, CLSCTX_INPROC_SERVER,
|
||||
IID_IDiaDataSource,
|
||||
reinterpret_cast<LPVOID *>(&DiaDataSource))))
|
||||
return Error::success();
|
||||
|
||||
// If the CoCreateInstance call above failed, msdia*.dll is not registered.
|
||||
// Try loading the DLL corresponding to the #included DIA SDK.
|
||||
#if !defined(_MSC_VER)
|
||||
return llvm::make_error<GenericError>(
|
||||
"DIA is only supported when using MSVC.");
|
||||
#else
|
||||
const wchar_t *msdia_dll = nullptr;
|
||||
#if _MSC_VER >= 1900 && _MSC_VER < 2000
|
||||
msdia_dll = L"msdia140.dll"; // VS2015
|
||||
#elif _MSC_VER >= 1800
|
||||
msdia_dll = L"msdia120.dll"; // VS2013
|
||||
#else
|
||||
#error "Unknown Visual Studio version."
|
||||
#endif
|
||||
|
||||
HRESULT HR;
|
||||
if (FAILED(HR = NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
|
||||
reinterpret_cast<LPVOID *>(&DiaDataSource))))
|
||||
return ErrorFromHResult(HR, "Calling NoRegCoCreate");
|
||||
return Error::success();
|
||||
#endif
|
||||
}
|
||||
|
||||
DIASession::DIASession(CComPtr<IDiaSession> DiaSession) : Session(DiaSession) {}
|
||||
|
||||
Error DIASession::createFromPdb(StringRef Path,
|
||||
std::unique_ptr<IPDBSession> &Session) {
|
||||
CComPtr<IDiaDataSource> DiaDataSource;
|
||||
CComPtr<IDiaSession> DiaSession;
|
||||
|
||||
// We assume that CoInitializeEx has already been called by the executable.
|
||||
if (auto E = LoadDIA(DiaDataSource))
|
||||
return E;
|
||||
|
||||
llvm::SmallVector<UTF16, 128> Path16;
|
||||
if (!llvm::convertUTF8ToUTF16String(Path, Path16))
|
||||
return make_error<GenericError>(generic_error_code::invalid_path);
|
||||
|
||||
const wchar_t *Path16Str = reinterpret_cast<const wchar_t*>(Path16.data());
|
||||
HRESULT HR;
|
||||
if (FAILED(HR = DiaDataSource->loadDataFromPdb(Path16Str))) {
|
||||
return ErrorFromHResult(HR, "Calling loadDataFromPdb {0}", Path);
|
||||
}
|
||||
|
||||
if (FAILED(HR = DiaDataSource->openSession(&DiaSession)))
|
||||
return ErrorFromHResult(HR, "Calling openSession");
|
||||
|
||||
Session.reset(new DIASession(DiaSession));
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
Error DIASession::createFromExe(StringRef Path,
|
||||
std::unique_ptr<IPDBSession> &Session) {
|
||||
CComPtr<IDiaDataSource> DiaDataSource;
|
||||
CComPtr<IDiaSession> DiaSession;
|
||||
|
||||
// We assume that CoInitializeEx has already been called by the executable.
|
||||
if (auto EC = LoadDIA(DiaDataSource))
|
||||
return EC;
|
||||
|
||||
llvm::SmallVector<UTF16, 128> Path16;
|
||||
if (!llvm::convertUTF8ToUTF16String(Path, Path16))
|
||||
return make_error<GenericError>(generic_error_code::invalid_path, Path);
|
||||
|
||||
const wchar_t *Path16Str = reinterpret_cast<const wchar_t *>(Path16.data());
|
||||
HRESULT HR;
|
||||
if (FAILED(HR = DiaDataSource->loadDataForExe(Path16Str, nullptr, nullptr)))
|
||||
return ErrorFromHResult(HR, "Calling loadDataForExe");
|
||||
|
||||
if (FAILED(HR = DiaDataSource->openSession(&DiaSession)))
|
||||
return ErrorFromHResult(HR, "Calling openSession");
|
||||
|
||||
Session.reset(new DIASession(DiaSession));
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
uint64_t DIASession::getLoadAddress() const {
|
||||
uint64_t LoadAddress;
|
||||
bool success = (S_OK == Session->get_loadAddress(&LoadAddress));
|
||||
return (success) ? LoadAddress : 0;
|
||||
}
|
||||
|
||||
void DIASession::setLoadAddress(uint64_t Address) {
|
||||
Session->put_loadAddress(Address);
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbolExe> DIASession::getGlobalScope() {
|
||||
CComPtr<IDiaSymbol> GlobalScope;
|
||||
if (S_OK != Session->get_globalScope(&GlobalScope))
|
||||
return nullptr;
|
||||
|
||||
auto RawSymbol = llvm::make_unique<DIARawSymbol>(*this, GlobalScope);
|
||||
auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol)));
|
||||
std::unique_ptr<PDBSymbolExe> ExeSymbol(
|
||||
static_cast<PDBSymbolExe *>(PdbSymbol.release()));
|
||||
return ExeSymbol;
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbol> DIASession::getSymbolById(uint32_t SymbolId) const {
|
||||
CComPtr<IDiaSymbol> LocatedSymbol;
|
||||
if (S_OK != Session->symbolById(SymbolId, &LocatedSymbol))
|
||||
return nullptr;
|
||||
|
||||
auto RawSymbol = llvm::make_unique<DIARawSymbol>(*this, LocatedSymbol);
|
||||
return PDBSymbol::create(*this, std::move(RawSymbol));
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbol>
|
||||
DIASession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
|
||||
enum SymTagEnum EnumVal = static_cast<enum SymTagEnum>(Type);
|
||||
|
||||
CComPtr<IDiaSymbol> Symbol;
|
||||
if (S_OK != Session->findSymbolByVA(Address, EnumVal, &Symbol)) {
|
||||
ULONGLONG LoadAddr = 0;
|
||||
if (S_OK != Session->get_loadAddress(&LoadAddr))
|
||||
return nullptr;
|
||||
DWORD RVA = static_cast<DWORD>(Address - LoadAddr);
|
||||
if (S_OK != Session->findSymbolByRVA(RVA, EnumVal, &Symbol))
|
||||
return nullptr;
|
||||
}
|
||||
auto RawSymbol = llvm::make_unique<DIARawSymbol>(*this, Symbol);
|
||||
return PDBSymbol::create(*this, std::move(RawSymbol));
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumLineNumbers>
|
||||
DIASession::findLineNumbers(const PDBSymbolCompiland &Compiland,
|
||||
const IPDBSourceFile &File) const {
|
||||
const DIARawSymbol &RawCompiland =
|
||||
static_cast<const DIARawSymbol &>(Compiland.getRawSymbol());
|
||||
const DIASourceFile &RawFile = static_cast<const DIASourceFile &>(File);
|
||||
|
||||
CComPtr<IDiaEnumLineNumbers> LineNumbers;
|
||||
if (S_OK !=
|
||||
Session->findLines(RawCompiland.getDiaSymbol(), RawFile.getDiaFile(),
|
||||
&LineNumbers))
|
||||
return nullptr;
|
||||
|
||||
return llvm::make_unique<DIAEnumLineNumbers>(LineNumbers);
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumLineNumbers>
|
||||
DIASession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const {
|
||||
CComPtr<IDiaEnumLineNumbers> LineNumbers;
|
||||
if (S_OK != Session->findLinesByVA(Address, Length, &LineNumbers))
|
||||
return nullptr;
|
||||
|
||||
return llvm::make_unique<DIAEnumLineNumbers>(LineNumbers);
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumSourceFiles>
|
||||
DIASession::findSourceFiles(const PDBSymbolCompiland *Compiland,
|
||||
llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const {
|
||||
IDiaSymbol *DiaCompiland = nullptr;
|
||||
CComBSTR Utf16Pattern;
|
||||
if (!Pattern.empty())
|
||||
Utf16Pattern = CComBSTR(Pattern.data());
|
||||
|
||||
if (Compiland)
|
||||
DiaCompiland = static_cast<const DIARawSymbol &>(Compiland->getRawSymbol())
|
||||
.getDiaSymbol();
|
||||
|
||||
Flags = static_cast<PDB_NameSearchFlags>(
|
||||
Flags | PDB_NameSearchFlags::NS_FileNameExtMatch);
|
||||
CComPtr<IDiaEnumSourceFiles> SourceFiles;
|
||||
if (S_OK !=
|
||||
Session->findFile(DiaCompiland, Utf16Pattern.m_str, Flags, &SourceFiles))
|
||||
return nullptr;
|
||||
return llvm::make_unique<DIAEnumSourceFiles>(*this, SourceFiles);
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBSourceFile>
|
||||
DIASession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
|
||||
llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const {
|
||||
auto SourceFiles = findSourceFiles(Compiland, Pattern, Flags);
|
||||
if (!SourceFiles || SourceFiles->getChildCount() == 0)
|
||||
return nullptr;
|
||||
return SourceFiles->getNext();
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
|
||||
DIASession::findCompilandsForSourceFile(llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const {
|
||||
auto File = findOneSourceFile(nullptr, Pattern, Flags);
|
||||
if (!File)
|
||||
return nullptr;
|
||||
return File->getCompilands();
|
||||
}
|
||||
|
||||
std::unique_ptr<PDBSymbolCompiland>
|
||||
DIASession::findOneCompilandForSourceFile(llvm::StringRef Pattern,
|
||||
PDB_NameSearchFlags Flags) const {
|
||||
auto Compilands = findCompilandsForSourceFile(Pattern, Flags);
|
||||
if (!Compilands || Compilands->getChildCount() == 0)
|
||||
return nullptr;
|
||||
return Compilands->getNext();
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumSourceFiles> DIASession::getAllSourceFiles() const {
|
||||
CComPtr<IDiaEnumSourceFiles> Files;
|
||||
if (S_OK != Session->findFile(nullptr, nullptr, nsNone, &Files))
|
||||
return nullptr;
|
||||
|
||||
return llvm::make_unique<DIAEnumSourceFiles>(*this, Files);
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumSourceFiles> DIASession::getSourceFilesForCompiland(
|
||||
const PDBSymbolCompiland &Compiland) const {
|
||||
CComPtr<IDiaEnumSourceFiles> Files;
|
||||
|
||||
const DIARawSymbol &RawSymbol =
|
||||
static_cast<const DIARawSymbol &>(Compiland.getRawSymbol());
|
||||
if (S_OK !=
|
||||
Session->findFile(RawSymbol.getDiaSymbol(), nullptr, nsNone, &Files))
|
||||
return nullptr;
|
||||
|
||||
return llvm::make_unique<DIAEnumSourceFiles>(*this, Files);
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBSourceFile>
|
||||
DIASession::getSourceFileById(uint32_t FileId) const {
|
||||
CComPtr<IDiaSourceFile> LocatedFile;
|
||||
if (S_OK != Session->findFileById(FileId, &LocatedFile))
|
||||
return nullptr;
|
||||
|
||||
return llvm::make_unique<DIASourceFile>(*this, LocatedFile);
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumDataStreams> DIASession::getDebugStreams() const {
|
||||
CComPtr<IDiaEnumDebugStreams> DiaEnumerator;
|
||||
if (S_OK != Session->getEnumDebugStreams(&DiaEnumerator))
|
||||
return nullptr;
|
||||
|
||||
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);
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
//===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- 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/DIASourceFile.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h"
|
||||
#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
|
||||
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::pdb;
|
||||
|
||||
DIASourceFile::DIASourceFile(const DIASession &PDBSession,
|
||||
CComPtr<IDiaSourceFile> DiaSourceFile)
|
||||
: Session(PDBSession), SourceFile(DiaSourceFile) {}
|
||||
|
||||
std::string DIASourceFile::getFileName() const {
|
||||
CComBSTR FileName16;
|
||||
HRESULT Result = SourceFile->get_fileName(&FileName16);
|
||||
if (S_OK != Result)
|
||||
return std::string();
|
||||
|
||||
std::string FileName8;
|
||||
llvm::ArrayRef<char> FileNameBytes(reinterpret_cast<char *>(FileName16.m_str),
|
||||
FileName16.ByteLength());
|
||||
llvm::convertUTF16ToUTF8String(FileNameBytes, FileName8);
|
||||
return FileName8;
|
||||
}
|
||||
|
||||
uint32_t DIASourceFile::getUniqueId() const {
|
||||
DWORD Id;
|
||||
return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
|
||||
}
|
||||
|
||||
std::string DIASourceFile::getChecksum() const {
|
||||
DWORD ByteSize = 0;
|
||||
HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr);
|
||||
if (ByteSize == 0)
|
||||
return std::string();
|
||||
std::vector<BYTE> ChecksumBytes(ByteSize);
|
||||
Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]);
|
||||
if (S_OK != Result)
|
||||
return std::string();
|
||||
return std::string(ChecksumBytes.begin(), ChecksumBytes.end());
|
||||
}
|
||||
|
||||
PDB_Checksum DIASourceFile::getChecksumType() const {
|
||||
DWORD Type;
|
||||
HRESULT Result = SourceFile->get_checksumType(&Type);
|
||||
if (S_OK != Result)
|
||||
return PDB_Checksum::None;
|
||||
return static_cast<PDB_Checksum>(Type);
|
||||
}
|
||||
|
||||
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
|
||||
DIASourceFile::getCompilands() const {
|
||||
CComPtr<IDiaEnumSymbols> DiaEnumerator;
|
||||
HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
|
||||
if (S_OK != Result)
|
||||
return nullptr;
|
||||
|
||||
auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
|
||||
new DIAEnumSymbols(Session, DiaEnumerator));
|
||||
return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
|
||||
new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator)));
|
||||
}
|
62
external/llvm/lib/DebugInfo/PDB/DIA/DIATable.cpp
vendored
62
external/llvm/lib/DebugInfo/PDB/DIA/DIATable.cpp
vendored
@ -1,62 +0,0 @@
|
||||
//===- 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;
|
||||
return PDB_TableType::TableInvalid;
|
||||
}
|
Reference in New Issue
Block a user