aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2022-11-08 18:47:24 +0100
committerTom de Vries <tdevries@suse.de>2022-11-08 18:47:24 +0100
commitbe6a2dca1505a4597fa3de71a85e7957d8d470ff (patch)
treee513776cc43f3b64403e13e5071aa4cb1aeacbda /gdb/cli
parent2939f92abde7b98ed58710ab2719c9750ea4acad (diff)
downloadgdb-be6a2dca1505a4597fa3de71a85e7957d8d470ff.zip
gdb-be6a2dca1505a4597fa3de71a85e7957d8d470ff.tar.gz
gdb-be6a2dca1505a4597fa3de71a85e7957d8d470ff.tar.bz2
[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 2f9d54cfcef ("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>
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-cmds.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index fe40416..bcfd364 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -488,7 +488,20 @@ quit_command (const char *args, int from_tty)
if (!quit_confirm ())
error (_("Not confirmed."));
- query_if_trace_running (from_tty);
+ try
+ {
+ query_if_trace_running (from_tty);
+ }
+ catch (const gdb_exception_error &ex)
+ {
+ if (ex.error == TARGET_CLOSE_ERROR)
+ /* We don't care about this since we're quitting anyway, so keep
+ quitting. */
+ exception_print (gdb_stderr, ex);
+ else
+ /* Rethrow, to properly handle error (_("Not confirmed.")). */
+ throw;
+ }
quit_force (args ? &exit_code : NULL, from_tty);
}