public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Pedro Alves <palves@redhat.com>
Cc: Yao Qi <qiyaoltc@gmail.com>,  gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] [GDBserver] Check input interrupt after reading in a packet
Date: Tue, 26 Jan 2016 13:53:00 -0000	[thread overview]
Message-ID: <86h9i0qwfu.fsf@gmail.com> (raw)
In-Reply-To: <56A75BA7.6070602@redhat.com> (Pedro Alves's message of "Tue, 26	Jan 2016 11:42:31 +0000")

Pedro Alves <palves@redhat.com> writes:

> I think we should expand the explanation, like:
>
>   /* The readchar above may have already read a '\003' out of the socket and
>    moved it to the local buffer.  For example, when GDB sends vCont;c immediately
>    followed by interrupt (see gdb.base/interrupt-noterm.exp).  As soon as we see
>    the vCont;c, we'll resume the inferior and wait.  Since we've already moved
>    the '\003' to the local buffer, SIGIO won't help.  In that case, if we don't
>    check for interrupt after the vCont;c packet, the interrupt character would
>    stay in the buffer unattended until after the next (unrelated) stop.  */
>

Take it into the patch.

>> +  if (readchar_bufcnt > 0 && *readchar_bufp == '\003')
>
> This should be a "while" instead of a single "if".
>

Fixed.

>> +    {
>> +      /* Consume the interrupt character in the buffer.  */
>> +      readchar ();
>> +      (*the_target->request_interrupt) ();
>> +    }
>> +
>>    return bp - buf;
>>  }
>
> Otherwise LGTM.

Patch below is pushed in.

-- 
Yao (齐尧)
From 18879fef1741464e522624bcc529048400453e0d Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Tue, 26 Jan 2016 13:50:22 +0000
Subject: [PATCH] [GDBserver] Check input interrupt after reading in a packet

GDBserver may read some packet together with '\003' in one go.  We've
already checked '\003' first when reading packet by my patch,

  Check input interrupt first when reading packet
  https://sourceware.org/ml/gdb-patches/2016-01/msg00057.html

but if we don't check '\003' *after* each packet, the interrupt will
be processed next time GDBserver reads from the buffer, so that the
interrupt isn't processed in time.  For example, GDB sends vCont;c and
interrupt (see gdb.base/interrupt-noterm.exp), we'll resume the
inferior and wait once packet vCont;c is seen.  If we don't check the
interrupt character after vCont;c packet, interrupt character will stay
in the buffer unattended until GDBserver returns from the wait, which
may take a while.  Note that since we've read '\003' from file
descriptor, SIGIO signal handler input_interrupt doesn't help either.

This issue can be exposed by hacking the end of getpkt like
@@ -1041,6 +1050,9 @@ getpkt (char *buf)
        }
     }

+  if (readchar_bufcnt > 0)
+    gdb_assert (*readchar_bufp != '\003');
+
   return bp - buf;
 }

and this can trigger internal error,
(gdb) PASS: gdb.base/interrupt-noterm.exp: interrupt
Remote connection closed^M
(gdb) FAIL: gdb.base/interrupt-noterm.exp: inferior received SIGINT
Remote debugging from host 10.2.206.40^M
/home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/remote-utils.c:1054: A problem internal to GDBserver has been detected.^M
getpkt: Assertion `*readchar_bufp != '\003'' failed.^M

This patch is to peek the buffer, if it is '\003', consume it and call
*the_target->request_interrupt.

gdb/gdbserver:

2016-01-26  Yao Qi  <yao.qi@linaro.org>

	* remote-utils.c (getpkt): If the buffer isn't empty, and the
	first character is '\003', call *the_target->request_interrupt.

diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 2e94aa8..4aa7350 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,8 @@
+2016-01-26  Yao Qi  <yao.qi@linaro.org>
+
+	* remote-utils.c (getpkt): If the buffer isn't empty, and the
+	first character is '\003', call *the_target->request_interrupt.
+
 2016-01-25  Yao Qi  <yao.qi@linaro.org>
 
 	* remote-utils.c (new_thread_notify): Remove.
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index 292197a..ccc99f1 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -1041,6 +1041,22 @@ getpkt (char *buf)
 	}
     }
 
+  /* The readchar above may have already read a '\003' out of the socket
+     and moved it to the local buffer.  For example, when GDB sends
+     vCont;c immediately followed by interrupt (see
+     gdb.base/interrupt-noterm.exp).  As soon as we see the vCont;c, we'll
+     resume the inferior and wait.  Since we've already moved the '\003'
+     to the local buffer, SIGIO won't help.  In that case, if we don't
+     check for interrupt after the vCont;c packet, the interrupt character
+     would stay in the buffer unattended until after the next (unrelated)
+     stop.  */
+  while (readchar_bufcnt > 0 && *readchar_bufp == '\003')
+    {
+      /* Consume the interrupt character in the buffer.  */
+      readchar ();
+      (*the_target->request_interrupt) ();
+    }
+
   return bp - buf;
 }
 

      reply	other threads:[~2016-01-26 13:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-22 16:29 [PATCH] Fix fail in gdb.base/interrupt-noterm.exp Yao Qi
2016-01-22 16:47 ` Pedro Alves
2016-01-22 17:14   ` Yao Qi
2016-01-22 17:35     ` Pedro Alves
2016-01-22 18:30       ` Pedro Alves
2016-01-25  9:30       ` Yao Qi
2016-01-25 10:43         ` Pedro Alves
2016-01-26  9:59         ` [PATCH 0/2 V2] Fix a " Yao Qi
2016-01-26  9:59           ` [PATCH 2/2] [GDBserver] Block and unblock SIGIO Yao Qi
2016-01-26 12:01             ` Pedro Alves
2016-01-26 13:55               ` Yao Qi
2016-01-26  9:59           ` [PATCH 1/2] [GDBserver] Check input interrupt after reading in a packet Yao Qi
2016-01-26 11:42             ` Pedro Alves
2016-01-26 13:53               ` Yao Qi [this message]

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=86h9i0qwfu.fsf@gmail.com \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.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 read-only IMAP folder(s) and NNTP newsgroup(s).