Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: gdb-patches@sourceware.org
Subject: Re: RFA: Support Windows extended error numbers in safe_strerror
Date: Thu, 09 Feb 2006 22:37:00 -0000	[thread overview]
Message-ID: <20060209223719.GA3865@nevyn.them.org> (raw)
In-Reply-To: <200602082107.k18L7xRh013417@elgar.sibelius.xs4all.nl>

On Wed, Feb 08, 2006 at 10:07:59PM +0100, Mark Kettenis wrote:
> My dislike for this stuff is probably there because where I've been
> cleaning out much of the host-specific quirks, this MinGW support
> seems to add back a lot special tweaks, and since Windows is so
> different from Unix-like systems, there's absolutely no hope, things
> can be unified.  That, together with the reintroduction of xm.h, seems
> like a giant leap backwards to me.  I really don't like that xm.h is
> back now, since it sets a precedent.  People have used these files for
> quick hacks in the past, and the new xm.h will make it harder to tell
> people that's not acceptable.  I think there is a better approach
> though.  How about having the implementation of safe_strerror() and
> gdb_select() in mingw-hdep.c and move the (trivial) existing
> implementations of these functions to a new posix-hdep.c?

I really dislike _this_ precedent: Don't allow the existance of xm.h
because people abused it in the past.  That's what review is for,
right?

Anyway, here's a patch updated in every way I can think of to make it
less upsetting.  Is this really better?  Select to follow in the proper
thread.

-- 
Daniel Jacobowitz
CodeSourcery

2006-02-06  Daniel Jacobowitz  <dan@codesourcery.com>

	* Makefile.in (mingw-hdep.o, posix-hdep.o): New dependencies.
	(ALLDEPFILES): Add mingw-hdep.c and posix-hdep.c.
	* configure.ac: Add gdb_host_obs to CONFIG_OBS.  Set gdb_host_obs
	to posix-hdep.o by default.
	* configure: Regenerated.
	* configure.host: Document gdb_host_obs.  Add an entry for
	i[34567]86-*-mingw32*.
	* mingw-hdep.c, posix-hdep.c: New files.
	* utils.c (safe_strerror): Remove, moved to posix-hdep.o.

Index: src/gdb/Makefile.in
===================================================================
--- src.orig/gdb/Makefile.in	2006-02-09 13:28:51.000000000 -0500
+++ src/gdb/Makefile.in	2006-02-09 16:50:17.000000000 -0500
@@ -1422,6 +1422,7 @@ ALLDEPFILES = \
 	m68kbsd-nat.c m68kbsd-tdep.c \
 	m68klinux-nat.c m68klinux-tdep.c \
 	m88k-tdep.c m88kbsd-nat.c \
+	mingw-hdep.c \
 	mips-linux-nat.c mips-linux-tdep.c \
 	mips-irix-tdep.c \
 	mips-tdep.c mipsv4-nat.c \
@@ -1430,6 +1431,7 @@ ALLDEPFILES = \
 	nbsd-tdep.c obsd-tdep.c \
 	solib-osf.c \
 	somread.c solib-som.c $(HPREAD_SOURCE) \
+	posix-hdep.c \
 	ppc-sysv-tdep.c ppc-linux-nat.c ppc-linux-tdep.c \
 	ppcnbsd-nat.c ppcnbsd-tdep.c \
 	ppcobsd-nat.c ppcobsd-tdep.c \
