blob: 40f5ae9ba8455252919e8a228681eed1b5f0a105 [file] [log] [blame]
Eugene Zelenko4fcfc192017-06-30 23:06:03 +00001//===- PDB.cpp - base header file for creating a PDB reader ---------------===//
Zachary Turner0e9e6632015-02-06 20:30:52 +00002//
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 Turner52c9f882015-02-14 03:53:56 +000010#include "llvm/DebugInfo/PDB/PDB.h"
Zachary Turner0e9e6632015-02-06 20:30:52 +000011#include "llvm/ADT/StringRef.h"
Zachary Turner52c9f882015-02-14 03:53:56 +000012#include "llvm/Config/config.h"
Zachary Turner2b370172016-05-06 20:59:35 +000013#include "llvm/DebugInfo/PDB/GenericError.h"
Michal Gorny89b6f162017-01-02 18:19:35 +000014#if LLVM_ENABLE_DIA_SDK
Zachary Turnercffff262015-02-10 21:17:52 +000015#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
16#endif
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000017#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
Eugene Zelenko4fcfc192017-06-30 23:06:03 +000018#include "llvm/Support/Error.h"
Zachary Turnerbd159d32017-11-17 01:00:35 +000019#include "llvm/Support/MemoryBuffer.h"
Zachary Turner0e9e6632015-02-06 20:30:52 +000020
21using namespace llvm;
Zachary Turnerec28fc32016-05-04 20:32:13 +000022using namespace llvm::pdb;
Zachary Turner0e9e6632015-02-06 20:30:52 +000023
Zachary Turner819e77d2016-05-06 20:51:57 +000024Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
25 std::unique_ptr<IPDBSession> &Session) {
Zachary Turner0e9e6632015-02-06 20:30:52 +000026 // Create the correct concrete instance type based on the value of Type.
Peter Collingbourne75257bc2017-10-20 19:48:26 +000027 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 Turner0a43efe2016-04-25 17:38:08 +000036
Michal Gorny89b6f162017-01-02 18:19:35 +000037#if LLVM_ENABLE_DIA_SDK
Zachary Turnerccf04152015-02-28 20:23:18 +000038 return DIASession::createFromPdb(Path, Session);
Zachary Turner0a43efe2016-04-25 17:38:08 +000039#else
Eugene Zelenko4fcfc192017-06-30 23:06:03 +000040 return make_error<GenericError>("DIA is not installed on the system");
Zachary Turner0a43efe2016-04-25 17:38:08 +000041#endif
Zachary Turner0e9e6632015-02-06 20:30:52 +000042}
Zachary Turner4b083542015-04-17 22:40:36 +000043
Zachary Turner819e77d2016-05-06 20:51:57 +000044Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
45 std::unique_ptr<IPDBSession> &Session) {
Dave Bartolomeoea039c12015-12-17 20:54:16 +000046 // Create the correct concrete instance type based on the value of Type.
Adrian McCarthy8f713192017-01-27 00:01:55 +000047 if (Type == PDB_ReaderType::Native)
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000048 return NativeSession::createFromExe(Path, Session);
Zachary Turner0a43efe2016-04-25 17:38:08 +000049
Michal Gorny89b6f162017-01-02 18:19:35 +000050#if LLVM_ENABLE_DIA_SDK
Zachary Turner4b083542015-04-17 22:40:36 +000051 return DIASession::createFromExe(Path, Session);
Zachary Turner0a43efe2016-04-25 17:38:08 +000052#else
Eugene Zelenko4fcfc192017-06-30 23:06:03 +000053 return make_error<GenericError>("DIA is not installed on the system");
Zachary Turner0a43efe2016-04-25 17:38:08 +000054#endif
Zachary Turner4b083542015-04-17 22:40:36 +000055}