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