blob: 2b384aaba18b14a70777675add210adbf6e408cc [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 Turner0e9e6632015-02-06 20:30:52 +000014#include "llvm/DebugInfo/PDB/IPDBSession.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000015#include "llvm/DebugInfo/PDB/PDB.h"
Zachary Turnercffff262015-02-10 21:17:52 +000016#if HAVE_DIA_SDK
17#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
18#endif
Zachary Turner0a43efe2016-04-25 17:38:08 +000019#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
Zachary Turner819e77d2016-05-06 20:51:57 +000020#include "llvm/Support/ErrorHandling.h"
21#include "llvm/Support/ManagedStatic.h"
Zachary Turner0e9e6632015-02-06 20:30:52 +000022
23using namespace llvm;
Zachary Turnerec28fc32016-05-04 20:32:13 +000024using namespace llvm::pdb;
Zachary Turner0e9e6632015-02-06 20:30:52 +000025
Zachary Turner819e77d2016-05-06 20:51:57 +000026Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
27 std::unique_ptr<IPDBSession> &Session) {
Zachary Turner0e9e6632015-02-06 20:30:52 +000028 // Create the correct concrete instance type based on the value of Type.
Zachary Turner0a43efe2016-04-25 17:38:08 +000029 if (Type == PDB_ReaderType::Raw)
Zachary Turnerec28fc32016-05-04 20:32:13 +000030 return RawSession::createFromPdb(Path, Session);
Zachary Turner0a43efe2016-04-25 17:38:08 +000031
Zachary Turnercffff262015-02-10 21:17:52 +000032#if HAVE_DIA_SDK
Zachary Turnerccf04152015-02-28 20:23:18 +000033 return DIASession::createFromPdb(Path, Session);
Zachary Turner0a43efe2016-04-25 17:38:08 +000034#else
Zachary Turner819e77d2016-05-06 20:51:57 +000035 return llvm::make_error<GenericError>("DIA is not installed on the system");
Zachary Turner0a43efe2016-04-25 17:38:08 +000036#endif
Zachary Turner0e9e6632015-02-06 20:30:52 +000037}
Zachary Turner4b083542015-04-17 22:40:36 +000038
Zachary Turner819e77d2016-05-06 20:51:57 +000039Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
40 std::unique_ptr<IPDBSession> &Session) {
Dave Bartolomeoea039c12015-12-17 20:54:16 +000041 // Create the correct concrete instance type based on the value of Type.
Zachary Turner0a43efe2016-04-25 17:38:08 +000042 if (Type == PDB_ReaderType::Raw)
Zachary Turnerec28fc32016-05-04 20:32:13 +000043 return RawSession::createFromExe(Path, Session);
Zachary Turner0a43efe2016-04-25 17:38:08 +000044
Zachary Turner4b083542015-04-17 22:40:36 +000045#if HAVE_DIA_SDK
46 return DIASession::createFromExe(Path, Session);
Zachary Turner0a43efe2016-04-25 17:38:08 +000047#else
Zachary Turner819e77d2016-05-06 20:51:57 +000048 return llvm::make_error<GenericError>("DIA is not installed on the system");
Zachary Turner0a43efe2016-04-25 17:38:08 +000049#endif
Zachary Turner4b083542015-04-17 22:40:36 +000050}