ruby-debug version 0.9.1 has been released!

Posted on April 03, 2007

Installation

As usual:

    $ sudo gem in ruby-debug

Changes

This is mainly a maintenance release, which includes several important bugfixes related to frame calculations.

In particular,

  1. All native (implemented in C) methods that take a block will create a new frame. What that means is that in the following code in order to reach line 2:

    1  (1..10).each do |i|
    2    puts i
    3  end
    4  ...
    

    you have to step into the each method. The next command will move you to line 4 skipping the block.

  2. The next command is now 'true' step-over operation. Which means that in the following code:

    1 def f; 1 end
    2 def b; 2 end
    3 f; b
    4
    

    if you are on line 3 you have to call next command twice in order to move to line 4.

  3. Previous change has a subtle side effect when you are debugging ERB templates. You probably already know that you can do that, right? Just set a breakpoint somewhere in your template:

    $ rdebug ./script/server 
    ./script/server:2 require File.dirname(__FILE__) + '/../config/boot'
    [-3, 6] in ./script/server
       1  #!/usr/local/bin/ruby
    => 2  require File.dirname(__FILE__) + '/../config/boot'
       3  require 'commands/server'
    (rdb:1) break list.rhtml:1
    Set breakpoint 1 at list.rhtml:1
    
    
    (rdb:1) cont
    ...
    Breakpoint 1 at list.rhtml:1
    script/../config/../app/views/bug/list.rhtml:1 <% @title = "Task List" -%>
    [-4, 5] in script/../config/../app/views/bug/list.rhtml
    => 1  <% @title = "Task List" -%>
       2  <center>
       3  <% if @list_action and session['filter'] -%>
       4  <div id="filter">Applied filter:&nbsp;
       5  <select name="filters" onchange="javascript:filterChanged(this);">
    
    
    (rdb:6) next
    script/../config/../app/views/bug/list.rhtml:2 <center>
    [-3, 6] in script/../config/../app/views/bug/list.rhtml
       1  <% @title = "Task List" -%>
    => 2  <center>
       3  <% if @list_action and session['filter'] -%>
       4  <div id="filter">Applied filter:&nbsp;
       5  <select name="filters" onchange="javascript:filterChanged(this);">
       6    <option value="all">-- Show All --</option>
    
    
    (rdb:6) eval @title
    "Task List"
    

    and the debugger will stop at the first line of list.rhtml template file when Rails renders it.

    Stepping through your template works relatively well. The only problem is that sometimes ERB generates several instructions for a single line of template code, so that you have to use next command several times in order to move to the next line. That is where you can find the force (+) modifier for step and next commands useful. What that means is that next+ and step+ commands will force the debugger to move to another line.

    Disclaimer: If you find yourself debugging your templates too often, consider revisiting your development approach. Your code does not belong there. Also, Ruby provides top-of-the-art unit-test libraries for you. Use them!

  4. And, finally, starting from this version you can pass the cont-inue command a numerical parameter which makes the debugger to continue until it reaches a specific line of code. This is sort of 'Run to Cursor' command found in modern GUI debuggers.

Enjoy.

