xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Debugging/DebugInfoSupport.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===--- DebugInfoSupport.h ---- Utils for debug info support ---*- 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 // Utilities to preserve and parse debug info from LinkGraphs.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGINFOSUPPORT_H
14 #define LLVM_EXECUTIONENGINE_ORC_DEBUGINFOSUPPORT_H
15 
16 #include "llvm/ExecutionEngine/Orc/Core.h"
17 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
18 #include "llvm/Support/Compiler.h"
19 
20 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
21 
22 namespace llvm {
23 
24 namespace orc {
25 
26 LLVM_ABI Error preserveDebugSections(jitlink::LinkGraph &G);
27 // The backing stringmap is also returned, for memory liftime management.
28 LLVM_ABI Expected<std::pair<std::unique_ptr<DWARFContext>,
29                             StringMap<std::unique_ptr<MemoryBuffer>>>>
30 createDWARFContext(jitlink::LinkGraph &G);
31 
32 // Thin wrapper around preserveDebugSections to be used as a standalone plugin.
33 class DebugInfoPreservationPlugin : public ObjectLinkingLayer::Plugin {
34 public:
modifyPassConfig(MaterializationResponsibility & MR,jitlink::LinkGraph & LG,jitlink::PassConfiguration & PassConfig)35   void modifyPassConfig(MaterializationResponsibility &MR,
36                         jitlink::LinkGraph &LG,
37                         jitlink::PassConfiguration &PassConfig) override {
38     PassConfig.PrePrunePasses.push_back(preserveDebugSections);
39   }
40 
notifyRemovingResources(JITDylib & JD,ResourceKey K)41   Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override {
42     // Do nothing.
43     return Error::success();
44   }
notifyFailed(MaterializationResponsibility & MR)45   Error notifyFailed(MaterializationResponsibility &MR) override {
46     // Do nothing.
47     return Error::success();
48   }
notifyTransferringResources(JITDylib & JD,ResourceKey DstKey,ResourceKey SrcKey)49   void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
50                                    ResourceKey SrcKey) override {
51     // Do nothing.
52   }
53 
Create()54   static Expected<std::unique_ptr<DebugInfoPreservationPlugin>> Create() {
55     return std::make_unique<DebugInfoPreservationPlugin>();
56   }
57 };
58 
59 } // namespace orc
60 
61 } // namespace llvm
62 
63 #endif
64