PDB.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //===- PDB.cpp - base header file for creating a PDB reader ---------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/DebugInfo/PDB/PDB.h"
  9. #include "llvm/ADT/StringRef.h"
  10. #include "llvm/Config/config.h"
  11. #include "llvm/DebugInfo/PDB/GenericError.h"
  12. #if LLVM_ENABLE_DIA_SDK
  13. #error #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
  14. #endif
  15. #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
  16. #include "llvm/Support/Error.h"
  17. using namespace llvm;
  18. using namespace llvm::pdb;
  19. Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
  20. std::unique_ptr<IPDBSession> &Session) {
  21. // Create the correct concrete instance type based on the value of Type.
  22. if (Type == PDB_ReaderType::Native)
  23. return NativeSession::createFromPdbPath(Path, Session);
  24. #if LLVM_ENABLE_DIA_SDK
  25. return DIASession::createFromPdb(Path, Session);
  26. #else
  27. return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
  28. #endif
  29. }
  30. Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
  31. std::unique_ptr<IPDBSession> &Session) {
  32. // Create the correct concrete instance type based on the value of Type.
  33. if (Type == PDB_ReaderType::Native) {
  34. Expected<std::string> PdbPath = NativeSession::searchForPdb({Path});
  35. if (!PdbPath)
  36. return PdbPath.takeError();
  37. return NativeSession::createFromPdbPath(PdbPath.get(), Session);
  38. }
  39. #if LLVM_ENABLE_DIA_SDK
  40. return DIASession::createFromExe(Path, Session);
  41. #else
  42. return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
  43. #endif
  44. }