From: "Alex Bennée" <alex.bennee@linaro.org>
To: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Cc: npiggin@gmail.com, fbarrat@linux.ibm.com, qemu-devel@nongnu.org,
qemu-stable@nongnu.org, bcain@quicinc.com
Subject: Re: [PATCH] gdbstub: Fix client Ctrl-C handling
Date: Thu, 10 Aug 2023 11:05:07 +0100 [thread overview]
Message-ID: <87r0ob2owj.fsf@linaro.org> (raw)
In-Reply-To: <456ed3318421dd7946bdfb5ceda7e05332da368c.1690910333.git.quic_mathbern@quicinc.com>
Matheus Tavares Bernardino <quic_mathbern@quicinc.com> writes:
> Hi, Nick.
>
>> Nicholas Piggin <npiggin@gmail.com> wrote:
>>
>> On Tue Jul 11, 2023 at 9:03 PM AEST, Matheus Tavares Bernardino wrote:
>> > > Nicholas Piggin <npiggin@gmail.com> wrote:
>> > >
>> > > 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
>> >
>> > Makes sense to me, but shouldn't we send the stop-reply packet only for
>> > Ctrl+C/0x03?
>>
>> Good question.
>>
>> I think if we get a character here that's not a 3, we're already in
>> trouble, and we eat it so even worse. Since we only send a stop packet
>> back when the vm stops, then if we don't send one now we might never
>> send it. At least if we send one then the client might have some chance
>> to get back to a sane state.
>
> I just noticed now (as I was integrating the latest upstream patches
> with our downstream qemu-system-hexagon) that this causes the
> gdbstub-untimely-packet tcg test to fail.
>
> My first thought was that, if 0x3 is the only valid case where we will
> read a char when the cpu is running, perhaps not issuing the stop-reply
> isn't that bad as GDB would ignore it anyways. E.g. from a `set debug
> remote 1` output:
>
> Sending packet: $qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;
> fork-events+;vfork-events+;exec-events+;vContSupported+;
> QThreadEvents+;no-resumed+;
> xmlRegisters=i386#6a...
> Packet instead of Ack, ignoring it
>
> So, perhaps, we could do:
>
> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
> index f123b40ce7..8af066301a 100644
> --- a/gdbstub/gdbstub.c
> +++ b/gdbstub/gdbstub.c
> @@ -2055,8 +2055,9 @@ void gdb_read_byte(uint8_t ch)
> */
> if (ch != 0x03) {
> warn_report("gdbstub: client sent packet while target
> running\n");
This warning seems to be triggering either way, investigating now.
> + } else {
> + gdbserver_state.allow_stop_reply = true;
> }
> - gdbserver_state.allow_stop_reply = true;
> vm_stop(RUN_STATE_PAUSED);
> } else
> #endif
> -- >8 --
>
> Alternatively, since GDB ignores the packet anyways, should we just let
> this be and refactor/remove the test?
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2023-08-10 10:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2023-07-12 2:13 ` Nicholas Piggin
2023-07-12 10:39 ` Michael Tokarev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r0ob2owj.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=bcain@quicinc.com \
--cc=fbarrat@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=quic_mathbern@quicinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).