helping the jruby effort debugging the source
Wanna help improve JRuby? Make sure you read this post by Charles Nutter first. There he explains how to run Ruby specs with JRuby.
Start with fixing Ruby specs is a great way to get acquainted with the code. And it’s also a important task in order to make sure JRuby is the most complete and compatible ruby implementation out there.
But before you get your hands dirty, it will be a lot easier if you can actually debug JRuby’s source while fixing any specs - or bugs/features for that matter.
Taking as an example one of the specs I fixed, this is how you run it - form within your jruby source directory:
$ bin/jruby spec/mspec/bin/mspec spec/ruby/language/class_spec.rb
This is using jruby to execute the mspec binary against the class_spec.rb script. Now, if you want to debug this script instead of only running it, try this:
$ bin/jruby -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000 -J-Xdebug spec/mspec/bin/mspec -T-X+C spec/ruby/language/class_spec.rb
The extra arguments will start a debugging session on port 4000 and suspend the VM, which will be waiting for another debug process to attach. You can do that using any IDE of your choice but I’ll use Eclipse for this example.
Go to the Run menu and select the “Debug Configurations…” item. You’ll see a screen similar to the one shown below:
{% img /assets/images/picture-2-300x240.png %}
As you can see, you need to create a new “Remote Java Application” configuration, setting the port to the same one you used to start the debugger session - 4000 in our case. Don’t forget to add JRuby’s source code in the Source tab on this same screen.
Once you’re done, set a breakpoint anywhere in JRuby’s sources and run the newly created configuration.
That’s it! Enjoy!