Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do I put in my Ruby (JRuby) code to break into the debugger?

I'm familiarizing myself with some JRuby code, and I'd like to be able to place a breakpoint in the code and run (as usual) from the command-line, having it break into the debugger when it gets to that point. Is there something I can put in my code to force JRuby to break into the debugger?

I've tried running jruby -r debug foo.rb (instead of the usual jruby foo.rb), and then setting a breakpoint with b bar.py:98, and then continuing. But the debugger stops every time there's an exception, and there seem to be a lot of them before it gets to the line of code I'm interested in. I'd like to be able to put the "break-into-debugger" line(s) in my code and run jruby foo.rb and have the first place the debugger stops be at that line.

(i.e. I'm looking for the Ruby/JRuby equivalent of import pdb;pdb.set_trace() in Python.)

like image 583
Daryl Spitzer Avatar asked Mar 24 '10 00:03

Daryl Spitzer


1 Answers

You could try Netbeans Ruby IDE, it has JRuby interpreter and debugging tools embedded and you can debug visually in the IDE directly.
If using an IDE is not an option for you, just install de debug gem into your JRuby distro and use it via debugger command:

  1. Manually download the ruby-debug-base-0.10.3.1-java.gem from debug-commons to a local directory.
  2. Install the Gem into your JRuby Gem repository:
    jruby -S gem install -l ruby-debug-base-0.10.3.1-java.gem
  3. Install ruby-debug gem:
    jruby -S gem install --ignore-dependencies ruby-debug

The debugger command should work now.

# test.rb
require 'rubygems'
require 'ruby-debug'
debugger
# run like this:
jruby --debug -S rdebug test.rb

More information on Netbeans wiki, rdebug wiki and JRuby wiki

like image 182
clyfe Avatar answered Oct 19 '22 22:10

clyfe