PDB.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "llvm/Support/MemoryBuffer.h"
  18. using namespace llvm;
  19. using namespace llvm::pdb;
  20. Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
  21. std::unique_ptr<IPDBSession> &Session) {
  22. // Create the correct concrete instance type based on the value of Type.
  23. if (Type == PDB_ReaderType::Native)
  24. return NativeSession::createFromPdbPath(Path, Session);
  25. #if LLVM_ENABLE_DIA_SDK
  26. return DIASession::createFromPdb(Path, Session);
  27. #else
  28. return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
  29. #endif
  30. }
  31. Error llvm::pdb::loadDataForEXE(PDB_ReaderType Type, StringRef Path,
  32. std::unique_ptr<IPDBSession> &Session) {
  33. // Create the correct concrete instance type based on the value of Type.
  34. if (Type == PDB_ReaderType::Native) {
  35. Expected<std::string> PdbPath = NativeSession::searchForPdb({Path});
  36. if (!PdbPath)
  37. return PdbPath.takeError();
  38. return NativeSession::createFromPdbPath(PdbPath.get(), Session);
  39. }
  40. #if LLVM_ENABLE_DIA_SDK
  41. return DIASession::createFromExe(Path, Session);
  42. #else
  43. return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
  44. #endif
  45. }