TPCDynamicLibrarySearchGenerator.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===------------ TPCDynamicLibrarySearchGenerator.h ------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Support loading and searching of dynamic libraries in a target process via
  15. // the TargetProcessControl class.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_EXECUTIONENGINE_ORC_TPCDYNAMICLIBRARYSEARCHGENERATOR_H
  19. #define LLVM_EXECUTIONENGINE_ORC_TPCDYNAMICLIBRARYSEARCHGENERATOR_H
  20. #include "llvm/ADT/FunctionExtras.h"
  21. #include "llvm/ExecutionEngine/Orc/TargetProcessControl.h"
  22. namespace llvm {
  23. namespace orc {
  24. class TPCDynamicLibrarySearchGenerator : public DefinitionGenerator {
  25. public:
  26. using SymbolPredicate = unique_function<bool(const SymbolStringPtr &)>;
  27. /// Create a DynamicLibrarySearchGenerator that searches for symbols in the
  28. /// library with the given handle.
  29. ///
  30. /// If the Allow predicate is given then only symbols matching the predicate
  31. /// will be searched for. If the predicate is not given then all symbols will
  32. /// be searched for.
  33. TPCDynamicLibrarySearchGenerator(TargetProcessControl &TPC,
  34. tpctypes::DylibHandle H,
  35. SymbolPredicate Allow = SymbolPredicate())
  36. : TPC(TPC), H(H), Allow(std::move(Allow)) {}
  37. /// Permanently loads the library at the given path and, on success, returns
  38. /// a DynamicLibrarySearchGenerator that will search it for symbol definitions
  39. /// in the library. On failure returns the reason the library failed to load.
  40. static Expected<std::unique_ptr<TPCDynamicLibrarySearchGenerator>>
  41. Load(TargetProcessControl &TPC, const char *LibraryPath,
  42. SymbolPredicate Allow = SymbolPredicate());
  43. /// Creates a TPCDynamicLibrarySearchGenerator that searches for symbols in
  44. /// the target process.
  45. static Expected<std::unique_ptr<TPCDynamicLibrarySearchGenerator>>
  46. GetForTargetProcess(TargetProcessControl &TPC,
  47. SymbolPredicate Allow = SymbolPredicate()) {
  48. return Load(TPC, nullptr, std::move(Allow));
  49. }
  50. Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD,
  51. JITDylibLookupFlags JDLookupFlags,
  52. const SymbolLookupSet &Symbols) override;
  53. private:
  54. TargetProcessControl &TPC;
  55. tpctypes::DylibHandle H;
  56. SymbolPredicate Allow;
  57. };
  58. } // end namespace orc
  59. } // end namespace llvm
  60. #endif // LLVM_EXECUTIONENGINE_ORC_TPCDYNAMICLIBRARYSEARCHGENERATOR_H
  61. #ifdef __GNUC__
  62. #pragma GCC diagnostic pop
  63. #endif