@@ -2280,6 +2282,7 @@ memattr.o: memattr.c $(defs_h) $(command
 	$(target_h) $(value_h) $(language_h) $(gdb_string_h)
 mem-break.o: mem-break.c $(defs_h) $(symtab_h) $(breakpoint_h) $(inferior_h) \
 	$(target_h)
+mingw-hdep.o: mingw-hdep.c $(defs_h) $(gdb_string_h)
 minsyms.o: minsyms.c $(defs_h) $(gdb_string_h) $(symtab_h) $(bfd_h) \
 	$(symfile_h) $(objfiles_h) $(demangle_h) $(value_h) $(cp_abi_h)
 mips64obsd-nat.o: mips64obsd-nat.c $(defs_h) $(inferior_h) $(regcache_h) \
@@ -2375,6 +2378,7 @@ p-exp.o: p-exp.c $(defs_h) $(gdb_string_
 p-lang.o: p-lang.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(expression_h) $(parser_defs_h) $(language_h) $(p_lang_h) \
 	$(valprint_h) $(value_h)
+posix-hdep.o: posix-hdep.c $(defs_h)
 ppc-bdm.o: ppc-bdm.c $(defs_h) $(gdbcore_h) $(gdb_string_h) $(frame_h) \
 	$(inferior_h) $(bfd_h) $(symfile_h) $(target_h) $(gdbcmd_h) \
 	$(objfiles_h) $(gdb_stabs_h) $(serial_h) $(ocd_h) $(ppc_tdep_h) \
Index: src/gdb/configure.ac
===================================================================
--- src.orig/gdb/configure.ac	2006-02-09 13:28:51.000000000 -0500
+++ src/gdb/configure.ac	2006-02-09 16:52:25.000000000 -0500
@@ -112,6 +112,10 @@ AC_DEFINE_DIR(DEBUGDIR, debugdir,
 
 AC_CONFIG_SUBDIRS(doc testsuite)
 
+# Provide defaults for some variables set by the per-host and per-target
+# configuration.
+gdb_host_obs=posix-hdep.o
+
 . $srcdir/configure.host
 
 . $srcdir/configure.tgt
@@ -1225,6 +1229,9 @@ case ${host} in
 esac	    
 AC_SUBST(WIN32LIBS)
 
+# Add any host-specific objects to GDB.
+CONFIG_OBS="${CONFIG_OBS} ${gdb_host_obs}"
+
 LIBGUI="../libgui/src/libgui.a"
 GUI_CFLAGS_X="-I${srcdir}/../libgui/src"
 AC_SUBST(LIBGUI)
Index: src/gdb/configure.host
===================================================================
--- src.orig/gdb/configure.host	2006-02-09 13:28:51.000000000 -0500
+++ src/gdb/configure.host	2006-02-09 16:52:12.000000000 -0500
@@ -7,6 +7,7 @@
 #  gdb_host_float_format	host's float floatformat, or 0
 #  gdb_host_double_format	host's double floatformat, or 0
 #  gdb_host_long_double_format	host's long double floatformat, or 0
+#  gdb_host_obs			host-specific .o files to include
 
 # Map host cpu into the config cpu subdirectory name.
 # The default is $host_cpu.
@@ -64,6 +65,9 @@ i[34567]86-*-netbsdelf* | i[34567]86-*-k
 			gdb_host=nbsdelf ;;
 i[34567]86-*-netbsd*)	gdb_host=nbsdaout ;;
 i[34567]86-*-go32*)	gdb_host=go32 ;;
+i[34567]86-*-mingw32*)	gdb_host=mingw
+			gdb_host_obs=mingw-hdep.o
+			;;
 i[34567]86-*-msdosdjgpp*) gdb_host=go32 ;;
 i[34567]86-*-linux*)	gdb_host=linux ;;
 i[34567]86-*-lynxos*)	gdb_host=i386lynx ;;
