From 55751f5f6303582ef683dabc151fcd4ccab6780b Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Sun, 14 Nov 2021 15:42:45 -0800 Subject: [PATCH] [llvm-jitlink] Add an explicit -debugger-support option. Commit 69be352a196 restricted the MachO debugger support testcase to run on Darwin only, but we still need to disable debugger support by default for other noexec tests. This patch introduces a -debugger-support option to llvm-jitlink that is on-by-default when executing code, and off-by-default for noexec tests. This should prevent regression tests from trying (and failing) to set up MachO debugging support when running on non-Darwin platforms. to explicitly enable/disable support. --- .../X86/MachO_gdb_jit_debuginfo_register.s | 3 ++- llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 23 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_gdb_jit_debuginfo_register.s b/llvm/test/ExecutionEngine/JITLink/X86/MachO_gdb_jit_debuginfo_register.s index 968b7c9794c9..1d0c813aed54 100644 --- a/llvm/test/ExecutionEngine/JITLink/X86/MachO_gdb_jit_debuginfo_register.s +++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_gdb_jit_debuginfo_register.s @@ -1,6 +1,7 @@ # REQUIRES: system-darwin && asserts # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -filetype=obj -o %t %s -# RUN: llvm-jitlink -debug-only=orc -noexec %t 2>&1 | FileCheck %s +# RUN: llvm-jitlink -debug-only=orc -debugger-support -noexec %t 2>&1 \ +# RUN: | FileCheck %s # # Check that presence of a "__DWARF" section triggers the # GDBJITDebugInfoRegistrationPlugin. diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index 81c1e94b6b13..202b459a6078 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -101,6 +101,11 @@ static cl::list InputArgv("args", cl::Positional, cl::ZeroOrMore, cl::PositionalEatsArgs, cl::cat(JITLinkCategory)); +static cl::opt + DebuggerSupport("debugger-support", + cl::desc("Enable debugger suppport (default = !-noexec)"), + cl::init(true), cl::Hidden, cl::cat(JITLinkCategory)); + static cl::opt NoProcessSymbols("no-process-syms", cl::desc("Do not resolve to llvm-jitlink process symbols"), @@ -990,7 +995,7 @@ Session::Session(std::unique_ptr EPC, Error &Err) auto &TT = ES.getExecutorProcessControl().getTargetTriple(); - if (TT.isOSBinFormatMachO()) + if (DebuggerSupport && TT.isOSBinFormatMachO()) ObjLayer.addPlugin(ExitOnErr( GDBJITDebugInfoRegistrationPlugin::Create(this->ES, *MainJD, TT))); @@ -1011,11 +1016,13 @@ Session::Session(std::unique_ptr EPC, Error &Err) Err = P.takeError(); return; } - } else if (!NoExec && !TT.isOSWindows() && !TT.isOSBinFormatMachO()) { - ObjLayer.addPlugin(std::make_unique( - ES, ExitOnErr(EPCEHFrameRegistrar::Create(this->ES)))); - ObjLayer.addPlugin(std::make_unique( - ES, ExitOnErr(createJITLoaderGDBRegistrar(this->ES)))); + } else if (!TT.isOSWindows() && !TT.isOSBinFormatMachO()) { + if (!NoExec) + ObjLayer.addPlugin(std::make_unique( + ES, ExitOnErr(EPCEHFrameRegistrar::Create(this->ES)))); + if (DebuggerSupport) + ObjLayer.addPlugin(std::make_unique( + ES, ExitOnErr(createJITLoaderGDBRegistrar(this->ES)))); } ObjLayer.addPlugin(std::make_unique(*this)); @@ -1206,6 +1213,10 @@ static Error sanitizeArguments(const Triple &TT, const char *ArgV0) { if (EntryPointName.empty()) EntryPointName = TT.getObjectFormat() == Triple::MachO ? "_main" : "main"; + // Disable debugger support by default in noexec tests. + if (DebuggerSupport.getNumOccurrences() == 0 && NoExec) + DebuggerSupport = false; + // If -slab-allocate is passed, check that we're not trying to use it in // -oop-executor or -oop-executor-connect mode. //