2017-01-25 22:38:55 +00:00
|
|
|
//===- NativeSession.cpp - Native implementation of IPDBSession -*- C++ -*-===//
|
2016-04-25 17:38:08 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
|
|
|
|
|
2016-11-23 23:16:32 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-07-12 19:38:11 +00:00
|
|
|
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
|
2016-05-06 20:51:57 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/GenericError.h"
|
2016-04-25 17:38:08 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
|
2017-07-12 19:38:11 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeBuiltinSymbol.h"
|
2017-06-28 22:47:40 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
|
2017-03-29 19:27:08 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
|
2017-01-25 22:38:55 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/Native/RawError.h"
|
2016-04-25 17:38:08 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
|
2016-11-23 23:16:32 +00:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2017-03-02 20:52:51 +00:00
|
|
|
#include "llvm/Support/BinaryByteStream.h"
|
2016-11-23 23:16:32 +00:00
|
|
|
#include "llvm/Support/Error.h"
|
2016-04-25 17:38:08 +00:00
|
|
|
#include "llvm/Support/ErrorOr.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2017-06-28 22:47:40 +00:00
|
|
|
|
2016-11-23 23:16:32 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
2017-06-28 22:47:40 +00:00
|
|
|
#include <utility>
|
2016-04-25 17:38:08 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
2016-07-22 19:56:05 +00:00
|
|
|
using namespace llvm::msf;
|
2016-04-29 17:28:47 +00:00
|
|
|
using namespace llvm::pdb;
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2017-07-12 19:38:11 +00:00
|
|
|
namespace {
|
|
|
|
// Maps codeview::SimpleTypeKind of a built-in type to the parameters necessary
|
|
|
|
// to instantiate a NativeBuiltinSymbol for that type.
|
2017-07-12 19:46:35 +00:00
|
|
|
static const struct BuiltinTypeEntry {
|
2017-07-12 19:38:11 +00:00
|
|
|
codeview::SimpleTypeKind Kind;
|
|
|
|
PDB_BuiltinType Type;
|
|
|
|
uint32_t Size;
|
|
|
|
} BuiltinTypes[] = {
|
|
|
|
{codeview::SimpleTypeKind::Int32, PDB_BuiltinType::Int, 4},
|
|
|
|
{codeview::SimpleTypeKind::UInt32, PDB_BuiltinType::UInt, 4},
|
|
|
|
{codeview::SimpleTypeKind::UInt32Long, PDB_BuiltinType::UInt, 4},
|
|
|
|
{codeview::SimpleTypeKind::UInt64Quad, PDB_BuiltinType::UInt, 8},
|
|
|
|
{codeview::SimpleTypeKind::NarrowCharacter, PDB_BuiltinType::Char, 1},
|
|
|
|
{codeview::SimpleTypeKind::SignedCharacter, PDB_BuiltinType::Char, 1},
|
|
|
|
{codeview::SimpleTypeKind::UnsignedCharacter, PDB_BuiltinType::UInt, 1},
|
|
|
|
{codeview::SimpleTypeKind::UInt16Short, PDB_BuiltinType::UInt, 2},
|
|
|
|
{codeview::SimpleTypeKind::Boolean8, PDB_BuiltinType::Bool, 1}
|
|
|
|
// This table can be grown as necessary, but these are the only types we've
|
|
|
|
// needed so far.
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
|
|
|
|
std::unique_ptr<BumpPtrAllocator> Allocator)
|
2016-07-22 19:56:26 +00:00
|
|
|
: Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {}
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::~NativeSession() = default;
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
Error NativeSession::createFromPdb(StringRef Path,
|
|
|
|
std::unique_ptr<IPDBSession> &Session) {
|
2016-04-25 17:38:08 +00:00
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
|
|
|
|
/*RequiresNullTerminator=*/false);
|
2016-07-06 17:25:12 +00:00
|
|
|
if (!ErrorOrBuffer)
|
2016-11-23 23:16:32 +00:00
|
|
|
return make_error<GenericError>(generic_error_code::invalid_path);
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-06-10 05:10:19 +00:00
|
|
|
std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
|
2017-02-28 00:04:07 +00:00
|
|
|
auto Stream = llvm::make_unique<MemoryBufferByteStream>(
|
|
|
|
std::move(Buffer), llvm::support::little);
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-07-22 19:56:26 +00:00
|
|
|
auto Allocator = llvm::make_unique<BumpPtrAllocator>();
|
2017-02-16 23:35:45 +00:00
|
|
|
auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator);
|
2016-05-06 20:51:57 +00:00
|
|
|
if (auto EC = File->parseFileHeaders())
|
|
|
|
return EC;
|
|
|
|
if (auto EC = File->parseStreamData())
|
|
|
|
return EC;
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-07-22 19:56:26 +00:00
|
|
|
Session =
|
2017-01-25 22:38:55 +00:00
|
|
|
llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator));
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2016-05-06 20:51:57 +00:00
|
|
|
return Error::success();
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
Error NativeSession::createFromExe(StringRef Path,
|
|
|
|
std::unique_ptr<IPDBSession> &Session) {
|
2016-11-23 23:16:32 +00:00
|
|
|
return make_error<RawError>(raw_error_code::feature_unsupported);
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 22:47:40 +00:00
|
|
|
std::unique_ptr<PDBSymbolCompiland>
|
|
|
|
NativeSession::createCompilandSymbol(DbiModuleDescriptor MI) {
|
2017-07-12 19:38:11 +00:00
|
|
|
const auto Id = static_cast<SymIndexId>(SymbolCache.size());
|
2017-06-28 22:47:40 +00:00
|
|
|
SymbolCache.push_back(
|
|
|
|
llvm::make_unique<NativeCompilandSymbol>(*this, Id, MI));
|
|
|
|
return llvm::make_unique<PDBSymbolCompiland>(
|
|
|
|
*this, std::unique_ptr<IPDBRawSymbol>(SymbolCache[Id]->clone()));
|
|
|
|
}
|
|
|
|
|
2017-07-12 19:38:11 +00:00
|
|
|
SymIndexId NativeSession::findSymbolByTypeIndex(codeview::TypeIndex Index) {
|
|
|
|
// First see if it's already in our cache.
|
|
|
|
const auto Entry = TypeIndexToSymbolId.find(Index);
|
|
|
|
if (Entry != TypeIndexToSymbolId.end())
|
|
|
|
return Entry->second;
|
|
|
|
|
|
|
|
// Symbols for built-in types are created on the fly.
|
|
|
|
if (Index.isSimple()) {
|
|
|
|
// FIXME: We will eventually need to handle pointers to other simple types,
|
|
|
|
// which are still simple types in the world of CodeView TypeIndexes.
|
|
|
|
if (Index.getSimpleMode() != codeview::SimpleTypeMode::Direct)
|
|
|
|
return 0;
|
|
|
|
const auto Kind = Index.getSimpleKind();
|
2017-07-12 19:46:35 +00:00
|
|
|
const auto It =
|
|
|
|
std::find_if(std::begin(BuiltinTypes), std::end(BuiltinTypes),
|
|
|
|
[Kind](const BuiltinTypeEntry &Builtin) {
|
|
|
|
return Builtin.Kind == Kind;
|
|
|
|
});
|
2017-07-12 19:38:11 +00:00
|
|
|
if (It == std::end(BuiltinTypes))
|
|
|
|
return 0;
|
|
|
|
SymIndexId Id = SymbolCache.size();
|
|
|
|
SymbolCache.emplace_back(
|
2017-07-12 19:46:35 +00:00
|
|
|
llvm::make_unique<NativeBuiltinSymbol>(*this, Id, It->Type, It->Size));
|
2017-07-12 19:38:11 +00:00
|
|
|
TypeIndexToSymbolId[Index] = Id;
|
|
|
|
return Id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Look up PDB type by type index
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
uint64_t NativeSession::getLoadAddress() const { return 0; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
void NativeSession::setLoadAddress(uint64_t Address) {}
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2017-06-22 18:42:23 +00:00
|
|
|
std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
|
2017-07-12 19:38:11 +00:00
|
|
|
const auto Id = static_cast<SymIndexId>(SymbolCache.size());
|
2017-06-28 22:47:40 +00:00
|
|
|
SymbolCache.push_back(llvm::make_unique<NativeExeSymbol>(*this, Id));
|
|
|
|
auto RawSymbol = SymbolCache[Id]->clone();
|
2017-02-24 00:10:47 +00:00
|
|
|
auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol)));
|
|
|
|
std::unique_ptr<PDBSymbolExe> ExeSymbol(
|
2017-06-22 18:42:23 +00:00
|
|
|
static_cast<PDBSymbolExe *>(PdbSymbol.release()));
|
2017-02-24 00:10:47 +00:00
|
|
|
return ExeSymbol;
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
std::unique_ptr<PDBSymbol>
|
|
|
|
NativeSession::getSymbolById(uint32_t SymbolId) const {
|
2017-06-28 22:47:40 +00:00
|
|
|
// If the caller has a SymbolId, it'd better be in our SymbolCache.
|
|
|
|
return SymbolId < SymbolCache.size()
|
|
|
|
? PDBSymbol::create(*this, SymbolCache[SymbolId]->clone())
|
|
|
|
: nullptr;
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<PDBSymbol>
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumLineNumbers>
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
|
|
|
|
const IPDBSourceFile &File) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumLineNumbers>
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::findLineNumbersByAddress(uint64_t Address,
|
|
|
|
uint32_t Length) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumSourceFiles>
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
|
|
|
|
StringRef Pattern,
|
|
|
|
PDB_NameSearchFlags Flags) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBSourceFile>
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
|
|
|
|
StringRef Pattern,
|
|
|
|
PDB_NameSearchFlags Flags) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::findCompilandsForSourceFile(StringRef Pattern,
|
|
|
|
PDB_NameSearchFlags Flags) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<PDBSymbolCompiland>
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::findOneCompilandForSourceFile(StringRef Pattern,
|
|
|
|
PDB_NameSearchFlags Flags) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
|
2016-04-25 17:38:08 +00:00
|
|
|
const PDBSymbolCompiland &Compiland) const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<IPDBSourceFile>
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::getSourceFileById(uint32_t FileId) const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
|
2016-04-25 17:38:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|