Batch command file - bug or feature?

Michael Eager
Thu Jun 19 15:22:00 GMT 2014

I noticed some unexpected behavior with a batch command
file which calls a target function.

$ cat t.c
#include <stdio.h>
void foo (int a)  {
   printf ("a = %d\n", a);
void main (void) {
   foo (123);

$cat gdb.cmd
b main
b foo
call foo(234)
p a

$ gdb -x gdb.cmd t
Breakpoint 1 at 0x400551: file t.c, line 7.
Breakpoint 2 at 0x400537: file t.c, line 3.

Breakpoint 1, main () at t.c:7
7         foo (123);

Breakpoint 2, foo (a=234) at t.c:3
3         printf ("a = %d\n", a);
gdb.cmd:4: Error in sourced command file:
The program being debugged stopped while in a function called from GDB.
Evaluation of the expression containing the function
(foo) will be abandoned.
When the function is done executing, GDB will silently stop.

The breakpoint during the target function call apparently
causes gdb to decide that there is an error in the batch
file which it abandons.  Subsequent commands in the batch
file are ignored.  It doesn't seem to matter whether the
target generates an interrupt from a breakpoint or a SEGV.

If run with --batch --command instead of -x, gdb terminates
rather than generating the CLI prompt.

I think that this is a bug and that execution should continue
with the next command in the batch file.  Does anyone think gdb
is working as intended?

Michael Eager
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

More information about the Gdb mailing list