0
I have a breakpoint on a function (e.g. called foo
) that silently triggers some actions (e.g. count occurences).
break foo
commands
silent
set $counter = $counter+1
cont
end
If I use it on a simple program:
int foo( int x ) { return x-1; }
int bar( int x ) { while (x>0) x = foo(x); }
int
main( int argc, char** argv)
{
bar(10);
return 0;
}
Everything goes well and I end up with $counter
holding a value of 10.
Now if I call bar
directly from gdb:
(gdb) call bar(5)
Not only GDB displays the standard warning message:
the program being debugged stopped while in a function called from GDB...
But the commands associated with the foo breakpoint will be discarded at this occurence of the breakpoint. Thus if I finish with the evaluation, $counter
ends up with a unexpected value
(gdb) call bar(5)
The program being debugged stopped while in a function called from GDB.
Evaluation of the expression containing the function
(bar) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb) cont
Continuing.
(gdb) p $counter
$1 = 4
What can I do to solve this issue, and have gdb executing the breakpoint commands ?