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 
19 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
20 
21 namespace llvm {
22 
23 namespace orc {
24 
25 Error preserveDebugSections(jitlink::LinkGraph &G);
26 // The backing stringmap is also returned, for memory liftime management.
27 Expected<std::pair<std::unique_ptr<DWARFContext>,
28                    StringMap<std::unique_ptr<MemoryBuffer>>>>
29 createDWARFContext(jitlink::LinkGraph &G);
30 
31 // Thin wrapper around preserveDebugSections to be used as a standalone plugin.
32 class DebugInfoPreservationPlugin : public ObjectLinkingLayer::Plugin {
33 public:
34   void modifyPassConfig(MaterializationResponsibility &MR,
35                         jitlink::LinkGraph &LG,
36                         jitlink::PassConfiguration &PassConfig) override {
37     PassConfig.PrePrunePasses.push_back(preserveDebugSections);
38   }
39 
40   Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override {
41     // Do nothing.
42     return Error::success();
43   }
44   Error notifyFailed(MaterializationResponsibility &MR) override {
45     // Do nothing.
46     return Error::success();
47   }
48   void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
49                                    ResourceKey SrcKey) override {
50     // Do nothing.
51   }
52 
53   static Expected<std::unique_ptr<DebugInfoPreservationPlugin>> Create() {
54     return std::make_unique<DebugInfoPreservationPlugin>();
55   }
56 };
57 
58 } // namespace orc
59 
60 } // namespace llvm
61 
62 #endif