How to attach the Rubymine IDE debugger to a shell process?
Asked Answered
I

3

12

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?

Illampu answered 16/1, 2012 at 21:41 Comment(1)
I think the title of your question is missing a verb.Cassiopeia
S
8

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.

Stephan answered 16/1, 2012 at 22:1 Comment(1)
Thanks @Stephan that worked, after I sifted through my confusion a bit: 1. Launch from the command line the rdebug-ide command, e.g. to debug a rails console shell session it would read: rdebug-ide --port 1234 -- rails console. 2. In RubyMine, use the run configuration editor and make a new Ruby Remote Debug configuration using the same port (here 1234), and the remote path set to the working directory, then hit the debug button, and it'll cause the shell to initialize, while the sources can be breakpointed in RubyMine. Much appreciated!Illampu
V
7

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"

Valery answered 11/6, 2012 at 20:5 Comment(9)
Thanks, but that actually no longer works in Rails 3.2, because rails console now spawns a separate process, and the RubyMine IDE debugger cannot yet handle multi-process debugging, although they're supposedly including this in the next release of RubyMine.Illampu
I am debugging a rails 3.2.2 application (ruby 1.9.3p194) at the moment with RubyMine 4.0.3 . When I tried running "boot.rb" (with rdebug-ide) the process started and stopped right away. It worked for me when I used the command above though.Valery
You can get the process to run no problem, but I don't think you can get it to stop at breakpoints, because the rails executable spawns a background process that's not monitored. And my whole reason for running it in the debugger in the first place is to set breakpoints. youtrack.jetbrains.com/issue/RUBY-10967Illampu
Mine is stopping at breakpoints and everything is working as expected. Could it be because I have this code in my development.rb? silence_warnings do begin require 'pry' Rails::Console::IRB = Pry rescue LoadError rescue end endValery
Ah, perhaps the behavior with Pry is different. I haven't tried. But good to know.Illampu
Awesome. After struggling around endless hours this steps got me finally get remote debugging running with IntelliJ (Ruby 4.0.3.20120406), ruby-debug-ide 0.4.17.beta9 and ruby-debug-base 0.11. It works like a charm. But does someone know how to debug the application accessed by a browser (and without specifying any script directly as rdebug-ide parameter)?Freestyle
@Christopher you mean the web application? If so, this is the easy one! If it's the first time, in Run > Edit Configurations, click on Rails then hit the + button. You might be facing problems with the SDK so select the SDK that you use when doing rails server. After clicking apply, next time you hit debug, it will be using this configuration (given that it's the only one). If you have other configurations, you can click the drop down and select the newly created config. =) If my answer above was helpful, make sure to upvote it! :-)Valery
@Valery This works pretty for local HTTP debugging, but not for remote. I want my IDE to use the environment of my VM installation. And this is where it gets unthrifty. But yesterday I found a (not perfect but acceptable) solution for this. I can pass the WEBrick server as to rdebug-ide. rdebug-ide --port 1234 --host 192.168.56.101 -- /my/remote/path/script/rails server -p 3000 After starting the remote-debug within my IDE it actually stops at my breakpoints. The only disadvantage is the fact, that I have to pass the port (3000) to all my HTTP requests.. but still better than nothing.Freestyle
Good solution there! If you don't want to keep passing port numbers, you can use nginx as a proxy and you're good to go :-)Valery
I
3

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.

Influential answered 31/10, 2015 at 3:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.