ruby-debug / ruby-debug-ide

An interface which glues ruby-debug to IDEs like Eclipse (RDT), NetBeans and RubyMine.
https://www.jetbrains.com/ruby/features/ruby_debugger.html
Other
370 stars 83 forks source link

Do not kill the Ruby process when IDE debugger session disconnects #199

Open TSMMark opened 3 years ago

TSMMark commented 3 years ago

When my IDE disconnects from the debug session, it kills the main process – the process started by rdebug-ide command. How to avoid this?

If this is not supported already, I would be happy to try to implement a CLI flag for this if given a pointer or two in the right direction.

I scoured this repo for a way to do this or an open issue but couldn't find anything. --disable-int-handler sounded like it might do it, but has no effect. Sorry if this is a duplicate issue!

lalunamel commented 3 years ago

I'd like this feature as well.

I'm not a maintainer or anything, but I've been noodling around the code recently and can point you in the right direction.

Here's the bit of code that handles the quit command, which is sent when your IDE disconnects from a debugging session. https://github.com/ruby-debug/ruby-debug-ide/blob/master/lib/ruby-debug-ide/commands/control.rb#L2

Commands are sent over a socket from the IDE to ruby-debug-ide and parsed here. https://github.com/ruby-debug/ruby-debug-ide/blob/master/lib/ruby-debug-ide/ide_processor.rb#L75

I'd imagine any solution to prevent ruby-debug-ide from terminating would involve mucking around in control.rb

hurricup commented 3 years ago

@TSMMark what version of the gem used?

TSMMark commented 3 years ago

@hurricup latest. ruby-debug-ide (0.7.2)

TSMMark commented 3 years ago

In my quick local testing, it looks like simply removing the exit! line here works like a charm!

https://github.com/ruby-debug/ruby-debug-ide/blob/83b5d22f71879cad0a1dd0b2a9a5f1d7a9aabc5b/lib/ruby-debug-ide/commands/control.rb#L14

The same Ruby process can later be reattached to the debugger and everything.


I'll try to submit a PR asap that optionally skips the exit! based on cli flag or env var or something

yasaichi commented 1 year ago

For the future googlers, here's my patch until the PR is merged:

$ cat bin/rdebug-ide
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "ruby-debug-ide"

Debugger::QuitCommand.prepend(
  Module.new {
    def execute
      # NOTE: We must ensure that all breakpoints are cleared before disconnecting sessions,
      # or you'll face a `closed stream` error.
      Debugger.breakpoints.clear
      @printer.print_msg("finished")
    end
  }
)

load Gem.bin_path("ruby-debug-ide", "rdebug-ide")

Usage:

$ bin/rdebug-ide [same arguments as the original ones]