Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to reset breakpoint stats in GDB?

Assume the following .gdbinit:

break foobar
ignore 1 1
run

The program is started using gdb --args ./myprogram --argument1 --argument2 etc.

Now, when I start this the first time around all is fine and dandy. However, if I issue a run on the (gdb) prompt in order to restart the program with the last-known command line, the ignore line will simply not take effect.

The reason is of course clear. The first time around I end up with

(gdb) info break
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000000000061ea6a in foobar at ../foobar.c:1173
        breakpoint already hit 1 time

And any subsequent run starts with whatever value is shown for X in breakpoint already hit X time. Naturally that value will already exceed the limit set by ignore.

How can I reset the stats on the breakpoints or better yet how can I cause run to do that automatically for me?

like image 457
0xC0000022L Avatar asked Oct 19 '22 15:10

0xC0000022L


1 Answers

How can I reset the stats on the breakpoints or better yet how can I cause run to do that automatically for me?

One way to do that is:

# ~/.gdbinit
break foobar
break main
commands 2
  silent
  ignore 1 1
  continue
end

Now, every time you run, you hit silent breakpoint on main, which resets the ignore count on foobar breakpoint and continues.

like image 71
Employed Russian Avatar answered Oct 23 '22 06:10

Employed Russian