2017-01-25 22:38:55 +00:00
|
|
|
//===- NativeSession.cpp - Native implementation of IPDBSession -*- C++ -*-===//
|
2016-04-25 17:38:08 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-04-25 17:38:08 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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-04-25 17:38:08 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
|
2017-06-28 22:47:40 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
|
2017-08-04 22:37:58 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h"
|
2017-03-29 19:27:08 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
|
2018-09-07 00:12:56 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
|
2017-01-25 22:38:55 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/Native/RawError.h"
|
2018-09-07 00:12:34 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
|
2017-08-04 22:37:58 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
|
2016-04-25 17:38:08 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
|
2017-08-04 22:37:58 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.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>
|
2017-08-04 22:37:58 +00:00
|
|
|
#include <cassert>
|
2016-11-23 23:16:32 +00:00
|
|
|
#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
|
|
|
|
2018-09-07 00:12:34 +00:00
|
|
|
static DbiStream *getDbiStreamPtr(PDBFile &File) {
|
|
|
|
Expected<DbiStream &> DbiS = File.getPDBDbiStream();
|
|
|
|
if (DbiS)
|
|
|
|
return &DbiS.get();
|
|
|
|
|
|
|
|
consumeError(DbiS.takeError());
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-12 19:38:11 +00:00
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
|
|
|
|
std::unique_ptr<BumpPtrAllocator> Allocator)
|
2018-09-07 00:12:34 +00:00
|
|
|
: Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)),
|
|
|
|
Cache(*this, getDbiStreamPtr(*Pdb)) {}
|
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-10-20 19:48:26 +00:00
|
|
|
Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer,
|
2017-01-25 22:38:55 +00:00
|
|
|
std::unique_ptr<IPDBSession> &Session) {
|
2017-10-20 19:48:26 +00:00
|
|
|
StringRef Path = Buffer->getBufferIdentifier();
|
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-01-25 22:38:55 +00:00
|
|
|
uint64_t NativeSession::getLoadAddress() const { return 0; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2018-02-23 00:02:27 +00:00
|
|
|
bool NativeSession::setLoadAddress(uint64_t Address) { return false; }
|
2016-04-25 17:38:08 +00:00
|
|
|
|
2017-06-22 18:42:23 +00:00
|
|
|
std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() {
|
2018-09-05 23:30:38 +00:00
|
|
|
return PDBSymbol::createAs<PDBSymbolExe>(*this, getNativeGlobalScope());
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 22:38:55 +00:00
|
|
|
std::unique_ptr<PDBSymbol>
|
2018-09-10 21:30:59 +00:00
|
|
|
NativeSession::getSymbolById(SymIndexId SymbolId) const {
|
2018-09-07 00:12:34 +00:00
|
|
|
return Cache.getSymbolById(SymbolId);
|
2016-04-25 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 22:10:02 +00:00
|
|
|
bool NativeSession::addressForVA(uint64_t VA, uint32_t &Section,
|
|
|
|
uint32_t &Offset) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeSession::addressForRVA(uint32_t VA, uint32_t &Section,
|
|
|
|
uint32_t &Offset) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-10 17:33:18 +00:00
|
|
|
std::unique_ptr<PDBSymbol>
|
|
|
|
NativeSession::findSymbolByRVA(uint32_t RVA, PDB_SymType Type) const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<PDBSymbol>
|
|
|
|
NativeSession::findSymbolBySectOffset(uint32_t Sect, uint32_t Offset,
|
|
|
|
PDB_SymType Type) const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-25 17:38:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-03-26 22:13:22 +00:00
|
|
|
std::unique_ptr<IPDBEnumLineNumbers>
|
|
|
|
NativeSession::findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-15 06:04:51 +00:00
|
|
|
std::unique_ptr<IPDBEnumLineNumbers>
|
|
|
|
NativeSession::findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset,
|
|
|
|
uint32_t Length) const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-25 17:38:08 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-11-16 14:33:09 +00:00
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumTables> NativeSession::getEnumTables() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-13 17:46:06 +00:00
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumInjectedSources>
|
|
|
|
NativeSession::getInjectedSources() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-22 04:08:15 +00:00
|
|
|
|
|
|
|
std::unique_ptr<IPDBEnumSectionContribs>
|
|
|
|
NativeSession::getSectionContribs() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-09-05 23:30:38 +00:00
|
|
|
|
2018-10-23 08:14:53 +00:00
|
|
|
std::unique_ptr<IPDBEnumFrameData>
|
|
|
|
NativeSession::getFrameData() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-09-07 00:12:34 +00:00
|
|
|
void NativeSession::initializeExeSymbol() {
|
|
|
|
if (ExeSymbol == 0)
|
|
|
|
ExeSymbol = Cache.createSymbol<NativeExeSymbol>();
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeExeSymbol &NativeSession::getNativeGlobalScope() const {
|
|
|
|
const_cast<NativeSession &>(*this).initializeExeSymbol();
|
|
|
|
|
|
|
|
return Cache.getNativeSymbolById<NativeExeSymbol>(ExeSymbol);
|
2018-09-05 23:30:38 +00:00
|
|
|
}
|