xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/PDB/PDB.cpp (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric //===- PDB.cpp - base header file for creating a PDB reader ---------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/PDB.h"
100b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
110b57cec5SDimitry Andric #include "llvm/Config/config.h"
120b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/GenericError.h"
130b57cec5SDimitry Andric #if LLVM_ENABLE_DIA_SDK
140b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
150b57cec5SDimitry Andric #endif
160b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
170b57cec5SDimitry Andric #include "llvm/Support/Error.h"
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric using namespace llvm;
200b57cec5SDimitry Andric using namespace llvm::pdb;
210b57cec5SDimitry Andric 
loadDataForPDB(PDB_ReaderType Type,StringRef Path,std::unique_ptr<IPDBSession> & Session)220b57cec5SDimitry Andric Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
230b57cec5SDimitry Andric                                 std::unique_ptr<IPDBSession> &Session) {
240b57cec5SDimitry Andric   // Create the correct concrete instance type based on the value of Type.
25*5ffd83dbSDimitry Andric   if (Type == PDB_ReaderType::Native)
26*5ffd83dbSDimitry Andric     return NativeSession::createFromPdbPath(Path, Session);
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric #if LLVM_ENABLE_DIA_SDK
290b57cec5SDimitry Andric   return DIASession::createFromPdb(Path, Session);
300b57cec5SDimitry Andric #else
310b57cec5SDimitry Andric   return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
320b57cec5SDimitry Andric #endif
330b57cec5SDimitry Andric }
340b57cec5SDimitry Andric 
loadDataForEXE(PDB_ReaderType Type,StringRef Path,std::unique_ptr<IPDBSession> & Session)350b57cec5SDimitry Andric Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
360b57cec5SDimitry Andric                                 std::unique_ptr<IPDBSession> &Session) {
370b57cec5SDimitry Andric   // Create the correct concrete instance type based on the value of Type.
38*5ffd83dbSDimitry Andric   if (Type == PDB_ReaderType::Native) {
39*5ffd83dbSDimitry Andric     Expected<std::string> PdbPath = NativeSession::searchForPdb({Path});
40*5ffd83dbSDimitry Andric     if (!PdbPath)
41*5ffd83dbSDimitry Andric       return PdbPath.takeError();
42*5ffd83dbSDimitry Andric     return NativeSession::createFromPdbPath(PdbPath.get(), Session);
43*5ffd83dbSDimitry Andric   }
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric #if LLVM_ENABLE_DIA_SDK
460b57cec5SDimitry Andric   return DIASession::createFromExe(Path, Session);
470b57cec5SDimitry Andric #else
480b57cec5SDimitry Andric   return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
490b57cec5SDimitry Andric #endif
500b57cec5SDimitry Andric }
51