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
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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.
|
2017-10-21 03:48:26 +08:00
|
|
|
if (Type == PDB_ReaderType::Native) {
|
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
|
|
|
|
/*RequiresNullTerminator=*/false);
|
|
|
|
if (!ErrorOrBuffer)
|
2018-09-01 01:41:58 +08:00
|
|
|
return errorCodeToError(ErrorOrBuffer.getError());
|
2017-10-21 03:48:26 +08:00
|
|
|
|
|
|
|
return NativeSession::createFromPdb(std::move(*ErrorOrBuffer), 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.
|
2017-01-27 08:01:55 +08:00
|
|
|
if (Type == PDB_ReaderType::Native)
|
2017-01-26 06:38:55 +08:00
|
|
|
return NativeSession::createFromExe(Path, Session);
|
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
|
|
|
}
|