Index: src/gdb/mingw-hdep.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/mingw-hdep.c	2006-02-09 16:49:11.000000000 -0500
@@ -0,0 +1,71 @@
+/* Host support routines for MinGW, for GDB, the GNU debugger.
+
+   Copyright (C) 2006
+   Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
+
+#include "defs.h"
+
+#include "gdb_string.h"
+
+#include <windows.h>
+
+/* The strerror() function can return NULL for errno values that are
+   out of range.  Provide a "safe" version that always returns a
+   printable string.
+
+   The Windows runtime implementation of strerror never returns NULL,
+   but does return a useless string for anything above sys_nerr;
+   unfortunately this includes all socket-related error codes.
+   This replacement tries to find a system-provided error message.  */
+
+char *
+safe_strerror (int errnum)
+{
+  static char *buffer;
+  int len;
+
+  if (errnum >= 0 && errnum < sys_nerr)
+    return strerror (errnum);
+
+  if (buffer)
+    {
+      LocalFree (buffer);
+      buffer = NULL;
+    }
+
+  if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
+		     | FORMAT_MESSAGE_FROM_SYSTEM,
+		     NULL, errnum,
+		     MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+		     (LPTSTR) &buffer, 0, NULL) == 0)
+    {
+      static char buf[32];
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
+      return buf;
+    }
+
+  /* Windows error messages end with a period and a CR-LF; strip that
+     out.  */
+  len = strlen (buffer);
+  if (len > 3 && strcmp (buffer + len - 3, ".\r\n") == 0)
+    buffer[len - 3] = '\0';
+
+  return buffer;
+}
Index: src/gdb/posix-hdep.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/posix-hdep.c	2006-02-09 16:47:26.000000000 -0500
@@ -0,0 +1,43 @@
+/* Host support routines for MinGW, for GDB, the GNU debugger.
+
+   Copyright (C) 2006
+   Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
+
+#include "defs.h"
+
+/* The strerror() function can return NULL for errno values that are
+   out of range.  Provide a "safe" version that always returns a
+   printable string. */
+
+char *
+safe_strerror (int errnum)
+{
+  char *msg;
+
+  msg = strerror (errnum);
+  if (msg == NULL)
+    {
+      static char buf[32];
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
+      msg = buf;
+    }
+  return (msg);
+}
+
Index: src/gdb/utils.c
===================================================================
--- src.orig/gdb/utils.c	2006-02-07 11:11:34.000000000 -0500
+++ src/gdb/utils.c	2006-02-09 16:47:34.000000000 -0500
@@ -838,25 +838,6 @@ internal_warning (const char *file, int 
   va_end (ap);
 }
 
