This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] Re: [PATCH] Avoid potencially-stale errno usage
- From: Pedro Alves <palves at redhat dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 09 Apr 2013 13:19:42 +0100
- Subject: [commit] Re: [PATCH] Avoid potencially-stale errno usage
- References: <CAL8qUbrD=fgMP7nE0O8tX=AXifUpQXas25o_4SfK4p79rfoUpw at mail dot gmail dot com> <CAL8qUbqjtBKJFJZ6dPS78Zh8Eb3b33U9JXTmn1pS3Le93xt7Rw at mail dot gmail dot com> <20130325195832 dot GA15218 at host2 dot jankratochvil dot net> <515478BE dot 3030801 at redhat dot com> <51630502 dot 3050109 at redhat dot com> <20130408183434 dot GA32515 at host2 dot jankratochvil dot 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."));
}
}