Bug 17198 - Batch cmd file abandoned when breakpoint hit
Summary: Batch cmd file abandoned when breakpoint hit
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-24 18:49 UTC by eager
Modified: 2024-01-02 16:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description eager 2014-07-24 18:49:37 UTC

    
Comment 1 eager 2014-07-24 18:57:58 UTC
I noticed some unexpected behavior with a batch command file which calls a target function and encounters a breakpoint.  The batch command file is abandoned, rather than continuing to be executed following the breakpoint.

$ 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
run
call foo(234)
p a
c

$ 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.
(gdb)

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, but does not execute the remaining commands.

Being able to include commands in a batch command file which are executed after a brakepoint is hit is useful in a couple cases.  The first is to create a script which demonstrates a gdb bug.  Second is for automated testing.
Comment 2 Hannes Domani 2024-01-02 16:32:21 UTC
Not sure if this is a dup of PR8487.