1//===------ DebuggerSupport.cpp - Utils for enabling debugger support -----===//
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#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
10#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.h"
11#include "llvm/ExecutionEngine/Orc/Debugging/ELFDebugObjectPlugin.h"
12#include "llvm/ExecutionEngine/Orc/LLJIT.h"
13
14#define DEBUG_TYPE "orc"
15
16using namespace llvm;
17using namespace llvm::orc;
18
19namespace llvm::orc {
20
21Error enableDebuggerSupport(LLJIT &J) {
22 auto *ObjLinkingLayer = dyn_cast<ObjectLinkingLayer>(Val: &J.getObjLinkingLayer());
23 if (!ObjLinkingLayer)
24 return make_error<StringError>(Args: "Cannot enable LLJIT debugger support: "
25 "Debugger support requires JITLink",
26 Args: inconvertibleErrorCode());
27 auto &ES = J.getExecutionSession();
28 const auto &TT = J.getTargetTriple();
29
30 switch (TT.getObjectFormat()) {
31 case Triple::ELF: {
32 Error TargetSymErr = Error::success();
33 ObjLinkingLayer->addPlugin(
34 P: std::make_unique<ELFDebugObjectPlugin>(args&: ES, args: false, args&: TargetSymErr));
35 return TargetSymErr;
36 }
37 case Triple::MachO: {
38 auto DS = GDBJITDebugInfoRegistrationPlugin::Create(
39 ES, BootstrapJD&: ES.getBootstrapJITDylib());
40 if (!DS)
41 return DS.takeError();
42 ObjLinkingLayer->addPlugin(P: std::move(*DS));
43 return Error::success();
44 }
45 default:
46 return make_error<StringError>(
47 Args: "Cannot enable LLJIT debugger support: " +
48 Triple::getObjectFormatTypeName(ObjectFormat: TT.getObjectFormat()) +
49 " is not supported",
50 Args: inconvertibleErrorCode());
51 }
52}
53
54} // namespace llvm::orc
55