5 useful rdebug tweaks
Here are a few tips on how to make rdebug a lot more useful in just a few minutes.
These settings live in your ~/.rdebug
file. As with all other configuration
files, I recommend keeping this under version control.
List size
set listsize 40
By default rdebug only shows a few lines before and after the line at which your program is currently paused. This setting increases the list size to 40 lines, providing a lot more context.
Auto list
set autolist
When stepping through the code, do a ‘list’ command (that is, print listsize
lines around the current line) after each step. When quickly stepping over
several lines, this almost resembles using a debugger in an IDE where a marker
moves over the lines as they are executed.
Auto eval
set autoeval
Automatically evaluate any unrecognized command as Ruby code. Slightly confusing if you use short variable names in your debug sessions, because they’ll sometimes collide with the debugger command aliases (for example ‘s’).
Auto reload
set autoreload
Reload source files whenever a change has been detected. Not sure how effective this is in Rails projects. If I make a source change I usually just ‘cont’ the debug session and then restart it. In a Rails project, the code will have been reloaded the next time I hit my breakpoint.
Force step
set forcestep
Force stepping to another source line. This fixes the annoying issue where you step on the same line several times because it contains multiple stopping points. You usually want to move to a different line when stepping and this setting ensures that you always do.