2017-07-01 09:22:02 -04:00
|
|
|
//===- PDB.cpp - base header file for creating a PDB reader ---------------===//
|
2015-05-27 14:44:32 -04:00
|
|
|
//
|
2019-08-20 16:50:12 -04: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
|
2015-05-27 14:44:32 -04:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/PDB.h"
|
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
|
#include "llvm/Config/config.h"
|
2016-07-23 16:41:05 -04:00
|
|
|
#include "llvm/DebugInfo/PDB/GenericError.h"
|
2017-01-02 14:17:04 -05:00
|
|
|
#if LLVM_ENABLE_DIA_SDK
|
2015-05-27 14:44:32 -04:00
|
|
|
#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
|
|
|
|
|
#endif
|
2017-04-16 12:01:22 -04:00
|
|
|
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
|
2017-07-01 09:22:02 -04:00
|
|
|
#include "llvm/Support/Error.h"
|
2017-12-18 15:10:56 -05:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2015-05-27 14:44:32 -04:00
|
|
|
|
|
|
|
|
using namespace llvm;
|
2016-07-23 16:41:05 -04:00
|
|
|
using namespace llvm::pdb;
|
2015-05-27 14:44:32 -04:00
|
|
|
|
2016-07-23 16:41:05 -04:00
|
|
|
Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
|
|
|
|
|
std::unique_ptr<IPDBSession> &Session) {
|
2015-05-27 14:44:32 -04:00
|
|
|
// Create the correct concrete instance type based on the value of Type.
|
2020-07-26 15:36:28 -04:00
|
|
|
if (Type == PDB_ReaderType::Native)
|
|
|
|
|
return NativeSession::createFromPdbPath(Path, Session);
|
2016-07-23 16:41:05 -04:00
|
|
|
|
2017-01-02 14:17:04 -05:00
|
|
|
#if LLVM_ENABLE_DIA_SDK
|
2015-05-27 14:44:32 -04:00
|
|
|
return DIASession::createFromPdb(Path, Session);
|
2016-07-23 16:41:05 -04:00
|
|
|
#else
|
2019-01-19 05:01:25 -05:00
|
|
|
return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
|
2015-05-27 14:44:32 -04:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 16:41:05 -04:00
|
|
|
Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
|
|
|
|
|
std::unique_ptr<IPDBSession> &Session) {
|
2015-12-30 06:46:15 -05:00
|
|
|
// Create the correct concrete instance type based on the value of Type.
|
2020-07-26 15:36:28 -04:00
|
|
|
if (Type == PDB_ReaderType::Native) {
|
|
|
|
|
Expected<std::string> PdbPath = NativeSession::searchForPdb({Path});
|
|
|
|
|
if (!PdbPath)
|
|
|
|
|
return PdbPath.takeError();
|
|
|
|
|
return NativeSession::createFromPdbPath(PdbPath.get(), Session);
|
|
|
|
|
}
|
2016-07-23 16:41:05 -04:00
|
|
|
|
2017-01-02 14:17:04 -05:00
|
|
|
#if LLVM_ENABLE_DIA_SDK
|
2015-05-27 14:44:32 -04:00
|
|
|
return DIASession::createFromExe(Path, Session);
|
2016-07-23 16:41:05 -04:00
|
|
|
#else
|
2019-01-19 05:01:25 -05:00
|
|
|
return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
|
2015-05-27 14:44:32 -04:00
|
|
|
#endif
|
|
|
|
|
}
|