-/* The strerror() function can return NULL for errno values that are
-   out of range.  Provide a "safe" version that always returns a
-   printable string. */
-
-char *
-safe_strerror (int errnum)
-{
-  char *msg;
-
-  msg = strerror (errnum);
-  if (msg == NULL)
-    {
-      static char buf[32];
-      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
-      msg = buf;
-    }
-  return (msg);
-}
-
 /* Print the system error message for errno, and also mention STRING
    as the file name for which the error was encountered.
    Then return to command level.  */


  parent reply	other threads:[~2006-02-09 22:37 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-03 21:55 Daniel Jacobowitz
2006-02-03 23:25 ` Mark Kettenis
2006-02-03 23:39   ` Christopher Faylor
2006-02-04  3:27     ` Daniel Jacobowitz
2006-02-04  6:29       ` Jim Blandy
2006-02-04 10:33         ` Eli Zaretskii
2006-02-04 10:59       ` Eli Zaretskii
2006-02-04 14:35       ` Mark Kettenis
2006-02-04 14:52         ` Daniel Jacobowitz
2006-02-04 15:14         ` Eli Zaretskii
2006-02-05  0:15           ` Christopher Faylor
2006-02-05  4:46             ` Eli Zaretskii
2006-02-05 19:34               ` Christopher Faylor
2006-02-05 19:49                 ` Daniel Jacobowitz
2006-02-05 20:19                 ` Eli Zaretskii
2006-02-05 20:22                   ` Daniel Jacobowitz
2006-02-05 21:50                     ` Christopher Faylor
2006-02-05 21:57                       ` Daniel Jacobowitz
2006-02-05 22:33                         ` Christopher Faylor
2006-02-05 22:41                           ` Daniel Jacobowitz
2006-02-06  6:35                             ` Christopher Faylor
2006-02-06 17:26                               ` Daniel Jacobowitz
2006-02-05 22:59                           ` Eli Zaretskii
2006-02-05 22:47                         ` Eli Zaretskii
2006-02-06  2:41                           ` Daniel Jacobowitz
2006-02-06  4:20                             ` Eli Zaretskii
2006-02-05 22:57                       ` Eli Zaretskii
2006-02-05 22:44                   ` Christopher Faylor
2006-02-05 23:07                     ` Eli Zaretskii
2006-02-06  5:14                       ` Christopher Faylor
2006-02-06  7:20                         ` Eli Zaretskii
2006-02-06  8:47                           ` Corinna Vinschen
2006-02-06 12:07                             ` Bob Rossi
2006-02-06 14:23                               ` Daniel Jacobowitz
2006-02-06 18:37                                 ` Eli Zaretskii
2006-02-04 10:03     ` Eli Zaretskii
2006-02-05  0:27       ` Christopher Faylor
2006-02-05  2:01         ` Daniel Jacobowitz
2006-02-05  4:49           ` Eli Zaretskii
2006-02-05  7:39             ` Jim Blandy
2006-02-05 20:01               ` Eli Zaretskii
2006-02-05 20:20                 ` Daniel Jacobowitz
2006-02-05 22:45                   ` Eli Zaretskii
2006-02-06  2:38                     ` Daniel Jacobowitz
2006-02-05  4:48         ` Eli Zaretskii
2006-02-04  1:06   ` Jim Blandy
2006-02-04  3:00     ` Daniel Jacobowitz
2006-02-04  6:22       ` Ian Lance Taylor
2006-02-04 10:29         ` Eli Zaretskii
2006-02-04 13:53           ` Mark Kettenis
2006-02-04 15:17             ` Eli Zaretskii
2006-02-04 10:24       ` Eli Zaretskii
2006-02-04 15:33         ` Mark Kettenis
2006-02-04 15:35           ` Eli Zaretskii
2006-02-04 10:20     ` Eli Zaretskii
2006-02-04 13:14     ` Mark Kettenis
2006-02-05  7:41       ` Jim Blandy
2006-03-02  0:53   ` Michael Snyder
2006-02-04 11:58 ` Eli Zaretskii
2006-02-04 14:53   ` Daniel Jacobowitz
2006-02-04 15:09     ` Eli Zaretskii
2006-02-04 15:57       ` David Ayers
2006-02-06 17:35 ` Daniel Jacobowitz
2006-02-06 17:54   ` Christopher Faylor
2006-02-06 18:23   ` Jim Blandy
2006-02-06 19:08   ` Eli Zaretskii
2006-02-06 19:58     ` Daniel Jacobowitz
2006-02-06 20:59   ` Daniel Jacobowitz
2006-02-06 22:55   ` Mark Kettenis
2006-02-06 22:58     ` Daniel Jacobowitz
2006-02-08  0:08       ` Daniel Jacobowitz
2006-02-08 21:08         ` Mark Kettenis
2006-02-08 21:12           ` Bob Rossi
2006-02-08 23:17             ` Mark Kettenis
2006-02-08 23:23               ` Daniel Jacobowitz
2006-02-09  0:12               ` Joel Brobecker
2006-02-09  1:54                 ` Bob Rossi
2006-02-09  7:47                 ` Eli Zaretskii
2006-02-09  9:18                   ` Jim Blandy
2006-02-08 21:54           ` Eli Zaretskii
2006-02-08 23:10             ` Mark Kettenis
2006-02-08 23:22               ` Daniel Jacobowitz
2006-02-09 14:40                 ` Mark Kettenis
2006-02-09 15:14                   ` Daniel Jacobowitz
2006-02-09 20:24                   ` Eli Zaretskii
2006-02-09  8:00               ` Eli Zaretskii
2006-02-09 14:44                 ` Mark Kettenis
2006-02-09 14:57                   ` Daniel Jacobowitz
2006-02-09 20:40                     ` Eli Zaretskii
2006-02-09 21:06                       ` Daniel Jacobowitz
2006-02-09 22:13                         ` Eli Zaretskii
2006-02-09 20:26                   ` Eli Zaretskii
2006-02-09 22:37           ` Daniel Jacobowitz [this message]
2006-02-10  7:53             ` Eli Zaretskii
2006-02-10 16:18               ` Christopher Faylor
2006-02-10 16:49                 ` Daniel Jacobowitz
2006-02-10 18:18                 ` Eli Zaretskii
2006-02-10 21:56 ` Daniel Jacobowitz

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=20060209223719.GA3865@nevyn.them.org \
    --to=drow@false.org \
    --cc=gdb-patches@sourceware.org \
    --cc=mark.kettenis@xs4all.nl \
    /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