From dcd2b2db0cafb9ca9fd4bb3d6ac81f9e66ac72ae Mon Sep 17 00:00:00 2001 From: TSMMark Date: Fri, 25 Sep 2020 16:44:28 -0400 Subject: [PATCH 1/2] DEBUGGER_KEEP_PROCESS_ALIVE --- bin/rdebug-ide | 6 ++++++ lib/ruby-debug-ide/commands/control.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/rdebug-ide b/bin/rdebug-ide index fce28c94..4e9c6b17 100755 --- a/bin/rdebug-ide +++ b/bin/rdebug-ide @@ -18,6 +18,7 @@ options = OpenStruct.new( 'stop' => false, 'tracing' => false, 'skip_wait_for_start' => false, + 'keep_process_alive' => false, 'int_handler' => true, 'dispatcher_port' => -1, 'evaluation_timeout' => 10, @@ -70,6 +71,7 @@ EOB opts.on('--stop', 'stop when the script is loaded') {options.stop = true} opts.on("-x", "--trace", "turn on line tracing") {options.tracing = true} opts.on("--skip_wait_for_start", "skip wait for 'start' command") {options.skip_wait_for_start = true} + opts.on("--keep-process-alive", "don't exit the process when debugger is exited") {options.keep_process_alive = true} opts.on("-l", "--load-mode", "load mode (experimental)") {options.load_mode = true} opts.on("-d", "--debug", "Debug self - prints information for debugging ruby-debug itself") do Debugger.cli_debug = true @@ -167,6 +169,10 @@ if options.int_handler trap('INT') { Debugger.interrupt_last } end +if options.keep_process_alive + ENV['DEBUGGER_KEEP_PROCESS_ALIVE'] = "true" +end + # set options Debugger.keep_frame_binding = options.frame_bind Debugger.tracing = options.tracing diff --git a/lib/ruby-debug-ide/commands/control.rb b/lib/ruby-debug-ide/commands/control.rb index 6fd030f2..d8fba9fc 100644 --- a/lib/ruby-debug-ide/commands/control.rb +++ b/lib/ruby-debug-ide/commands/control.rb @@ -11,7 +11,7 @@ def execute @printer.print_msg("finished") @printer.print_debug("Exiting debugger.") ensure - exit! # exit -> exit!: No graceful way to stop threads... + exit! unless ENV['DEBUGGER_KEEP_PROCESS_ALIVE'] == "true" # exit -> exit!: No graceful way to stop threads... end end From dc35b3bac274ca3894a8bb12ad7e15839b95dc36 Mon Sep 17 00:00:00 2001 From: Vilmos Agoston Date: Sun, 10 Jul 2022 19:57:37 +0100 Subject: [PATCH 2/2] Improve --keep-process-alive --- lib/ruby-debug-ide/commands/control.rb | 10 ++++++++-- lib/ruby-debug-ide/interface.rb | 4 +++- test-base/test_base.rb | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ruby-debug-ide/commands/control.rb b/lib/ruby-debug-ide/commands/control.rb index d8fba9fc..d92efb98 100644 --- a/lib/ruby-debug-ide/commands/control.rb +++ b/lib/ruby-debug-ide/commands/control.rb @@ -8,8 +8,14 @@ def regexp def execute begin - @printer.print_msg("finished") - @printer.print_debug("Exiting debugger.") + if ENV['DEBUGGER_KEEP_PROCESS_ALIVE'] == "true" + @delegate_sd_obj.interface.closing = true + Debugger.breakpoints.clear + @delegate_sd_obj.interface.command_queue << 'c' + else + @printer.print_msg("finished") + @printer.print_debug("Exiting debugger.") + end ensure exit! unless ENV['DEBUGGER_KEEP_PROCESS_ALIVE'] == "true" # exit -> exit!: No graceful way to stop threads... end diff --git a/lib/ruby-debug-ide/interface.rb b/lib/ruby-debug-ide/interface.rb index 3d68ba0b..269d2a4e 100644 --- a/lib/ruby-debug-ide/interface.rb +++ b/lib/ruby-debug-ide/interface.rb @@ -10,10 +10,12 @@ class LocalInterface < Interface class RemoteInterface < Interface # :nodoc: attr_accessor :command_queue + attr_accessor :closing def initialize(socket) @socket = socket @command_queue = Queue.new + @closing = false end def read_command @@ -23,7 +25,7 @@ def read_command end def print(*args) - @socket.printf(*args) + @socket.printf(*args) unless (@closing && ENV['DEBUGGER_KEEP_PROCESS_ALIVE']) end def close diff --git a/test-base/test_base.rb b/test-base/test_base.rb index a9719b4e..6e520225 100644 --- a/test-base/test_base.rb +++ b/test-base/test_base.rb @@ -128,7 +128,7 @@ def start_ruby_process(script, additional_opts = '') status = wait_thr.value end @process_finished = true - fail "ERROR: \"#{process}\" failed with exitstatus=#{status.exitstatus}" unless status.success? + fail "ERROR: \"#{cmd}\" failed with exitstatus=#{status.exitstatus}" unless status.success? end end