Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach the Rubymine IDE debugger to a shell process?

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?

like image 642
Wolfram Arnold Avatar asked Jan 16 '12 21:01

Wolfram Arnold


People also ask

How do I run a RubyMine debugger?

Select the Run | Debug Shift+F9 command from the main menu and select the required configuration.

How do you attach a debugger to a process in IntelliJ?

Press Ctrl+Alt+F5 or choose Run | Attach to Process from the main menu. IntelliJ IDEA will show the list of the running local processes. Select the process to attach to. The processes launched with the debug agent are shown under Java.

How do you add a configuration in RubyMine?

Create a run/debug configuration from a template From the main menu, select Run | Edit Configurations. Alternatively, press Alt+Shift+F10 , then 0 . on the toolbar or press Alt+Insert .


3 Answers

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.

like image 175
CrazyCoder Avatar answered Sep 25 '22 14:09

CrazyCoder


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"

like image 39
Abdo Avatar answered Sep 23 '22 14:09

Abdo


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.

like image 24
Chris P Avatar answered Sep 25 '22 14:09

Chris P