Comments
  1. pantarheiApril 03, 2007 @ 02:57 AM

    great as always! Thank you so much.

    one short question. is it possible to autmatically run rdebug after reading the .rdebugrc file? i have several commands in the file, and every time i start rdebug it "hangs" at startup:

    $ rdebug script/server
    ./script/server:2 require File.dirname(__FILE__) + '/../config/boot'
    [-3, 6] in ./script/server
       1  #!/usr/bin/env ruby
    => 2  require File.dirname(__FILE__) + '/../config/boot'
       3  require 'commands/server'
    (rdb:1)
    

    after entering 'c' the server starts up. is there a way to pass the 'c' in .rdebugrc too?

    regards

  2. KentApril 03, 2007 @ 10:53 AM

    pantarhei,

    Give rdebug script -n option:

    $ rdebug -n ./script/server
    
  3. Martin KrauskopfApril 03, 2007 @ 01:18 PM

    Hi Kent,

    are full paths supported on Windows OS when with breakpoint command? I've just run:

    rdebug c:/somepath/somescript.rb

    when I then use:

    b 2
    b c:/somepath/somescript.rb:3
    b c:\somepath\somescript.rb:4
    b c:\somepath\somescript.rb:5
    b somescript.rb:6
    

    breakpoint on lines 3, 4 and 5 are ignored. On Linux-like OSes full paths work. Actually I have some problems in debug-commons project which utilizes your backend and uses full paths and also I've very limited access to Windows OS :) Thanks for the great work.

  4. KentApril 03, 2007 @ 02:09 PM

    Hi Martin,

    Thanks for the bug report. It shows that I'm not a Windows user myself :-).

    Anyway, it's fixed in the trunk.

  5. conorhApril 17, 2007 @ 01:25 PM

    Hi Kent, I'm running into this error quite a lot with ruby-debug. I'm using 0.9.2, debugging a rails app with Debugger.start in my environment.rb and a debugger statement where I want to debug. This happens at the debugger statement..

     INTERNAL ERROR!!! wrong argument type OutputCatcher (expected File)
     /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.2/cli/ruby-debug/interface.rb:44:in `readline'
    /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.2/cli/ruby-debug/interface.rb:44:in `readline'
     /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.2/cli/ruby-debug/interface.rb:4:in `read_command'
     /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.2/cli/ruby-debug/processor.rb:116:in `process_commands'
    
     /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-0.9.2/cli/ruby-debug/processor.rb:66:in `__at_line'
        (eval):5:in `at_line'
        /opt/local/lib/ruby/1.8/thread.rb:135:in `synchronize'
        (eval):3:in `at_line'
     /opt/local/lib/ruby/gems/1.8/gems/ruby-debug-base-0.9.2/lib/ruby-debug-base.rb:46:in `at_line'
    
  6. KentApril 18, 2007 @ 12:48 AM

    conorh,

    Something is overriding $stdout with a instance of OutputCatcher class which is not IO object. That breaks readline since it can't get access to the active terminal.

    Probably you can try the remote mode.

  7. DavidApril 19, 2007 @ 11:46 AM

    How do you install this on a Windows machine with InstantRails?

  8. ChristopherApril 27, 2007 @ 09:23 PM

    Hi,

    Thanks for writing this--it's very helpful! I just posted a bug report of a problem I had under cygwin here:

    http://rubyforge.org/tracker/index.php?func=detail&aid=10425&group_id=1900&atid=7436

  9. TomTomApril 30, 2007 @ 09:49 AM

    Hello, i'm having problems with installing ruby-debug on windows. gem install ruby-debug leads into the following.

    Need to update 1 gems from http://gems.rubyforge.org . complete Install required dependency ruby-debug-base? [Yn] y Building native extensions. This could take a while... ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError) ERROR: Failed to build gem native extension.

    ruby extconf.rb install ruby-debug creating Makefile

    nmake

    Microsoft (R) Program Maintenance Utility Version 1.50 Copyright (c) Microsoft Corp 1988-94. All rights reserved.

        cl -nologo -I. -Ic:/Programme/ruby/lib/ruby/1.8/i386-mswin32 -Ic:/Programme/ruby/lib/ruby/1.8/i386-mswin32 -I. -MD -Zi -O2b2xg- -G6  -c -Tcruby_debug.c
    

    Der Befehl "cl" ist entweder falsch geschrieben oder konnte nicht gefunden werden. NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x1' Stop.

    Gem files will remain installed in c:/Programme/ruby/lib/ruby/gems/1.8/gems/ruby-debug-base-0.9.3 for inspection. Results logged to c:/Programme/ruby/lib/ruby/gems/1.8/gems/ruby-debug-base-0.9.3/ext/gem_make.out

    any help? whats going wrong here? installing ruby-debug on cygwin works fine.

  10. Brian DonovanMay 09, 2007 @ 03:44 AM

    Thanks for ruby-debug! It's great, and I'm sure that it'll become increasingly popular as script/breakpointer is discontinued. To help ease the transition I've started a series of screencasts. The first one, which covers just the basics, is already up, and can be viewed on my blog.

  11. KentMay 10, 2007 @ 01:00 AM

    Hey Brain,

    Very nice screencast!

  12. Stephen BannaschMay 28, 2007 @ 12:35 AM

    When I use ruby-debug with Rails the parameters I set in ~/rdebug appear to be ignored.

    Here's what's in rmy debug bow, set autolist set autoreload