qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gdbstub: Fix client Ctrl-C handling
@ 2023-07-11  8:59 Nicholas Piggin
  2023-07-11 11:03 ` Matheus Tavares Bernardino
  2023-07-12  2:13 ` Nicholas Piggin
  0 siblings, 2 replies; 13+ messages in thread
From: Nicholas Piggin @ 2023-07-11  8:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: Nicholas Piggin, qemu-stable, Matheus Tavares Bernardino,
	Alex Bennée, Taylor Simpson, Frederic Barrat

The gdb remote protocol has a special interrupt character (0x03) that is
transmitted outside the regular packet processing, and represents a
Ctrl-C pressed in the client. Despite not being a regular packet, it
does expect a regular stop response if the stub successfully stops the
running program.

See: https://sourceware.org/gdb/onlinedocs/gdb/Interrupts.html

Inhibiting the stop reply packet can lead to gdb client hang. So permit
a stop response when receiving a character from gdb that stops the vm.
Additionally, add a warning if that was not a 0x03 character, because
the gdb session is likely to end up getting confused if this happens.

Cc: qemu-stable@nongnu.org
Cc: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Taylor Simpson <tsimpson@quicinc.com>
Reported-by: Frederic Barrat <fbarrat@linux.ibm.com>
Fixes: 758370052fb ("gdbstub: only send stop-reply packets when allowed to")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
Hey Fred, I'm not sure if this is the gdb hang you were seeing, but it
is the one I could reproduce. Could be worth checking there are no more
corner case hangs after this.

Thanks,
Nick

 gdbstub/gdbstub.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 6911b73c07..ce8b42eb15 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -2051,8 +2051,17 @@ void gdb_read_byte(uint8_t ch)
             return;
     }
     if (runstate_is_running()) {
-        /* when the CPU is running, we cannot do anything except stop
-           it when receiving a char */
+        /*
+         * When the CPU is running, we cannot do anything except stop
+         * it when receiving a char. This is expected on a Ctrl-C in the
+         * gdb client. Because we are in all-stop mode, gdb sends a
+         * 0x03 byte which is not a usual packet, so we handle it specially
+         * here, but it does expect a stop reply.
+         */
+        if (ch != 0x03) {
+            warn_report("gdbstub: client sent packet while target running\n");
+        }
+        gdbserver_state.allow_stop_reply = true;
         vm_stop(RUN_STATE_PAUSED);
     } else
 #endif
-- 
2.40.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-08-10 10:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-11  8:59 [PATCH] gdbstub: Fix client Ctrl-C handling Nicholas Piggin
2023-07-11 11:03 ` Matheus Tavares Bernardino
2023-07-12  2:11   ` Nicholas Piggin
2023-07-26  6:35     ` Joel Stanley
2023-07-30  9:43       ` Nicholas Piggin
2023-07-31  6:58         ` Joel Stanley
2023-07-31 13:59           ` Peter Maydell
2023-08-01 20:05             ` Philippe Mathieu-Daudé
2023-08-01 18:40     ` Matheus Tavares Bernardino
2023-08-08 22:56       ` Richard Henderson
2023-08-10 10:05       ` Alex Bennée
2023-07-12  2:13 ` Nicholas Piggin
2023-07-12 10:39   ` Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).