From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14160 invoked by alias); 9 Feb 2006 22:37:26 -0000 Received: (qmail 14151 invoked by uid 22791); 9 Feb 2006 22:37:25 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Thu, 09 Feb 2006 22:37:22 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1F7KPf-0001A1-V4; Thu, 09 Feb 2006 17:37:20 -0500 Date: Thu, 09 Feb 2006 22:37:00 -0000 From: Daniel Jacobowitz To: Mark Kettenis Cc: gdb-patches@sourceware.org Subject: Re: RFA: Support Windows extended error numbers in safe_strerror Message-ID: <20060209223719.GA3865@nevyn.them.org> Mail-Followup-To: Mark Kettenis , gdb-patches@sourceware.org References: <20060203215455.GA3501@nevyn.them.org> <20060206173550.GB22947@nevyn.them.org> <200602062254.k16MsagK009925@elgar.sibelius.xs4all.nl> <20060206225829.GA31895@nevyn.them.org> <20060208000855.GA5040@nevyn.them.org> <200602082107.k18L7xRh013417@elgar.sibelius.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200602082107.k18L7xRh013417@elgar.sibelius.xs4all.nl> User-Agent: Mutt/1.5.8i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-02/txt/msg00226.txt.bz2 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 * 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 + +/* 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. */