xref: /llvm-project/llvm/lib/DebugInfo/PDB/PDB.cpp (revision ec28fc349987fa9cd9a05680ea5e81d9a9b35ce3)
1 //===- 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 
10 #include "llvm/DebugInfo/PDB/PDB.h"
11 
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Config/config.h"
14 #include "llvm/DebugInfo/PDB/IPDBSession.h"
15 #include "llvm/DebugInfo/PDB/PDB.h"
16 
17 #if HAVE_DIA_SDK
18 #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
19 #endif
20 #include "llvm/DebugInfo/PDB/Raw/RawSession.h"
21 
22 using namespace llvm;
23 using namespace llvm::pdb;
24 
25 PDB_ErrorCode llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
26                                         std::unique_ptr<IPDBSession> &Session) {
27   // Create the correct concrete instance type based on the value of Type.
28   if (Type == PDB_ReaderType::Raw)
29     return RawSession::createFromPdb(Path, Session);
30 
31 #if HAVE_DIA_SDK
32   return DIASession::createFromPdb(Path, Session);
33 #else
34   return PDB_ErrorCode::NoDiaSupport;
35 #endif
36 }
37 
38 PDB_ErrorCode llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
39                                         std::unique_ptr<IPDBSession> &Session) {
40   // Create the correct concrete instance type based on the value of Type.
41   if (Type == PDB_ReaderType::Raw)
42     return RawSession::createFromExe(Path, Session);
43 
44 #if HAVE_DIA_SDK
45   return DIASession::createFromExe(Path, Session);
46 #else
47   return PDB_ErrorCode::NoDiaSupport;
48 #endif
49 }
50