in Rails

Ruby-debug quick tips: init file and -n option

I use ruby-debug quite a bit (too much? perhaps). And every time I start it, I find myself setting a few options (always the same ones), and it finally got to the point where I thought there had to be a better way. And there was! (Thank you, Kent)

The solution is even documented in some recent release notes:

Create a .rdebugrc in your home directory (it also looks for one in the current directory first):

set autolist
set autoeval
set autoreload
set forcestep

And voila! Each time you start rdebug, it executes this script.

An other good tip: run with -n to avoid stopping on the first instruction, now that you don’t need to run all these commands.

Update: with version 0.10, -n does not seem to be recognized, but —no-stop still works.

  1. -n was found to be broken right before the 0.10.0 release. Although this breaks backwards compatibility a bit, it was felt to leave out because there are now a number of other “no” options, e.g. —no-check,—no-quit, as well as—no-stop. And in 0.10.1 there will probably be —no-rewrite-program.

    If there were some other precedent for -n meaning—no-stop, for example if gdb used it for that purposed that would have also influenced keeping -n. But gdb doesn’t use -n and I’m not aware of other debuggers that use it for that purpose either.

    There is a desire to try to be compatible with gdb except when there is good reason not to. So the experience one has or gains in using rdebug or gdb (or pydb or bashdb) is reinforced in switching between gdb-like debuggers.

  2. Rocky,

    this sounds reasonable. It was a case of bad timing on my part: right after I hit publish, I found out there was a newer version, so I updated and realized -n no longer worked.

    A possible suggestion: add commands that one can put in .rdebugrc to do the—no-stop, and all the others.

  3. An interesting idea worth considering and I’ll put it on the list of things to do. However it’s not without some complexity and potential confusion.

    .rdebugrc is not just read/executed when running rdebug. It is read/executed inside Debugger.debugger or every time the debugger is entered via an explicit call. But (no-)stop makes sense only if run initially. It seems weird to add a debugger command with such a limited use. There are other command options that either can’t be done in the middle of a running program, or are pretty difficult to do. For example, starting/stopping a control thread, or changing a port specification. Possibly some of these options could be used in specifying options run when a reset is done.

    Lastly .rdebugrc is conceptually running debugger commands. It is supposed to be equivalent to running the “source command on the init file. Setting options is a slightly different beast. However this aspect is the least troublesome.

  4. Thank you for taking it into consideration :)

    I did try to put a continue in the .rdebugrc, but it was ignored… Oh well, worth a try.

    I suppose one could alias rdebug to “rdebug—no-stop” and that would do it.

  5. I could try to explain why this doesn’t work, but it’s a little complicated. Suffice it to say it’s a bug that I can’t easily fix right now.

    So instead in SVN (for release 0.10.1), I’ve just added yet another file that gets read $HOME/.rdboptrc (on Unixy things and rdbopt.ini for MS Windosw). In that file you can set the OpenStruct object options. Actually since this file is eval’d you can run arbitrary Ruby code in that, including such as debugger so you can see how options are set already.

    
     # This file contains how you want the default options to ruby-debug
     # to be set.
     options.stop = false
     puts "My .rdboptrc was run"
    
    

    The 0.10.1 manual lists the fields of options or look at the rdebug source code.

Comments are closed.