Skip to content

Commit

Permalink
Revert "[ORC][LLJIT] Move enable-debugger-support utility out of LLJI…
Browse files Browse the repository at this point in the history
…TBuilder."

This reverts commit e1a5bb5 while I
investigate the bot failure at
https://lab.llvm.org/buildbot/#/builders/168/builds/15831
  • Loading branch information
lhames committed Sep 23, 2023
1 parent bcc5b48 commit e5f169f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 118 deletions.
10 changes: 2 additions & 8 deletions clang/lib/Interpreter/IncrementalExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "clang/Interpreter/PartialTranslationUnit.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
Expand Down Expand Up @@ -47,13 +46,8 @@ IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
JTMB.addFeatures(TI.getTargetOpts().Features);
LLJITBuilder Builder;
Builder.setJITTargetMachineBuilder(JTMB);
Builder.setPrePlatformSetup(
[](LLJIT &J) {
// Try to enable debugging of JIT'd code (only works with JITLink for
// ELF and MachO).
consumeError(enableDebuggerSupport(J));
return llvm::Error::success();
});
// Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
Builder.setEnableDebuggerSupport(true);

if (auto JitOrErr = Builder.create())
Jit = std::move(*JitOrErr);
Expand Down
4 changes: 3 additions & 1 deletion clang/tools/clang-repl/ClangRepl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ int main(int argc, const char **argv) {
llvm::InitializeAllAsmPrinters();

if (OptHostSupportsJit) {
auto J = llvm::orc::LLJITBuilder().create();
auto J = llvm::orc::LLJITBuilder()
.setEnableDebuggerSupport(true)
.create();
if (J)
llvm::outs() << "true\n";
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ TEST(InterpreterTest, CatchException) {
llvm::InitializeNativeTargetAsmPrinter();

{
auto J = llvm::orc::LLJITBuilder().create();
auto J = llvm::orc::LLJITBuilder()
.setEnableDebuggerSupport(true)
.create();
if (!J) {
// The platform does not support JITs.
// Using llvm::consumeError will require typeinfo for ErrorInfoBase, we
Expand Down
4 changes: 3 additions & 1 deletion clang/unittests/Interpreter/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ static std::string MangleName(NamedDecl *ND) {
}

static bool HostSupportsJit() {
auto J = llvm::orc::LLJITBuilder().create();
auto J = llvm::orc::LLJITBuilder()
.setEnableDebuggerSupport(true)
.create();
if (J)
return true;
LLVMConsumeError(llvm::wrap(J.takeError()));
Expand Down
28 changes: 0 additions & 28 deletions llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h

This file was deleted.

7 changes: 7 additions & 0 deletions llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class LLJITBuilderState {
unique_function<Error(LLJIT &)> PrePlatformSetup;
PlatformSetupFunction SetUpPlatform;
unsigned NumCompileThreads = 0;
bool EnableDebuggerSupport = false;

/// Called prior to JIT class construcion to fix up defaults.
Error prepareForConstruction();
Expand Down Expand Up @@ -454,6 +455,12 @@ class LLJITBuilderSetters {
return impl();
}

/// Enable / disable debugger support (off by default).
SetterImpl &setEnableDebuggerSupport(bool EnableDebuggerSupport) {
impl().EnableDebuggerSupport = EnableDebuggerSupport;
return impl();
}

/// Set an ExecutorProcessControl object.
///
/// If the platform uses ObjectLinkingLayer by default and no
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ add_llvm_component_library(LLVMOrcJIT
CompileUtils.cpp
Core.cpp
DebugObjectManagerPlugin.cpp
DebuggerSupport.cpp
DebuggerSupportPlugin.cpp
DebugUtils.cpp
EPCDynamicLibrarySearchGenerator.cpp
Expand Down
61 changes: 0 additions & 61 deletions llvm/lib/ExecutionEngine/Orc/DebuggerSupport.cpp

This file was deleted.

56 changes: 54 additions & 2 deletions llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h"
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/COFFPlatform.h"
#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
#include "llvm/ExecutionEngine/Orc/DebuggerSupportPlugin.h"
#include "llvm/ExecutionEngine/Orc/ELFNixPlatform.h"
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
#include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
Expand Down Expand Up @@ -779,8 +781,18 @@ Error LLJITBuilderState::prepareForConstruction() {

// If we need a process JITDylib but no setup function has been given then
// create a default one.
if (!SetupProcessSymbolsJITDylib && LinkProcessSymbolsByDefault) {
LLVM_DEBUG(dbgs() << "Creating default Process JD setup function\n");
if (!SetupProcessSymbolsJITDylib &&
(LinkProcessSymbolsByDefault || EnableDebuggerSupport)) {

LLVM_DEBUG({
dbgs() << "Creating default Process JD setup function (neeeded for";
if (LinkProcessSymbolsByDefault)
dbgs() << " <link-process-syms-by-default>";
if (EnableDebuggerSupport)
dbgs() << " <debugger-support>";
dbgs() << ")\n";
});

SetupProcessSymbolsJITDylib = [this](LLJIT &J) -> Expected<JITDylibSP> {
auto &JD =
J.getExecutionSession().createBareJITDylib("<Process Symbols>");
Expand Down Expand Up @@ -1002,6 +1014,46 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
}
}

if (S.EnableDebuggerSupport) {
if (auto *OLL = dyn_cast<ObjectLinkingLayer>(ObjLinkingLayer.get())) {
switch (TT.getObjectFormat()) {
case Triple::ELF: {
auto Registrar = createJITLoaderGDBRegistrar(*ES);
if (!Registrar) {
Err = Registrar.takeError();
return;
}
OLL->addPlugin(std::make_unique<DebugObjectManagerPlugin>(
*ES, std::move(*Registrar), true, true));
break;
}
case Triple::MachO: {
assert(ProcessSymbols && "ProcessSymbols JD should be available when "
"EnableDebuggerSupport is set");
auto DS =
GDBJITDebugInfoRegistrationPlugin::Create(*ES, *ProcessSymbols, TT);
if (!DS) {
Err = DS.takeError();
return;
}
OLL->addPlugin(std::move(*DS));
break;
}
default:
LLVM_DEBUG({
dbgs() << "Cannot enable LLJIT debugger support: "
<< Triple::getObjectFormatTypeName(TT.getObjectFormat())
<< " not supported.\n";
});
}
} else {
LLVM_DEBUG({
dbgs() << "Cannot enable LLJIT debugger support: "
" debugger support is only available when using JITLink.\n";
});
}
}

if (S.PrePlatformSetup) {
if (auto Err2 = S.PrePlatformSetup(*this)) {
Err = std::move(Err2);
Expand Down
18 changes: 3 additions & 15 deletions llvm/tools/lli/lli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
#include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
#include "llvm/ExecutionEngine/Orc/EPCGenericRTDyldMemoryManager.h"
Expand Down Expand Up @@ -845,17 +844,6 @@ int mingw_noop_main(void) {
return 0;
}

// Try to enable debugger support for the given instance.
// This alway returns success, but prints a warning if it's not able to enable
// debugger support.
Error tryEnableDebugSupport(orc::LLJIT &J) {
if (auto Err = enableDebuggerSupport(J)) {
[[maybe_unused]] std::string ErrMsg = toString(std::move(Err));
LLVM_DEBUG(dbgs() << "lli: " << ErrMsg << "\n");
}
return Error::success();
}

int runOrcJIT(const char *ProgName) {
// Start setting up the JIT environment.

Expand Down Expand Up @@ -936,9 +924,6 @@ int runOrcJIT(const char *ProgName) {
});
}

// Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
Builder.setPrePlatformSetup(tryEnableDebugSupport);

// Set up LLJIT platform.
LLJITPlatform P = Platform;
if (P == LLJITPlatform::Auto)
Expand Down Expand Up @@ -975,6 +960,9 @@ int runOrcJIT(const char *ProgName) {
});
}

// Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
Builder.setEnableDebuggerSupport(true);

auto J = ExitOnErr(Builder.create());

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

0 comments on commit e5f169f

Please sign in to comment.