xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===---- DebugObjectManagerPlugin.h - JITLink debug objects ---*- C++ -*-===//
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 //
9 // ObjectLinkingLayer plugin for emitting debug objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H
14 #define LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H
15 
16 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
17 #include "llvm/ExecutionEngine/Orc/Core.h"
18 #include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
19 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/Error.h"
22 #include "llvm/Support/Memory.h"
23 #include "llvm/Support/MemoryBufferRef.h"
24 #include "llvm/TargetParser/Triple.h"
25 
26 #include <functional>
27 #include <map>
28 #include <memory>
29 #include <mutex>
30 
31 namespace llvm {
32 namespace orc {
33 
34 class DebugObject;
35 
36 /// Creates and manages DebugObjects for JITLink artifacts.
37 ///
38 /// DebugObjects are created when linking for a MaterializationResponsibility
39 /// starts. They are pending as long as materialization is in progress.
40 ///
41 /// There can only be one pending DebugObject per MaterializationResponsibility.
42 /// If materialization fails, pending DebugObjects are discarded.
43 ///
44 /// Once executable code for the MaterializationResponsibility is emitted, the
45 /// corresponding DebugObject is finalized to target memory and the provided
46 /// DebugObjectRegistrar is notified. Ownership of DebugObjects remains with the
47 /// plugin.
48 ///
49 class LLVM_ABI DebugObjectManagerPlugin : public ObjectLinkingLayer::Plugin {
50 public:
51   // DEPRECATED - Please specify options explicitly
52   DebugObjectManagerPlugin(ExecutionSession &ES,
53                            std::unique_ptr<DebugObjectRegistrar> Target);
54 
55   /// Create the plugin to submit DebugObjects for JITLink artifacts. For all
56   /// options the recommended setting is true.
57   ///
58   /// RequireDebugSections:
59   ///   Submit debug objects to the executor only if they contain actual debug
60   ///   info. Turning this off may allow minimal debugging based on raw symbol
61   ///   names. Note that this may cause significant memory and transport
62   ///   overhead for objects built with a release configuration.
63   ///
64   /// AutoRegisterCode:
65   ///   Notify the debugger for each new debug object. This is a good default
66   ///   mode, but it may cause significant overhead when adding many modules in
67   ///   sequence. When turning this off, the user has to issue the call to
68   ///   __jit_debug_register_code() on the executor side manually.
69   ///
70   DebugObjectManagerPlugin(ExecutionSession &ES,
71                            std::unique_ptr<DebugObjectRegistrar> Target,
72                            bool RequireDebugSections, bool AutoRegisterCode);
73   ~DebugObjectManagerPlugin();
74 
75   void notifyMaterializing(MaterializationResponsibility &MR,
76                            jitlink::LinkGraph &G, jitlink::JITLinkContext &Ctx,
77                            MemoryBufferRef InputObject) override;
78 
79   Error notifyEmitted(MaterializationResponsibility &MR) override;
80   Error notifyFailed(MaterializationResponsibility &MR) override;
81   Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override;
82 
83   void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
84                                    ResourceKey SrcKey) override;
85 
86   void modifyPassConfig(MaterializationResponsibility &MR,
87                         jitlink::LinkGraph &LG,
88                         jitlink::PassConfiguration &PassConfig) override;
89 
90 private:
91   ExecutionSession &ES;
92 
93   using OwnedDebugObject = std::unique_ptr<DebugObject>;
94   std::map<MaterializationResponsibility *, OwnedDebugObject> PendingObjs;
95   std::map<ResourceKey, std::vector<OwnedDebugObject>> RegisteredObjs;
96 
97   std::mutex PendingObjsLock;
98   std::mutex RegisteredObjsLock;
99 
100   std::unique_ptr<DebugObjectRegistrar> Target;
101   bool RequireDebugSections;
102   bool AutoRegisterCode;
103 };
104 
105 } // namespace orc
106 } // namespace llvm
107 
108 #endif // LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H
109