DebugObjectManagerPlugin.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===---- DebugObjectManagerPlugin.h - JITLink debug objects ---*- 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. // ObjectLinkingLayer plugin for emitting debug objects.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H
  18. #define LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H
  19. #include "llvm/ADT/Triple.h"
  20. #include "llvm/ExecutionEngine/JITLink/JITLink.h"
  21. #include "llvm/ExecutionEngine/Orc/Core.h"
  22. #include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
  23. #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
  24. #include "llvm/Support/Error.h"
  25. #include "llvm/Support/Memory.h"
  26. #include "llvm/Support/MemoryBufferRef.h"
  27. #include <functional>
  28. #include <map>
  29. #include <memory>
  30. #include <mutex>
  31. namespace llvm {
  32. namespace orc {
  33. class DebugObject;
  34. /// Creates and manages DebugObjects for JITLink artifacts.
  35. ///
  36. /// DebugObjects are created when linking for a MaterializationResponsibility
  37. /// starts. They are pending as long as materialization is in progress.
  38. ///
  39. /// There can only be one pending DebugObject per MaterializationResponsibility.
  40. /// If materialization fails, pending DebugObjects are discarded.
  41. ///
  42. /// Once executable code for the MaterializationResponsibility is emitted, the
  43. /// corresponding DebugObject is finalized to target memory and the provided
  44. /// DebugObjectRegistrar is notified. Ownership of DebugObjects remains with the
  45. /// plugin.
  46. ///
  47. class DebugObjectManagerPlugin : public ObjectLinkingLayer::Plugin {
  48. public:
  49. DebugObjectManagerPlugin(ExecutionSession &ES,
  50. std::unique_ptr<DebugObjectRegistrar> Target);
  51. ~DebugObjectManagerPlugin();
  52. void notifyMaterializing(MaterializationResponsibility &MR,
  53. jitlink::LinkGraph &G, jitlink::JITLinkContext &Ctx,
  54. MemoryBufferRef InputObject) override;
  55. Error notifyEmitted(MaterializationResponsibility &MR) override;
  56. Error notifyFailed(MaterializationResponsibility &MR) override;
  57. Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override;
  58. void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
  59. ResourceKey SrcKey) override;
  60. void modifyPassConfig(MaterializationResponsibility &MR,
  61. jitlink::LinkGraph &LG,
  62. jitlink::PassConfiguration &PassConfig) override;
  63. private:
  64. ExecutionSession &ES;
  65. using OwnedDebugObject = std::unique_ptr<DebugObject>;
  66. std::map<MaterializationResponsibility *, OwnedDebugObject> PendingObjs;
  67. std::map<ResourceKey, std::vector<OwnedDebugObject>> RegisteredObjs;
  68. std::mutex PendingObjsLock;
  69. std::mutex RegisteredObjsLock;
  70. std::unique_ptr<DebugObjectRegistrar> Target;
  71. };
  72. } // namespace orc
  73. } // namespace llvm
  74. #endif // LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H
  75. #ifdef __GNUC__
  76. #pragma GCC diagnostic pop
  77. #endif