121
|
1 //===- PDB.cpp - base header file for creating a PDB reader ---------------===//
|
83
|
2 //
|
|
3 // The LLVM Compiler Infrastructure
|
|
4 //
|
|
5 // This file is distributed under the University of Illinois Open Source
|
|
6 // License. See LICENSE.TXT for details.
|
|
7 //
|
|
8 //===----------------------------------------------------------------------===//
|
|
9
|
|
10 #include "llvm/DebugInfo/PDB/PDB.h"
|
|
11 #include "llvm/ADT/StringRef.h"
|
|
12 #include "llvm/Config/config.h"
|
120
|
13 #include "llvm/DebugInfo/PDB/GenericError.h"
|
121
|
14 #if LLVM_ENABLE_DIA_SDK
|
83
|
15 #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
|
|
16 #endif
|
121
|
17 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
|
|
18 #include "llvm/Support/Error.h"
|
83
|
19
|
|
20 using namespace llvm;
|
120
|
21 using namespace llvm::pdb;
|
83
|
22
|
120
|
23 Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
|
|
24 std::unique_ptr<IPDBSession> &Session) {
|
83
|
25 // Create the correct concrete instance type based on the value of Type.
|
121
|
26 if (Type == PDB_ReaderType::Native) {
|
|
27 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
|
|
28 MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
|
|
29 /*RequiresNullTerminator=*/false);
|
|
30 if (!ErrorOrBuffer)
|
|
31 return make_error<GenericError>(generic_error_code::invalid_path, Path);
|
120
|
32
|
121
|
33 return NativeSession::createFromPdb(std::move(*ErrorOrBuffer), Session);
|
|
34 }
|
|
35
|
|
36 #if LLVM_ENABLE_DIA_SDK
|
95
|
37 return DIASession::createFromPdb(Path, Session);
|
120
|
38 #else
|
121
|
39 return make_error<GenericError>("DIA is not installed on the system");
|
83
|
40 #endif
|
|
41 }
|
95
|
42
|
120
|
43 Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
|
|
44 std::unique_ptr<IPDBSession> &Session) {
|
100
|
45 // Create the correct concrete instance type based on the value of Type.
|
121
|
46 if (Type == PDB_ReaderType::Native)
|
|
47 return NativeSession::createFromExe(Path, Session);
|
120
|
48
|
121
|
49 #if LLVM_ENABLE_DIA_SDK
|
95
|
50 return DIASession::createFromExe(Path, Session);
|
120
|
51 #else
|
121
|
52 return make_error<GenericError>("DIA is not installed on the system");
|
95
|
53 #endif
|
|
54 }
|