Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 1 | //===- PDB.cpp - base header file for creating a PDB reader ---------------===// |
Zachary Turner | 0e9e663 | 2015-02-06 20:30:52 +0000 | [diff] [blame] | 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 | |
Zachary Turner | 52c9f88 | 2015-02-14 03:53:56 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/PDB/PDB.h" |
Zachary Turner | 0e9e663 | 2015-02-06 20:30:52 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/StringRef.h" |
Zachary Turner | 52c9f88 | 2015-02-14 03:53:56 +0000 | [diff] [blame] | 12 | #include "llvm/Config/config.h" |
Zachary Turner | 2b37017 | 2016-05-06 20:59:35 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/PDB/GenericError.h" |
Michal Gorny | 89b6f16 | 2017-01-02 18:19:35 +0000 | [diff] [blame] | 14 | #if LLVM_ENABLE_DIA_SDK |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/DIA/DIASession.h" |
| 16 | #endif |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/Native/NativeSession.h" |
Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Error.h" |
Zachary Turner | bd159d3 | 2017-11-17 01:00:35 +0000 | [diff] [blame] | 19 | #include "llvm/Support/MemoryBuffer.h" |
Zachary Turner | 0e9e663 | 2015-02-06 20:30:52 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
Zachary Turner | ec28fc3 | 2016-05-04 20:32:13 +0000 | [diff] [blame] | 22 | using namespace llvm::pdb; |
Zachary Turner | 0e9e663 | 2015-02-06 20:30:52 +0000 | [diff] [blame] | 23 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 24 | Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path, |
| 25 | std::unique_ptr<IPDBSession> &Session) { |
Zachary Turner | 0e9e663 | 2015-02-06 20:30:52 +0000 | [diff] [blame] | 26 | // Create the correct concrete instance type based on the value of Type. |
Peter Collingbourne | 75257bc | 2017-10-20 19:48:26 +0000 | [diff] [blame] | 27 | if (Type == PDB_ReaderType::Native) { |
| 28 | ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer = |
| 29 | MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, |
| 30 | /*RequiresNullTerminator=*/false); |
| 31 | if (!ErrorOrBuffer) |
| 32 | return make_error<GenericError>(generic_error_code::invalid_path, Path); |
| 33 | |
| 34 | return NativeSession::createFromPdb(std::move(*ErrorOrBuffer), Session); |
| 35 | } |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 36 | |
Michal Gorny | 89b6f16 | 2017-01-02 18:19:35 +0000 | [diff] [blame] | 37 | #if LLVM_ENABLE_DIA_SDK |
Zachary Turner | ccf0415 | 2015-02-28 20:23:18 +0000 | [diff] [blame] | 38 | return DIASession::createFromPdb(Path, Session); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 39 | #else |
Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 40 | return make_error<GenericError>("DIA is not installed on the system"); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 41 | #endif |
Zachary Turner | 0e9e663 | 2015-02-06 20:30:52 +0000 | [diff] [blame] | 42 | } |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 43 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 44 | Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path, |
| 45 | std::unique_ptr<IPDBSession> &Session) { |
Dave Bartolomeo | ea039c1 | 2015-12-17 20:54:16 +0000 | [diff] [blame] | 46 | // Create the correct concrete instance type based on the value of Type. |
Adrian McCarthy | 8f71319 | 2017-01-27 00:01:55 +0000 | [diff] [blame] | 47 | if (Type == PDB_ReaderType::Native) |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 48 | return NativeSession::createFromExe(Path, Session); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 49 | |
Michal Gorny | 89b6f16 | 2017-01-02 18:19:35 +0000 | [diff] [blame] | 50 | #if LLVM_ENABLE_DIA_SDK |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 51 | return DIASession::createFromExe(Path, Session); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 52 | #else |
Eugene Zelenko | 4fcfc19 | 2017-06-30 23:06:03 +0000 | [diff] [blame] | 53 | return make_error<GenericError>("DIA is not installed on the system"); |
Zachary Turner | 0a43efe | 2016-04-25 17:38:08 +0000 | [diff] [blame] | 54 | #endif |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 55 | } |