Question

I want to use Rubymine's IDE debugger to debug a ruby process running in the command shell, as it is spawned, e.g. by "rails console".

I've gotten great mileage out of the debugger when running the web server (from within Rubymine) or test suites (also run from within Rubymine).

However, if the process isn't started by Rubymine, I'm at a loss of how to attach the debugger.

I'm using version Rubymine 3.2.4 on Ubuntu with Sun Java 1.6.0_26, Ruby REE 1.8.7, and the latest debug gems:

ruby-debug-base (0.10.4)
ruby-debug-ide (0.4.17.beta8)

Thoughts?

Was it helpful?

Solution

Use Ruby Remote Debug configuration type in RubyMine. Refer to the official RubyMine documentation for details.

Basically you run the script like:

rdebug-ide --port <port number> -- script.rb

and then connect to the specified port from RubyMine debugger.

OTHER TIPS

This is how you do it in Rails:

First, make sure you have rdebug-ide installed:

gem install ruby-debug-ide --platform=ruby

Next, run this in the console:

rdebug-ide --port 6778 -- /projects/your_rails_project/script/rails console

or for rails 4.0+

rdebug-ide --port 6778 -- /projects/your_rails_project/bin/rails console

Or, as @ChristopherWill mentioned below, you can pass a --host parameter if you wish to debug a non-local server. (Read his comment below for caveats)

This will wait for remote debug clients to connect.

  1. Click on Run > Edit Configurations in RubyMine then add a "Ruby Remote Debug" instance

  2. Use the same port as above 6778 (If you change the one above, make sure the ports match)

  3. Root folder and Local root folder are the same, /projects/your_rails_project

  4. Click on Apply and close.

Next, pick this configuration from the list right next to the run and debug buttons then click on the debug button. Give it a few seconds and the console will run "rails console" where ever you ran "rdebug-ide"

I really want to post something here that is very hard to find a complete answer out there for and it took me a very long time to figure out. There are people asking how to attach remote debug to resque worker and here is the proper way that works finally for me. This article is high on google search and will be easy to find.

FROM SHELL on the server (for me its my laptop) execute this from your site root: rdebug-ide --port 1236 --dispatcher-port 26166 --host 0.0.0.0 bin/rake resque:work QUEUE=*

in RubyMine IDE configure remote debug with: Remote host: 127.0.0.1 Remote Port: 1236 Remote Root Folder: path on server to site root Local Port: 26166 Local root path: path on your workstation to your root file where you would set breakpoints (in my case its all local so its all 1 path and 1 copy of the files)

Run your web server as normal with: rails s

setup a breakpoint in your Resque worker and attempt to execute whatever you need to in your site to get you to that breakpoint.

1 note - having the "spring" gem gave me errors and I had to comment it out/bundle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top