GDB as a program analyzer - some thoughts

Jim Blandy
Thu May 20 03:11:00 GMT 2004

Alexandre Courbot <> writes:
> So, I wonder if some breakpoint settings would be implementable with
> gdb (or if they can already be expressed and I missed them):
> - Setting a breakpoint at the returning of a function

I think this would be a great feature.  Stan Shebs and I looked into
implementing a long time ago, and decided that it couldn't be done
without further help from the compiler.  The first problem is that
it's hard to decide where to put the breakpoint: the function return
code could be replicated many times in the function's body.  But even
then, you need to set the breakpoint before the code that restores the
caller's registers and frame pointer, or else you won't be able to
find your local variables.

So this is harder than it looks.  I think it might need help from the

> - Setting a breakpoint at some fixed point of a function (for
> instance, a C label)

This would be nice, too.  At the moment, GCC does produce debugging
information for labels when the Dwarf 2 debug format is used, but
GDB's support for them is incomplete.

> - Any other breakpoint setting that is not line-number based and would
> support source modification

GDB's 'search' command sets the convenience variable $_ to the number
of the matching line.  So you can do stuff like this:

(gdb) search marker
6         i--;  /* marker */
(gdb) break $_
Breakpoint 1 at 0x804837b: file label.c, line 6.

I think that's your best bet at the moment.

More information about the Gdb mailing list