Skip to content

Commit e5f169f

Browse files
committed
Revert "[ORC][LLJIT] Move enable-debugger-support utility out of LLJITBuilder."
This reverts commit e1a5bb5 while I investigate the bot failure at https://lab.llvm.org/buildbot/#/builders/168/builds/15831
1 parent bcc5b48 commit e5f169f

File tree

10 files changed

+75
-118
lines changed

10 files changed

+75
-118
lines changed

clang/lib/Interpreter/IncrementalExecutor.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "clang/Interpreter/PartialTranslationUnit.h"
1818
#include "llvm/ExecutionEngine/ExecutionEngine.h"
1919
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
20-
#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
2120
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
2221
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
2322
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
@@ -47,13 +46,8 @@ IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
4746
JTMB.addFeatures(TI.getTargetOpts().Features);
4847
LLJITBuilder Builder;
4948
Builder.setJITTargetMachineBuilder(JTMB);
50-
Builder.setPrePlatformSetup(
51-
[](LLJIT &J) {
52-
// Try to enable debugging of JIT'd code (only works with JITLink for
53-
// ELF and MachO).
54-
consumeError(enableDebuggerSupport(J));
55-
return llvm::Error::success();
56-
});
49+
// Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
50+
Builder.setEnableDebuggerSupport(true);
5751

5852
if (auto JitOrErr = Builder.create())
5953
Jit = std::move(*JitOrErr);

