Changes in version ruby-debug 0.2

Posted on July 16, 2006

Remote Debugging

I've just released a new version of ruby-debug which has a new feature: remote debugging. In order to use it you have to pass -s parameter to rdebug script:

    $ rdebug -s <script.rb>

This option makes the debugger start listening for an incoming TCP connection on port 8989, by default. You can change the default port and host name with -p and -h option respectively.

Now when the debugger is started this way, you can connect to it using this command:

    $ rdebug -c

Also since this feature is implemented using plain sockets, you can connect to the remote debugger using a plain telnet client:

    $ telnet localhost 8989
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    script/../config/../app/controllers/shop_controller.rb:28: product_id = params['id']
    PROMPT (rdb:3) 
    list
    [23, 32] in script/../config/../app/controllers/shop_controller.rb
       23      end
       24    end
       25  
       26    def product
       27      debugger
    => 28      product_id = params['id']
       29      unless product_id
       30        redirect_to :action => 'index'
       31        return
       32      end
    PROMPT (rdb:3) 
    cont

API Changes

One more thing. There are two important changes have been made.

  • First off, starting from this version when you require 'ruby-debug', it doesn't activate the debugger by default. You have to explicitly activate it by calling Debugger#start method. Also if you want to activate remote debugging, you should start the listener server by calling Debugger#start_server(host, port) method.

    require 'ruby-debug'
    Debugger.start_server
    Debugger.start
    
  • Second off, it used to be possible at the debugger prompt to type anything and the debugger evaluates the expression, now you should use eval or p command.

Win32 gem

Thanks to Max Muermann, win32 version of ruby-debug 0.1.5 is available for download. The ruby-debug 0.2 version is coming too.

Update: win32 version of ruby-debug 0.2 is now available.

Comments
  1. aurelianJuly 16, 2006 @ 11:14 PM

    Hi,
    I have upgraded to this version and my problem is fixed.
    10x for this great piece of software.

  2. Jay LevittJuly 18, 2006 @ 01:50 PM

    I’m confused about how to use the remote debugger on win32. If I go to a rails directory and type

    rdebug -s script/console

    I still see the normal, local debugger in operation. And if I open up a second command prompt and type

    rdebug -c

    (no host or port), it says “Connected”. But then I can’t type anything.

    If I go down to the rdebug server window and type “c” to continue the program, console starts up and gives me its input prompt. Still nothing shown on the client window.

    And if I try to telnet to port 8989 at any time, it just immediately hangs up on me.

  3. KentJuly 18, 2006 @ 02:26 PM

    Jay,

    Yeah, it’s a little bit confusing. It works like that:

    1. When you start your application with:

    rdebug -s script/console
    you still start the debugger in the local mode. `-s` parameter makes the debugger start listening on the port 8989. At this point you can either set your breakpoints and continue (or you can simply continue in case you use `debugger` method somewhere in your code).

    2. Then you connect to the debugger with

    rdebug -c
    Whenever your code reaches breakpoint or `debugger` method call, this client will get a debugger prompt. If you start a new client with `rdebug -c` or connect with a telnet, it will take over the first client.

    I know it’s a little bit confusing, but I open to suggestions though.

Post a comment
Comment





You may use Markdown in your comments, so please give your code snippets a four-space indent.