LLVM 22.0.0git
DebuggerSupport.cpp
Go to the documentation of this file.
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
13
14#define DEBUG_TYPE "orc"
15
16using namespace llvm;
17using namespace llvm::orc;
18
19namespace llvm::orc {
20
22 auto *ObjLinkingLayer = dyn_cast<ObjectLinkingLayer>(&J.getObjLinkingLayer());
23 if (!ObjLinkingLayer)
24 return make_error<StringError>("Cannot enable LLJIT debugger support: "
25 "Debugger support requires JITLink",
27 auto ProcessSymsJD = J.getProcessSymbolsJITDylib();
28 if (!ProcessSymsJD)
29 return make_error<StringError>("Cannot enable LLJIT debugger support: "
30 "Process symbols are not available",
32
33 auto &ES = J.getExecutionSession();
34 const auto &TT = J.getTargetTriple();
35
36 switch (TT.getObjectFormat()) {
37 case Triple::ELF: {
38 auto Registrar = createJITLoaderGDBRegistrar(ES);
39 if (!Registrar)
40 return Registrar.takeError();
41 ObjLinkingLayer->addPlugin(std::make_unique<DebugObjectManagerPlugin>(
42 ES, std::move(*Registrar), false, true));
43 return Error::success();
44 }
45 case Triple::MachO: {
46 auto DS = GDBJITDebugInfoRegistrationPlugin::Create(ES, *ProcessSymsJD, TT);
47 if (!DS)
48 return DS.takeError();
49 ObjLinkingLayer->addPlugin(std::move(*DS));
50 return Error::success();
51 }
52 default:
54 "Cannot enable LLJIT debugger support: " +
55 Triple::getObjectFormatTypeName(TT.getObjectFormat()) +
56 " is not supported",
58 }
59}
60
61} // namespace llvm::orc
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
static LLVM_ABI StringRef getObjectFormatTypeName(ObjectFormatType ObjectFormat)
Get the name for the Object format.
Definition Triple.cpp:412
static Expected< std::unique_ptr< GDBJITDebugInfoRegistrationPlugin > > Create(ExecutionSession &ES, JITDylib &ProcessJD, const Triple &TT)
A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
Definition LLJIT.h:42
ObjectLayer & getObjLinkingLayer()
Returns a reference to the ObjLinkingLayer.
Definition LLJIT.h:217
const Triple & getTargetTriple() const
Returns a reference to the triple for this instance.
Definition LLJIT.h:70
JITDylibSP getProcessSymbolsJITDylib()
Returns the ProcessSymbols JITDylib, which by default reflects non-JIT'd symbols in the host process.
Definition LLJIT.cpp:865
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
Definition LLJIT.h:67
LLVM_ABI Error enableDebuggerSupport(LLJIT &J)
LLVM_ABI Expected< std::unique_ptr< EPCDebugObjectRegistrar > > createJITLoaderGDBRegistrar(ExecutionSession &ES, std::optional< ExecutorAddr > RegistrationFunctionDylib=std::nullopt)
Create a ExecutorProcessControl-based DebugObjectRegistrar that emits debug objects to the GDB JIT in...
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:98
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340