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