1 //===- PDB.cpp - base header file for creating a PDB reader ---------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/PDB/PDB.h"
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/Config/config.h"
12 #include "llvm/DebugInfo/PDB/GenericError.h"
13 #if LLVM_ENABLE_DIA_SDK
14 #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
16 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
17 #include "llvm/Support/Error.h"
18 #include "llvm/Support/MemoryBuffer.h"
21 using namespace llvm::pdb
;
23 Error
llvm::pdb::loadDataForPDB(PDB_ReaderType Type
, StringRef Path
,
24 std::unique_ptr
<IPDBSession
> &Session
) {
25 // Create the correct concrete instance type based on the value of Type.
26 if (Type
== PDB_ReaderType::Native
) {
27 ErrorOr
<std::unique_ptr
<MemoryBuffer
>> ErrorOrBuffer
=
28 MemoryBuffer::getFileOrSTDIN(Path
, /*FileSize=*/-1,
29 /*RequiresNullTerminator=*/false);
31 return errorCodeToError(ErrorOrBuffer
.getError());
33 return NativeSession::createFromPdb(std::move(*ErrorOrBuffer
), Session
);
36 #if LLVM_ENABLE_DIA_SDK
37 return DIASession::createFromPdb(Path
, Session
);
39 return make_error
<PDBError
>(pdb_error_code::dia_sdk_not_present
);
43 Error
llvm::pdb::loadDataForEXE(PDB_ReaderType Type
, StringRef Path
,
44 std::unique_ptr
<IPDBSession
> &Session
) {
45 // Create the correct concrete instance type based on the value of Type.
46 if (Type
== PDB_ReaderType::Native
)
47 return NativeSession::createFromExe(Path
, Session
);
49 #if LLVM_ENABLE_DIA_SDK
50 return DIASession::createFromExe(Path
, Session
);
52 return make_error
<PDBError
>(pdb_error_code::dia_sdk_not_present
);