From: Luis Machado <lgustavo@codesourcery.com>
To: "'gdb-patches@sourceware.org'" <gdb-patches@sourceware.org>
Subject: [PATCH, remote] Handle 'k' packet errors gracefully
Date: Mon, 22 Apr 2013 19:03:00 -0000 [thread overview]
Message-ID: <517549FC.5070606@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 514 bytes --]
Hi,
This is not a real problem with gdbserver, but other types of remote
targets (other stubs, QEMU etc) may cut the connection abruptly since
they are not required to reply to a 'k' (Kill) packet sent from GDB.
The following patch addresses any issues arising from such scenario,
which leads to a GDB internal error due to an attempt to pop the target
more than once. With the patch, this failure is handled gracefully.
As the ChangeLog suggests, i'm sending this on behalf of its original
authors.
Luis
[-- Attachment #2: 0004-harden_kill.diff --]
[-- Type: text/x-patch, Size: 1832 bytes --]
2013-04-22 Pedro Alves <pedro@codesourcery.com>
Maciej W. Rozycki <macro@codesourcery.com>
gdb/
* remote.c (remote_kill): Handle errors from the kill packet
gracefully.
Index: gdb/remote.c
===================================================================
--- gdb.orig/remote.c 2013-04-22 14:13:25.512124202 +0200
+++ gdb/remote.c 2013-04-22 14:13:39.744123949 +0200
@@ -7714,12 +7714,36 @@ putpkt_for_catch_errors (void *arg)
static void
remote_kill (struct target_ops *ops)
{
- /* Use catch_errors so the user can quit from gdb even when we
+ struct gdb_exception ex;
+
+ /* Catch errors so the user can quit from gdb even when we
aren't on speaking terms with the remote system. */
- catch_errors (putpkt_for_catch_errors, "k", "", RETURN_MASK_ERROR);
+ TRY_CATCH (ex, RETURN_MASK_ERROR)
+ {
+ putpkt ("k");
+ }
+ if (ex.reason < 0)
+ {
+ if (remote_desc == NULL)
+ {
+ /* If we got an (EOF) error that caused the target
+ to go away, then we're done, that's what we wanted.
+ "k" is susceptible to cause a premature EOF, given
+ that the remote server isn't actually required to
+ reply to "k", and it can happen that it doesn't
+ even get to reply ACK to the "k". */
+ return;
+ }
+
+ /* Otherwise, something went wrong. We didn't actually kill
+ the target. Just propagate the exception, and let the
+ user or higher layers decide what to do. */
+ throw_exception (ex);
+ }
- /* Don't wait for it to die. I'm not really sure it matters whether
- we do or not. For the existing stubs, kill is a noop. */
+ /* We've killed the remote end, we get to mourn it. Since this is
+ target remote, single-process, mourning the inferior also
+ unpushes remote_ops. */
target_mourn_inferior ();
}
next reply other threads:[~2013-04-22 14:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-22 19:03 Luis Machado [this message]
2013-04-22 21:06 ` Pedro Alves
[not found] ` <alpine.DEB.1.10.1311301416410.21686@tp.orcam.me.uk>
2013-12-02 10:57 ` Pedro Alves
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=517549FC.5070606@codesourcery.com \
--to=lgustavo@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/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