Remote Debugging: explore Ruby code easily

In the NetBeans 7.0 (dev) you may attach debugger to any process which have been started from the command line, with all the goodies of UI debugger frontend. This means that if you just found some strange behaviour or bug in some CLI tool or you are just curious how e.g. gem list, rake -T, etc. commands work, just run then in debug mode from a terminal and attach to them from the frontend.
There is no need to setup a NetBeans project, even not to open the file or doing whatever in NetBeans, just invoking Menu | Debug | Attach action there.

Let's say we are curious how does gem list --local works.

  • you need to have have ruby-debug-ide in version 0.4.1 (just released) or later installed
  • Run rdebug-ide -p 7000 --stop -- `which gem` list --local. On Windows just replace `which gem` with the c:\\full\\path\\to\\the\\gem command
    (the --stop switch ensures that the debugger stops on the first line. This might not be always what you want if you've set the breakpoints in advance in the NetBeans frontend (e.g. after the first run with the --stop switch). Then just omit the switch and debugger will run until the first breakpoint is hit)
  • In NetBeans invoke Menu | Debug | Attach choose Ruby Debugger in the Debugger combobox if there is more choices (you have also e.g. Java support installed)

That's all. Debugger will stop on the first line of the debuggee. After few steps you are inside RubyGems guts peeking around for how does it actually work.

RubyGems debugging

This is the first step letting you to attach NetBeans debugger to the application run from CLI and/or on another machine. Next step is to provide functionality similar to ruby-debug that you will be able to put a call like:

  if something_peculiar_has_happened
    require 'ruby-debug-ide'
    debugger(7000) # 7000 being a port

into your application and attach to it from the frontend.

Altough this is kind of "remote" debugging and you may attach to the process which was run on another machine, there are not yet sources association implemented in NetBeans. So you would have to have sources located on the same paths on the local machine as the one on the debuggee's machine. But for the case similar to the above which are probably the most frequent one this might be very usefull.

Worth to add that the support were added quite recently. I've also made the code base little bit more "aggressive" which should help to stabilize the debugger a bit more among the layers (from base backend up to the frontend) and prevent kind of random exception. So if you found any problems the feedback is more then welcomed. Either let me know here or through the mailing list or Issuezilla. Thanks


Wow, this is just awesome. I will probably use this a lot.
Do you know if this will also be possible with future versions of the Groovy and Python modules?

Posted by Markus Jais on November 12, 2008 at 04:24 PM PST #

Hi Markus. After quick wiki searching:

I did not find future plan regarding remote debugging feature, but will try to point relevant people here.

Posted by Martin Krauskopf on November 12, 2008 at 04:50 PM PST #

Is there a way to attach to a JRuby process running within Tomcat?

Posted by Darcy Schultz on December 03, 2008 at 12:09 PM PST #

Darcy> I've never tried JRuby - Tomcat combination. But the above should work in general if you are able to run rdebug-ide as main script for the JRuby with debuggee (debugged program) as a parameter. I.e. for Rails:

jruby --debug -S rdebug-ide -p 7000 --stop -- script/server

Posted by Martin Krauskopf on December 03, 2008 at 08:28 PM PST #

Martin, great work!

Can I put a debugger statement deep inside my code somewhere and have the debugger stop there?

This is what I'm doing now:

I'm looking for a regression in trunk jruby that happened in svn r8398.

The result is that some of the rails active record tests crash the jruby interpreter.

In order to make a simple test I am using the technique described on this page to run the netbeans debugger on the jruby rake task.

I'm using this release of the ruby ide:

I also added the Java cluster but that doesn't come into play here.

I'm running these tests on a patched version of the activerecord in rails trunk. More details here:

Here's the command I am using to start the debugger:

jruby --debug -S rdebug-ide -p 7000 --stop -- /Users/stephen/dev/ruby/src/jruby.git/bin/rake test_jdbcmysql TEST=test/cases/serialization_test.rb

I'd like to be able to insert a debugger statement into serialization_test.rb because while stepping through rake is interesting (and NB seems to do this very nicely) -- it takes a while.

My real goal here is to step through the rails code fo the to_sml method on an ActiveRecord instance far enough to find out where the crash is happening.

fyi: copy of this comment sent to

Posted by Stephen Bannasch on December 27, 2008 at 03:15 PM PST #

Hi Stephen, I've replied on the mailing list, let's continue there (

Posted by Martin Krauskopf on December 28, 2008 at 07:33 PM PST #

Is the host name always vboxsvr on version 3.1.2? If not, where do I find the host name? I can't map a drive to \\\\vboxsvr\\myshare. I can ping the host IP address from WIN 7 but can't map a drive using the IP address. It finds the box but not the folder.

Posted by aion kinah on March 04, 2010 at 04:47 PM PST #

I would like to use it to achieve software licensing mechanism per module, so if a module is not licensed it shoud get disabled. My current approach is to use ModuleInstaller, but then I cannot get rid of or customise the startup dialog allowing one to accept module disablement and continue, or exit.

Posted by secureid3 on March 04, 2010 at 05:06 PM PST #

I can ping the host IP address from WIN 7 but can't map a drive using the IP address. It finds the box but not the folder.

Posted by david on April 18, 2011 at 08:15 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Martin Krauskopf


« April 2014