14fcfc199SEugene Zelenko //===- PDB.cpp - base header file for creating a PDB reader ---------------===//
20e9e6633SZachary Turner //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60e9e6633SZachary Turner //
70e9e6633SZachary Turner //===----------------------------------------------------------------------===//
80e9e6633SZachary Turner
952c9f881SZachary Turner #include "llvm/DebugInfo/PDB/PDB.h"
100e9e6633SZachary Turner #include "llvm/ADT/StringRef.h"
1152c9f881SZachary Turner #include "llvm/Config/config.h"
122b37017cSZachary Turner #include "llvm/DebugInfo/PDB/GenericError.h"
1389b6f16bSMichal Gorny #if LLVM_ENABLE_DIA_SDK
14cffff26bSZachary Turner #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
15cffff26bSZachary Turner #endif
166b6b8c4fSAdrian McCarthy #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
174fcfc199SEugene Zelenko #include "llvm/Support/Error.h"
180e9e6633SZachary Turner
190e9e6633SZachary Turner using namespace llvm;
20ec28fc34SZachary Turner using namespace llvm::pdb;
210e9e6633SZachary Turner
loadDataForPDB(PDB_ReaderType Type,StringRef Path,std::unique_ptr<IPDBSession> & Session)22819e77d1SZachary Turner Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
23ccf04159SZachary Turner std::unique_ptr<IPDBSession> &Session) {
240e9e6633SZachary Turner // Create the correct concrete instance type based on the value of Type.
25*23609331SAmy Huang if (Type == PDB_ReaderType::Native)
26*23609331SAmy Huang return NativeSession::createFromPdbPath(Path, Session);
270a43efeaSZachary Turner
2889b6f16bSMichal Gorny #if LLVM_ENABLE_DIA_SDK
29ccf04159SZachary Turner return DIASession::createFromPdb(Path, Session);
300a43efeaSZachary Turner #else
316a7efef4SAlexandre Ganea return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
320a43efeaSZachary Turner #endif
330e9e6633SZachary Turner }
344b08354bSZachary Turner
loadDataForEXE(PDB_ReaderType Type,StringRef Path,std::unique_ptr<IPDBSession> & Session)35819e77d1SZachary Turner Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
364b08354bSZachary Turner std::unique_ptr<IPDBSession> &Session) {
374b08354bSZachary Turner // Create the correct concrete instance type based on the value of Type.
38*23609331SAmy Huang if (Type == PDB_ReaderType::Native) {
39*23609331SAmy Huang Expected<std::string> PdbPath = NativeSession::searchForPdb({Path});
40*23609331SAmy Huang if (!PdbPath)
41*23609331SAmy Huang return PdbPath.takeError();
42*23609331SAmy Huang return NativeSession::createFromPdbPath(PdbPath.get(), Session);
43*23609331SAmy Huang }
440a43efeaSZachary Turner
4589b6f16bSMichal Gorny #if LLVM_ENABLE_DIA_SDK
464b08354bSZachary Turner return DIASession::createFromExe(Path, Session);
470a43efeaSZachary Turner #else
486a7efef4SAlexandre Ganea return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
490a43efeaSZachary Turner #endif
504b08354bSZachary Turner }
51