Skip to content

Commit 1e4891e

Browse files
committed
[clang-repl] Enable debugging of JIT-ed code.
This change follows 21b5ebd and makes use of the jitlink infrastructure. In order to use this feature inside lldb one needs to run the lldb command: settings set plugin.jit-loader.gdb.enable on This works currently only on Darwin since jitlink is not a default ELF/x86-64 backend yet. Differential revision: https://reviews.llvm.org/D148481
1 parent 3e50896 commit 1e4891e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

clang/lib/Interpreter/IncrementalExecutor.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,18 @@
2121
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
2222
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
2323
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
24+
#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
2425
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
2526
#include "llvm/IR/Module.h"
2627
#include "llvm/Support/ManagedStatic.h"
2728
#include "llvm/Support/TargetSelect.h"
2829

30+
// Force linking some of the runtimes that helps attaching to a debugger.
31+
LLVM_ATTRIBUTE_USED void linkComponents() {
32+
llvm::errs() << (void *)&llvm_orc_registerJITLoaderGDBWrapper
33+
<< (void *)&llvm_orc_registerJITLoaderGDBAllocAction;
34+
}
35+
2936
namespace clang {
3037

3138
IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
@@ -37,7 +44,12 @@ IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
3744

3845
auto JTMB = JITTargetMachineBuilder(TI.getTriple());
3946
JTMB.addFeatures(TI.getTargetOpts().Features);
40-
if (auto JitOrErr = LLJITBuilder().setJITTargetMachineBuilder(JTMB).create())
47+
LLJITBuilder Builder;
48+
Builder.setJITTargetMachineBuilder(JTMB);
49+
// Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
50+
Builder.setEnableDebuggerSupport(true);
51+
52+
if (auto JitOrErr = Builder.create())
4153
Jit = std::move(*JitOrErr);
4254
else {
4355
Err = JitOrErr.takeError();

0 commit comments

Comments
 (0)