Cross-language debugging: from Ruby to Java and back
Until we bring the full support for two ways debugging - from Ruby to Java and vice versa; the following "trick" might be used to debug Ruby and Java at once in the NetBeans 6.5 (you might get 6.5 build here). It might be used to debug standard JRuby applications/scripts, JRuby's Java extension or JRuby's internals itself. I'm using it for some time during development of JRuby Fast Debugger extension.
The trick is to start actually two debugging sessions, one for Ruby part and second for Java part (JVM under which JRuby runtime runs). Sessions then automatically activate themselves when the breakpoint for their language is hit.
Except the Ruby IDE, we need to have Java support installed if it is not already the case. This can be find out by looking e.g. into the New Project Wizard. If the Java category is there, we have all we need. If not see the How do I install the Java support into the Ruby NetBeans IDE? FAQ.


That's it. As can be seen on the following screenshot, after I do a step in the Ruby code, Java debugging
session take over the control and I'm debugging the Java code called from Ruby code with the full power of
NetBeans Java debugger. Once I'm done with Java side I'll just press F5 (Continue) and Ruby debugging session
takes back the control and I can continue with the debugging of Ruby part.
Note that if you have JRuby sources you might just set the breakpoint somewhere in the JRuby interpreter's guts
and take a look what going around in there.

Clearly not fully-fledged cross-language debugging. Since sessions live their life independently, actions like
Step Into, Step Over and similar do not work in the cross-language context. We have to
simulate Step Into and similar actions by putting breakpoints on appropriate places. Stacktrace is not
shared, so we get two, one for each language, instead of one with nicely mixed frames from both languages. But
still, I find it pretty handy during JRuby Fast Debugger development.
If you do not want to repeatedly delete and add the long string from the step 2, you might
create a configuration as might be seen in the properties screenshot (JRuby
Debug in Configuration combobox).
To watch the progress on fully-fledge cross-language debugging, you might CC yourself to this RFE in the Issuezilla.
Posted at 11:05AM Oct 21, 2008 by Martin Krauskopf in Ruby | Comments[6]
Good you blogged about this, the feature has been pretty well hidden :)
Posted by emononen on October 21, 2008 at 11:39 AM PDT #
This is a HUGE deal!!! Many of us are really looking forward to this being feature complete. Excellent work!
Posted by Mario Aquino on October 29, 2008 at 01:50 PM PDT #
Erno> sure, such feature should not be for free! ;)
Mario> I'm not sure how much time I'll have for a debugger into the next release, but at least I could make all the above automatic (i.e. starting both session and doing 'Java Debugger Attach') which would help as well, until the fully-fledged solution is available.
Posted by Martin Krauskopf on October 30, 2008 at 01:22 AM PDT #
Thanks for nice description of how to do this. I've been meaning to write it up, but never have time.
I've been using this in various forms since late July including while developing the ruby debugger support in V3. This meant debugging a debugger (written in ruby and java) that is debugging ruby code that is running in java -- cool and crazy at the same time.
Posted by Peter Williams on November 06, 2008 at 01:44 PM PST #
Peter> yup, exactly my mine use-case, debugging the debugger :)
Posted by Martin Krauskopf on November 06, 2008 at 02:46 PM PST #
Do you think this approach would work trying to debug live code on an appserver (ie glassfish)?
Posted by Jay on March 13, 2009 at 10:04 AM PDT #