clang/tools/clang-repl/ClangRepl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ int main(int argc, const char **argv) {
152152
llvm::InitializeAllAsmPrinters();
153153

154154
if (OptHostSupportsJit) {
155-
auto J = llvm::orc::LLJITBuilder().create();
155+
auto J = llvm::orc::LLJITBuilder()
156+
.setEnableDebuggerSupport(true)
157+
.create();
156158
if (J)
157159
llvm::outs() << "true\n";
158160
else {

clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ TEST(InterpreterTest, CatchException) {
5252
llvm::InitializeNativeTargetAsmPrinter();
5353

5454
{
55-
auto J = llvm::orc::LLJITBuilder().create();
55+
auto J = llvm::orc::LLJITBuilder()
56+
.setEnableDebuggerSupport(true)
57+
.create();
5658
if (!J) {
5759
// The platform does not support JITs.
5860
// Using llvm::consumeError will require typeinfo for ErrorInfoBase, we

clang/unittests/Interpreter/InterpreterTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ static std::string MangleName(NamedDecl *ND) {
191191
}
192192

193193
static bool HostSupportsJit() {
194-
auto J = llvm::orc::LLJITBuilder().create();
194+
auto J = llvm::orc::LLJITBuilder()
195+
.setEnableDebuggerSupport(true)
196+
.create();
195197
if (J)
196198
return true;
197199
LLVMConsumeError(llvm::wrap(J.takeError()));

llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ class LLJITBuilderState {
322322
unique_function<Error(LLJIT &)> PrePlatformSetup;
323323
PlatformSetupFunction SetUpPlatform;
324324
unsigned NumCompileThreads = 0;
325+
bool EnableDebuggerSupport = false;
325326

326327
/// Called prior to JIT class construcion to fix up defaults.
327328
Error prepareForConstruction();
@@ -454,6 +455,12 @@ class LLJITBuilderSetters {
454455
return impl();
455456
}
456457

458+
/// Enable / disable debugger support (off by default).
459+
SetterImpl &setEnableDebuggerSupport(bool EnableDebuggerSupport) {
460+
impl().EnableDebuggerSupport = EnableDebuggerSupport;
461+
return impl();
462+
}
463+
457464
/// Set an ExecutorProcessControl object.
458465
///
459466
/// If the platform uses ObjectLinkingLayer by default and no

llvm/lib/ExecutionEngine/Orc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ add_llvm_component_library(LLVMOrcJIT
1313
CompileUtils.cpp
1414
Core.cpp
1515
DebugObjectManagerPlugin.cpp
16-
DebuggerSupport.cpp
1716
DebuggerSupportPlugin.cpp
1817
DebugUtils.cpp
1918
EPCDynamicLibrarySearchGenerator.cpp

llvm/lib/ExecutionEngine/Orc/DebuggerSupport.cpp

Lines changed: 0 additions & 61 deletions
This file was deleted.

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"
1111
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
1212
#include "llvm/ExecutionEngine/Orc/COFFPlatform.h"
13+
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
14+
#include "llvm/ExecutionEngine/Orc/DebuggerSupportPlugin.h"
1315
#include "llvm/ExecutionEngine/Orc/ELFNixPlatform.h"
1416
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
1517
#include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
@@ -779,8 +781,18 @@ Error LLJITBuilderState::prepareForConstruction() {
779781

780782
// If we need a process JITDylib but no setup function has been given then
781783
// create a default one.
782-
if (!SetupProcessSymbolsJITDylib && LinkProcessSymbolsByDefault) {
783-
LLVM_DEBUG(dbgs() << "Creating default Process JD setup function\n");
784+
if (!SetupProcessSymbolsJITDylib &&
785+
(LinkProcessSymbolsByDefault || EnableDebuggerSupport)) {
786+
787+
LLVM_DEBUG({
788+
dbgs() << "Creating default Process JD setup function (neeeded for";
789+
if (LinkProcessSymbolsByDefault)
790+
dbgs() << " <link-process-syms-by-default>";
791+
if (EnableDebuggerSupport)
792+
dbgs() << " <debugger-support>";
793+
dbgs() << ")\n";
794+
});
795+
784796
SetupProcessSymbolsJITDylib = [this](LLJIT &J) -> Expected<JITDylibSP> {
785797
auto &JD =
786798
J.getExecutionSession().createBareJITDylib("<Process Symbols>");
@@ -1002,6 +1014,46 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
10021014
}
10031015
}
10041016

1017+
if (S.EnableDebuggerSupport) {
1018+
if (auto *OLL = dyn_cast<ObjectLinkingLayer>(ObjLinkingLayer.get())) {
1019+
switch (TT.getObjectFormat()) {
1020+
case Triple::ELF: {
1021+
auto Registrar = createJITLoaderGDBRegistrar(*ES);
1022+
if (!Registrar) {
1023+
Err = Registrar.takeError();
1024+
return;
1025+
}
1026+
OLL->addPlugin(std::make_unique<DebugObjectManagerPlugin>(
1027+
*ES, std::move(*Registrar), true, true));
1028+
break;
1029+
}
1030+
case Triple::MachO: {
1031+
assert(ProcessSymbols && "ProcessSymbols JD should be available when "
1032+
"EnableDebuggerSupport is set");
1033+
auto DS =
1034+
GDBJITDebugInfoRegistrationPlugin::Create(*ES, *ProcessSymbols, TT);
1035+
if (!DS) {
1036+
Err = DS.takeError();
1037+
return;
1038+
}
1039+
OLL->addPlugin(std::move(*DS));
1040+
break;
1041+
}
1042+
default:
1043+
LLVM_DEBUG({
1044+
dbgs() << "Cannot enable LLJIT debugger support: "
1045+
<< Triple::getObjectFormatTypeName(TT.getObjectFormat())
1046+
<< " not supported.\n";
1047+
});
1048+
}
1049+
} else {
1050+
LLVM_DEBUG({
1051+
dbgs() << "Cannot enable LLJIT debugger support: "
1052+
" debugger support is only available when using JITLink.\n";
1053+
});
1054+
}
1055+
}
1056+
10051057
if (S.PrePlatformSetup) {
10061058
if (auto Err2 = S.PrePlatformSetup(*this)) {
10071059
Err = std::move(Err2);

llvm/tools/lli/lli.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "llvm/ExecutionEngine/MCJIT.h"
2727
#include "llvm/ExecutionEngine/ObjectCache.h"
2828
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
29-
#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
3029
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
3130
#include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
3231
#include "llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h"
@@ -845,17 +844,6 @@ int mingw_noop_main(void) {
845844
return 0;
846845
}
847846

848-
// Try to enable debugger support for the given instance.
849-
// This alway returns success, but prints a warning if it's not able to enable
850-
// debugger support.
851-
Error tryEnableDebugSupport(orc::LLJIT &J) {
852-
if (auto Err = enableDebuggerSupport(J)) {
853-
[[maybe_unused]] std::string ErrMsg = toString(std::move(Err));
854-
LLVM_DEBUG(dbgs() << "lli: " << ErrMsg << "\n");
855-
}
856-
return Error::success();
857-
}
858-
859847
int runOrcJIT(const char *ProgName) {
860848
// Start setting up the JIT environment.
861849

@@ -936,9 +924,6 @@ int runOrcJIT(const char *ProgName) {
936924
});
937925
}
938926

939-
// Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
940-
Builder.setPrePlatformSetup(tryEnableDebugSupport);
941-
942927
// Set up LLJIT platform.
943928
LLJITPlatform P = Platform;
944929
if (P == LLJITPlatform::Auto)
@@ -975,6 +960,9 @@ int runOrcJIT(const char *ProgName) {
975960
});
976961
}
977962

963+
// Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
964+
Builder.setEnableDebuggerSupport(true);
965+
978966
auto J = ExitOnErr(Builder.create());
979967

980968
auto *ObjLayer = &J->getObjLinkingLayer();

0 commit comments

Comments
 (0)