This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFA: Support Windows extended error numbers in safe_strerror
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sourceware dot org
- Date: Mon, 6 Feb 2006 12:35:50 -0500
- Subject: Re: RFA: Support Windows extended error numbers in safe_strerror
- References: <20060203215455.GA3501@nevyn.them.org>
On Fri, Feb 03, 2006 at 04:54:55PM -0500, Daniel Jacobowitz wrote:
> This is an improved version of a patch Mark Mitchell submitted last
> year. If you give strerror() anything above 42 (sys_nerr) on Windows,
> it gives you back "Unknown error" - particularly unfortunate since
> WSAECONNREFUSED is way above there, so connecting to a closed socket
> will give you a generic error message. This patch lets us try an
> OS-specific interface to fetch an error string.
>
> [Actually you need my next patch too to get the connection refused message;
> right now you'll get a timeout.]
>
> Any comments on this patch?
There were plenty :-) Is this better?
We had finally eliminated the XM files in favor of autoconf checks.
This patch re-adds an xm-*.h header file, but I think it's still
the best of our options. We can restrict our use of these headers
to things where autoconf is a bad fit - like right here.
Rather than creating a .mh file and setting XM_FILE there, I added
this and an equivalent to TDEPFILES to configure.host. This is in
line with discussion I vaguely remember from last year that the
makefile fragments were not a preferable solution for this sort
of thing. I do agree that it looks more elegant this way.
--
Daniel Jacobowitz
CodeSourcery
2006-02-06 Daniel Jacobowitz <dan@codesourcery.com>
* Makefile.in (mingw-hdep.o): New dependencies.
* configure.ac: Add gdb_host_obs to CONFIG_OBS. Don't fetch hostfile
from host_makefile_frag. Remove obsolete comment. Rename hostfile
to gdb_hostfile.
* configure: Regenerated.
* configure.host: Document gdb_host_obs and gdb_hostfile. Add
an entry for i[34567]86-*-mingw32*.
* mingw-hdep.c, config/i386/xm-mingw.h: New files.
Index: src/gdb/Makefile.in
===================================================================
--- src.orig/gdb/Makefile.in 2006-02-06 10:58:30.000000000 -0500
+++ src/gdb/Makefile.in 2006-02-06 12:27:15.000000000 -0500
@@ -2280,6 +2280,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) \
Index: src/gdb/configure.ac
===================================================================
--- src.orig/gdb/configure.ac 2006-02-06 10:58:30.000000000 -0500
+++ src/gdb/configure.ac 2006-02-06 12:06:48.000000000 -0500
@@ -1225,6 +1225,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)
@@ -1443,10 +1446,6 @@ AC_SUBST_FILE(target_makefile_frag)
AC_SUBST(frags)
changequote(,)dnl
-hostfile=`sed -n '
-s/XM_FILE[ ]*=[ ]*\([^ ]*\)/\1/p
-' ${host_makefile_frag}`
-
targetfile=`sed -n '
s/DEPRECATED_TM_FILE[ ]*=[ ]*\([^ ]*\)/\1/p
' ${target_makefile_frag}`
@@ -1494,20 +1493,16 @@ if test "x$build_nlm" = xyes; then
AC_CONFIG_SUBDIRS(nlm)
fi
-# If hostfile (XM_FILE) and/or targetfile (DEPRECATED_TM_FILE) and/or
-# nativefile (NAT_FILE) is not set in config/*/*.m[ht] files, we link
-# to an empty version.
-
files=
links=
rm -f xm.h
xm_h=""
-if test "${hostfile}" != ""; then
+if test "${gdb_hostfile}" != ""; then
xm_h=xm.h
- case "${hostfile}" in
- xm-*.h ) GDB_XM_FILE="config/${gdb_host_cpu}/${hostfile}" ;;
- * ) GDB_XM_FILE="${hostfile}"
+ case "${gdb_hostfile}" in
+ xm-*.h ) GDB_XM_FILE="config/${gdb_host_cpu}/${gdb_hostfile}" ;;
+ * ) GDB_XM_FILE="${gdb_hostfile}"
esac
files="${files} ${GDB_XM_FILE}"
links="${links} xm.h"
Index: src/gdb/configure.host
===================================================================
--- src.orig/gdb/configure.host 2005-05-22 15:11:42.000000000 -0400
+++ src/gdb/configure.host 2006-02-06 12:29:41.000000000 -0500
@@ -7,6 +7,8 @@
# 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
+# gdb_hostfile host-specific .h file to include
# Map host cpu into the config cpu subdirectory name.
# The default is $host_cpu.
@@ -64,6 +66,10 @@ 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
+ gdb_hostfile=xm-mingw.h
+ ;;
i[34567]86-*-msdosdjgpp*) gdb_host=go32 ;;
i[34567]86-*-linux*) gdb_host=linux ;;
i[34567]86-*-lynxos*) gdb_host=i386lynx ;;
Index: src/gdb/config/i386/xm-mingw.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/config/i386/xm-mingw.h 2006-02-06 12:28:38.000000000 -0500
@@ -0,0 +1,26 @@
+/* Host support for i386 running under MinGW.
+
+ 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., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* The standard strerror is too unfriendly in some cases; we provide our
+ own. */
+char *mingw_strerror (int);
+#define strerror mingw_strerror
Index: src/gdb/mingw-hdep.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ src/gdb/mingw-hdep.c 2006-02-06 12:29:23.000000000 -0500
@@ -0,0 +1,62 @@
+/* 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 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 *
+mingw_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)
+ return NULL;
+
+ /* Windows error messages end with a period and a CR-LF; strip them
+ out. */
+ len = strlen (buffer);
+ if (len > 3 && strcmp (buffer + len - 3, ".\r\n") == 0)
+ buffer[len - 3] = '\0';
+
+ return buffer;
+}