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,
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
eachmethod. The next command will move you to line 4 skipping the block.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 4if you are on line 3 you have to call next command twice in order to move to line 4.
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: 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: 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.rhtmltemplate 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!
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.
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:
after entering 'c' the server starts up. is there a way to pass the 'c' in .rdebugrc too?
regards
pantarhei,
Give
rdebugscript-noption: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:
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.
Hi Martin,
Thanks for the bug report. It shows that I'm not a Windows user myself :-).
Anyway, it's fixed in the trunk.
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..
conorh,
Something is overriding $stdout with a instance of OutputCatcher class which is not IO object. That breaks
readlinesince it can't get access to the active terminal.Probably you can try the remote mode.
How do you install this on a Windows machine with InstantRails?
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
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.
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.
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.
Hey Brain,
Very nice screencast!
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