xref: /llvm-project/llvm/lib/DebugInfo/PDB/PDB.cpp (revision 2f09b5091ce055dbc3a803ecb2576540d6abb503)
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 
24 PDB_ErrorCode llvm::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
25                                    std::unique_ptr<IPDBSession> &Session) {
26   // Create the correct concrete instance type based on the value of Type.
27   if (Type == PDB_ReaderType::Raw)
28     return pdb::RawSession::createFromPdb(Path, Session);
29 
30 #if HAVE_DIA_SDK
31   return DIASession::createFromPdb(Path, Session);
32 #else
33   return PDB_ErrorCode::NoDiaSupport;
34 #endif
35 }
36 
37 PDB_ErrorCode llvm::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
38                                    std::unique_ptr<IPDBSession> &Session) {
39   // Create the correct concrete instance type based on the value of Type.
40   if (Type == PDB_ReaderType::Raw)
41     return pdb::RawSession::createFromExe(Path, Session);
42 
43 #if HAVE_DIA_SDK
44   return DIASession::createFromExe(Path, Session);
45 #else
46   return PDB_ErrorCode::NoDiaSupport;
47 #endif
48 }
49