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