Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: [commit] Re: [PATCH] Avoid potencially-stale errno usage
Date: Tue, 09 Apr 2013 15:28:00 -0000	[thread overview]
Message-ID: <5164075E.8000607@redhat.com> (raw)
In-Reply-To: <20130408183434.GA32515@host2.jankratochvil.net>

On 04/08/2013 07:34 PM, Jan Kratochvil wrote:
> On Mon, 08 Apr 2013 19:57:22 +0200, Pedro Alves wrote:
>> @@ -7048,14 +7065,11 @@ readchar (int timeout)
>>    switch ((enum serial_rc) ch)
>>      {
>>      case SERIAL_EOF:
>> -      remote_unpush_target ();
>> -      throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
>> +      unpush_and_perror (_("Remote connection closed"));
> 
> I do not see why you have changed this part.  I have checked SERIAL_EOF is
> returned in cases where errno is not set (errno is unchanged).

Gah.  Is "patch sent in a hurry; wife and kid waiting in car" a good excuse?  :-P

> Otherwise it looks OK to me.

Thanks.  Committed.

---------------
Avoid potencially-stale errno usage.

The current throw_perror_with_name/TARGET_CLOSE_ERROR calls assume
errno is still set to the right error, although remote_unpush_target
is called in between, which may well change errno.

Tested on x86_64 Fedora 17 w/ gdbserver.

gdb/
2013-04-09  Pedro Alves  <palves@redhat.com>

	* remote.c (unpush_and_perror): New function.
	(readchar, remote_serial_write): Use it.
---
 gdb/remote.c |   29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 740324b..de075c8 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7033,6 +7033,23 @@ remote_files_info (struct target_ops *ignore)
 /* Stuff for dealing with the packets which are part of this protocol.
    See comment at top of file for details.  */
 
+/* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
+   error to higher layers.  Called when a serial error is detected.
+   The exception message is STRING, followed by a colon and a blank,
+   then the system error message for errno at function entry.  */
+
+static void
+unpush_and_perror (const char *string)
+{
+  char *errstr;
+
+  errstr = xstrprintf ("%s: %s", string, safe_strerror (errno));
+  make_cleanup (xfree, errstr);
+
+  remote_unpush_target ();
+  throw_error (TARGET_CLOSE_ERROR, "%s", errstr);
+}
+
 /* Read a single character from the remote end.  */
 
 static int
@@ -7052,10 +7069,8 @@ readchar (int timeout)
       throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
       /* no return */
     case SERIAL_ERROR:
-      remote_unpush_target ();
-      throw_perror_with_name (TARGET_CLOSE_ERROR,
-			      _("Remote communication error.  "
-				"Target disconnected."));
+      unpush_and_perror (_("Remote communication error.  "
+			   "Target disconnected."));
       /* no return */
     case SERIAL_TIMEOUT:
       break;
@@ -7071,10 +7086,8 @@ remote_serial_write (const char *str, int len)
 {
   if (serial_write (remote_desc, str, len))
     {
-      remote_unpush_target ();
-      throw_perror_with_name (TARGET_CLOSE_ERROR,
-			      _("Remote communication error.  "
-				"Target disconnected."));
+      unpush_and_perror (_("Remote communication error.  "
+			   "Target disconnected."));
     }
 }
 


  reply	other threads:[~2013-04-09 12:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAL8qUbrD=fgMP7nE0O8tX=AXifUpQXas25o_4SfK4p79rfoUpw@mail.gmail.com>
2013-03-14  2:02 ` Include putpkt in TRY_CATCH. PR gdb/51275 Gareth McMullin
2013-03-20 17:13   ` Jan Kratochvil
2013-03-21  1:15     ` Gareth McMullin
2013-03-21  8:20       ` Gareth McMullin
2013-03-26  7:27   ` Include putpkt in TRY_CATCH. PR gdb/15275 Jan Kratochvil
2013-03-27 20:17     ` [commit+7.6] " Jan Kratochvil
2013-03-28 20:14     ` Pedro Alves
2013-03-28 21:11       ` [PATCH] make -gdb-exit call disconnect_tracing too, and don't lose history if the target errors on "quit" (was: Re: Include putpkt in TRY_CATCH. PR gdb/15275) Pedro Alves
2013-04-10 19:57         ` [PATCH] make -gdb-exit call disconnect_tracing too, and don't lose history if the target errors on "quit" Pedro Alves
2013-03-29  0:44       ` Include putpkt in TRY_CATCH. PR gdb/15275 Gareth McMullin
2013-03-29 16:26       ` Jan Kratochvil
2013-04-02 15:24         ` Pedro Alves
2013-04-02 15:26           ` Jan Kratochvil
2013-04-09  7:15       ` [PATCH] Avoid potencially-stale errno usage (was: Re: Include putpkt in TRY_CATCH. PR gdb/15275) Pedro Alves
2013-04-09  8:21         ` Jan Kratochvil
2013-04-09 15:28           ` Pedro Alves [this message]
2013-04-11 12:53             ` [patch] Re: [commit] Re: [PATCH] Avoid potencially-stale errno usage Jan Kratochvil
2013-04-11 16:55               ` Pedro Alves
2013-04-11 22:59                 ` [commit] " Jan Kratochvil

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=5164075E.8000607@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@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