A GDB public service announcement

Possibly I’m about to make a fool of myself saying this, but since I wasted some time a few days ago I might help someone doing it.

Say you are debugging some feature in your program that is enabled with some command line paramater (“random” example: the –private option in Epiphany for private profiles). One way of passing this to gdb is the –args flag, but another one is to pass them to run/r in the prompt, like:

(gdb) r –private

You do your stuff, and then you decide you need to see what happens without the option. One “obvious” way to do it would be to write, after the previous line:

(gdb) r

Right? Wrong. From the GDB manual:

run with no arguments uses the same arguments used by the previous run, or those set by the set args command.

So you’d be basically running your program with –private again. The right way to do it, as the manual says, is to reset the arguments with ‘set args’.

I wonder how many silly things I have done through the years without noticing because I didn’t know this.

This entry was posted in General. Bookmark the permalink.

5 Responses to A GDB public service announcement

  1. tuXXX says:

    Well… this is something I already know.
    I don’t really know how I disovered that, but it’s usually good to avoid typing a lot of args again and again.

  2. Andy says:

    Wow, I didn’t know that 🙂

    The application I’m usually debugging I run with a “-i” parameter. It is so auto-pilot now for me, that when running other things in gdb, I use “r -i” to run them.

  3. stormy says:

    Wow. I can see how that would be really useful but incredibly confusing to someone who didn’t know that was going on.

  4. Frank Osterfeld says:

    If you want to clear the args, e.g. for running the program without any args, call

    set args

  5. Frank Osterfeld says:

    Ah, I see you already mentioned that. Nevermind then.

Leave a Reply

Your email address will not be published. Required fields are marked *