binutils-gdb/gdb/testsuite/gdb.server
Tom de Vries be6a2dca15 [gdb/cli] Make quit really quit after remote connection closed
Consider a hello world a.out, started using gdbserver:
...
$ gdbserver --once 127.0.0.1:2345 ./a.out
Process ./a.out created; pid = 15743
Listening on port 2345
...
that we can connect to using gdb:
...
$ gdb -ex "target remote 127.0.0.1:2345"
Remote debugging using 127.0.0.1:2345
Reading /home/vries/a.out from remote target...
  ...
0x00007ffff7dd4550 in _start () from target:/lib64/ld-linux-x86-64.so.2
(gdb)
...

After that, we can for instance quit with confirmation:
...
(gdb) quit
A debugging session is active.

        Inferior 1 [process 16691] will be killed.

Quit anyway? (y or n) y
$
...

Or, kill with confirmation and quit:
...
(gdb) kill
Kill the program being debugged? (y or n) y
[Inferior 1 (process 16829) killed]
(gdb) quit
$
...

Or, monitor exit, kill with confirmation, and quit:
...
(gdb) monitor exit
(gdb) kill
Kill the program being debugged? (y or n) y
Remote connection closed
(gdb) quit
$
...

But when doing monitor exit followed by quit with confirmation, we get the gdb
prompt back, requiring us to do quit once more:
...
(gdb) monitor exit
(gdb) quit
A debugging session is active.

        Inferior 1 [process 16944] will be killed.

Quit anyway? (y or n) y
Remote connection closed
(gdb) quit
$
...

So, the first quit didn't quit.  This happens as follows:
- quit_command calls query_if_trace_running
- a TARGET_CLOSE_ERROR is thrown
- it's caught in remote_target::get_trace_status, but then
  rethrown because it's TARGET_CLOSE_ERROR
- catch_command_errors catches the error, at which point the quit command
  has been aborted.

The TARGET_CLOSE_ERROR is defined as:
...
  /* Target throwing an error has been closed.  Current command should be
     aborted as the inferior state is no longer valid.  */
  TARGET_CLOSE_ERROR,
...
so in a way this is expected behaviour.  But aborting quit because the inferior
state (which we've already confirmed we're not interested in) is no longer
valid, and having to type quit again seems pointless.

Furthermore, the purpose of not catching errors thrown by
query_if_trace_running as per commit 2f9d54cfce ("make -gdb-exit call
disconnect_tracing too, and don't lose history if the target errors on
"quit""), was to make sure that error (_("Not confirmed.") had effect.

Fix this in quit_command by catching only the TARGET_CLOSE_ERROR exception
during query_if_trace_running and reporting it:
...
(gdb) monitor exit
(gdb) quit
A debugging session is active.

        Inferior 1 [process 19219] will be killed.

Quit anyway? (y or n) y
Remote connection closed
$
...

Tested on x86_64-linux.

PR server/15746
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=15746
Approved-By: Tom Tromey <tom@tromey.com>
2022-11-08 18:47:24 +01:00
..
abspath.exp
attach-flag.c
attach-flag.exp
bkpt-other-inferior.exp gdb, solib-svr4: support namespaces in DSO iteration 2022-10-18 14:16:11 +02:00
connect-stopped-target.c
connect-stopped-target.exp
connect-with-no-symbol-file.c
connect-with-no-symbol-file.exp [gdb/testsuite] Use remote_exec chmod instead of remote_spawn 2022-10-27 16:53:12 +02:00
connect-without-multi-process.c
connect-without-multi-process.exp
exit-multiple-threads.c
exit-multiple-threads.exp
ext-attach.c
ext-attach.exp
ext-restart.exp
ext-run.exp
ext-wrapper.exp
extended-remote-restart.c
extended-remote-restart.exp
file-transfer.exp [gdb/testsuite] Fix gdb.server/file-transfer.exp with local-remote-host.exp 2022-10-18 15:32:46 +02:00
monitor-exit-quit.exp [gdb/cli] Make quit really quit after remote connection closed 2022-11-08 18:47:24 +01:00
multi-ui-errors.c
multi-ui-errors.exp [gdb/testsuite] Fix gdb.server/multi-ui-errors.exp with local-remote-host-notty 2022-10-29 09:43:32 +02:00
no-thread-db.c
no-thread-db.exp [gdb/testsuite] Fix gdb.server/no-thread-db.exp with local-remote-host.exp 2022-10-18 15:32:46 +02:00
non-existing-program.exp
normal.c
reconnect-ctrl-c.c
reconnect-ctrl-c.exp
run-without-local-binary.exp
server-connect.exp
server-exec-info.exp
server-kill-python.exp
server-kill.c
server-kill.exp
server-mon.exp
server-pipe.exp
server-run.exp
server.c
solib-list-lib.c
solib-list-main.c
solib-list.exp gdb/testsuite: remove unneeded calls to get_compiler_info 2022-06-24 15:07:29 +01:00
stop-reply-no-thread-multi.c
stop-reply-no-thread-multi.exp
stop-reply-no-thread.c
stop-reply-no-thread.exp
sysroot.c
sysroot.exp
transfer.txt
twice-connect.c [gdb] Fix heap-buffer-overflow in find_program_interpreter 2022-10-14 21:22:57 +02:00
twice-connect.exp [gdb] Fix heap-buffer-overflow in find_program_interpreter 2022-10-14 21:22:57 +02:00
unittest.exp [gdb/testsuite] Fix gdb.server/unittest.exp with host board local-remote-host.exp 2022-10-14 19:59:26 +02:00
wrapper.c
wrapper.exp