Move safe_strerror to common/
authorSergio Durigan Junior <sergiodj@redhat.com>
Thu, 15 Jan 2015 20:09:15 +0000 (15:09 -0500)
committerSergio Durigan Junior <sergiodj@redhat.com>
Thu, 15 Jan 2015 20:09:15 +0000 (15:09 -0500)
This patch moves safe_strerror from the gdb/{posix,mingw}-hdep.c files
to the respective common/{posix,mingw}-strerror.c files.  This is a
preparation for the next patch, which shares a common code (to disable
address space randomization when creating a new inferior).

The patch has been regtested on Fedora 20 x86_64, and no regressions
were found.

gdb/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

* Makefile.in (ALLDEPFILES): Including common/mingw-strerror.c and
common/posix-strerror.c.
(posix-strerror.o): New rule.
(mingw-strerror.o): Likewise.
* common/common-utils.h (safe_strerror): Move prototype to here,
from utils.h.
* common/common.host: New file.
* common/mingw-strerror.c: Likewise.
* common/posix-strerror.c: Likewise.
* configure: Regenerated.
* configure.ac: Source common/common.host.  Add variable
common_host_obs to gdb_host_obs.
* contrib/ari/gdb_ari.sh: Mention gdb/common/mingw-strerror.c and
gdb/common/posix-strerror.c when warning about the use of
strerror.
* mingw-hdep.c (safe_strerror): Remove definition; move it to
common/mingw-strerror.c.
* posix-hdep.c (safe_strerror): Remove definition; move it to
common/posix-hdep.c.
* utils.h (safe_strerror): Remove prototype; move to
common/common-utils.h.

gdb/gdbserver/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

* Makefile.in (posix-strerror.o): New rule.
(mingw-strerror.o): Likewise.
* configure: Regenerated.
* configure.ac: Source file ../common/common.host.  Initialize new
variable srv_host_obs.  Add srv_host_obs to GDBSERVER_DEPFILES.

16 files changed:
gdb/ChangeLog
gdb/Makefile.in
gdb/common/common-utils.h
gdb/common/common.host [new file with mode: 0644]
gdb/common/mingw-strerror.c [new file with mode: 0644]
gdb/common/posix-strerror.c [new file with mode: 0644]
gdb/configure
gdb/configure.ac
gdb/contrib/ari/gdb_ari.sh
gdb/gdbserver/ChangeLog
gdb/gdbserver/Makefile.in
gdb/gdbserver/configure
gdb/gdbserver/configure.ac
gdb/mingw-hdep.c
gdb/posix-hdep.c
gdb/utils.h

index 5c45780d37a39a16e745957180ee0f090fd75340..985097aec44b0142abbeb44780f11816fc2282ae 100644 (file)
@@ -1,3 +1,27 @@
+2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       * Makefile.in (ALLDEPFILES): Including common/mingw-strerror.c and
+       common/posix-strerror.c.
+       (posix-strerror.o): New rule.
+       (mingw-strerror.o): Likewise.
+       * common/common-utils.h (safe_strerror): Move prototype to here,
+       from utils.h.
+       * common/common.host: New file.
+       * common/mingw-strerror.c: Likewise.
+       * common/posix-strerror.c: Likewise.
+       * configure: Regenerated.
+       * configure.ac: Source common/common.host.  Add variable
+       common_host_obs to gdb_host_obs.
+       * contrib/ari/gdb_ari.sh: Mention gdb/common/mingw-strerror.c and
+       gdb/common/posix-strerror.c when warning about the use of
+       strerror.
+       * mingw-hdep.c (safe_strerror): Remove definition; move it to
+       common/mingw-strerror.c.
+       * posix-hdep.c (safe_strerror): Remove definition; move it to
+       common/posix-hdep.c.
+       * utils.h (safe_strerror): Remove prototype; move to
+       common/common-utils.h.
+
 2015-01-15  Joel Brobecker  <brobecker@adacore.com>
 
        GDB 7.8.2 released.
index f9701765ef0352c605c00a332be01dfc3d9a0c8d..57ed361f3ebcbdc055a493c87225d7cd6eaa0384 100644 (file)
@@ -1680,7 +1680,7 @@ ALLDEPFILES = \
        m68klinux-nat.c m68klinux-tdep.c \
        m88k-tdep.c m88kbsd-nat.c \
        microblaze-tdep.c microblaze-linux-tdep.c \
-       mingw-hdep.c \
+       mingw-hdep.c common/mingw-strerror.c \
        mips-linux-nat.c mips-linux-tdep.c \
        mips-sde-tdep.c \
        mips-tdep.c \
@@ -1690,7 +1690,7 @@ ALLDEPFILES = \
        nios2-tdep.c nios2-linux-tdep.c \
        nbsd-nat.c nbsd-tdep.c obsd-nat.c obsd-tdep.c \
        somread.c solib-som.c \
-       posix-hdep.c \
+       posix-hdep.c common/posix-strerror.c \
        ppc-sysv-tdep.c ppc-linux-nat.c ppc-linux-tdep.c ppc64-tdep.c \
        ppcfbsd-nat.c ppcfbsd-tdep.c \
        ppcnbsd-nat.c ppcnbsd-tdep.c \
@@ -2227,6 +2227,14 @@ common-exceptions.o: ${srcdir}/common/common-exceptions.c
        $(COMPILE) $(srcdir)/common/common-exceptions.c
        $(POSTCOMPILE)
 
+posix-strerror.o: ${srcdir}/common/posix-strerror.c
+       $(COMPILE) $(srcdir)/common/posix-strerror.c
+       $(POSTCOMPILE)
+
+mingw-strerror.o: ${srcdir}/common/mingw-strerror.c
+       $(COMPILE) $(srcdir)/common/mingw-strerror.c
+       $(POSTCOMPILE)
+
 #
 # gdb/target/ dependencies
 #
index f110924fa0c5173fbb189b6a7bf5b012dc59c501..60aa030a0f7cfa7d9e5bb8f554fefb24769cf28d 100644 (file)
@@ -62,4 +62,10 @@ int xsnprintf (char *str, size_t size, const char *format, ...)
 
 char *savestring (const char *ptr, size_t len);
 
+/* The strerror() function can return NULL for errno values that are
+   out of range.  Provide a "safe" version that always returns a
+   printable string.  */
+
+extern char *safe_strerror (int);
+
 #endif
diff --git a/gdb/common/common.host b/gdb/common/common.host
new file mode 100644 (file)
index 0000000..8a83882
--- /dev/null
@@ -0,0 +1,36 @@
+# Common object files to include for each host.
+#
+# Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>.
+
+# Map host triplet into the common object files to be included by
+# GDB/gdbserver.  This is invoked from the autoconf generated
+# configure script.
+
+# This file sets the following shell variables:
+#  common_host_obs             host-specific .o files to include when building
+#                              GDB/gdbserver
+
+case "${host}" in
+
+*-mingw*)      common_host_obs=mingw-strerror.o
+               ;;
+*)
+               common_host_obs=posix-strerror.o
+               ;;
+
+esac
diff --git a/gdb/common/mingw-strerror.c b/gdb/common/mingw-strerror.c
new file mode 100644 (file)
index 0000000..c62c42d
--- /dev/null
@@ -0,0 +1,64 @@
+/* Safe version of strerror for MinGW, for GDB, the GNU debugger.
+
+   Copyright (C) 2006-2015 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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+
+#include <windows.h>
+
+/* Implementation of safe_strerror as defined in common-utils.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 *
+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;
+}
diff --git a/gdb/common/posix-strerror.c b/gdb/common/posix-strerror.c
new file mode 100644 (file)
index 0000000..119fcf6
--- /dev/null
@@ -0,0 +1,38 @@
+/* Safe version of strerror for POSIX systems for GDB, the GNU debugger.
+
+   Copyright (C) 2006-2015 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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+
+/* Implementation of safe_strerror as defined in common-utils.h.  */
+
+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 fdcf215253c78583d72ad686a797101a2272b1ff..f62d5a08c8aead2aa25f01c1c2e433388e794f4a 100755 (executable)
@@ -5308,6 +5308,10 @@ fi
 
 . $srcdir/configure.host
 
+# Add in the common host objects.
+. $srcdir/common/common.host
+gdb_host_obs="$gdb_host_obs $common_host_obs"
+
 # Accumulate some settings from configure.tgt over all enabled targets
 
 TARGET_OBS=
index cc181745bc8b921088a9429c59da7ecb8648a22b..8dd7f8fcc1b5a8d43c4fe0d454ecc70f1480e43d 100644 (file)
@@ -205,6 +205,10 @@ fi
 
 . $srcdir/configure.host
 
+# Add in the common host objects.
+. $srcdir/common/common.host
+gdb_host_obs="$gdb_host_obs $common_host_obs"
+
 # Accumulate some settings from configure.tgt over all enabled targets
 
 TARGET_OBS=
index 8a8cec848463cd5ac987f87f8de4740d6c70b36e..b868a17e175950196c6f30ab3aafc1f352ff74dc 100644 (file)
@@ -603,8 +603,8 @@ BEGIN { doc["strerror"] = "\
 Do not use strerror(), instead use safe_strerror()"
     category["strerror"] = ari_regression
     fix("strerror", "gdb/gdb_string.h", 1)
-    fix("strerror", "gdb/mingw-hdep.c", 1)
-    fix("strerror", "gdb/posix-hdep.c", 1)
+    fix("strerror", "gdb/common/mingw-strerror.c", 1)
+    fix("strerror", "gdb/common/posix-strerror.c", 1)
 }
 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
     fail("strerror")
index f762dafd412d8af0d909baa45a7e994b8d4bf2b3..c2d8e5672b4f7e6e5a7c899b918099cbda14ab37 100644 (file)
@@ -1,3 +1,11 @@
+2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       * Makefile.in (posix-strerror.o): New rule.
+       (mingw-strerror.o): Likewise.
+       * configure: Regenerated.
+       * configure.ac: Source file ../common/common.host.  Initialize new
+       variable srv_host_obs.  Add srv_host_obs to GDBSERVER_DEPFILES.
+
 2015-01-14  Yao Qi  <yao@codesourcery.com>
 
        * Makefile.in (SFILES): Add nat/ppc-linux.c.
index 0e442fcd973fb2f73bdd2d18516a43520f065a3b..8406ff4db5fed22f7db285a58f77af62c3d97b54 100644 (file)
@@ -518,6 +518,12 @@ rsp-low.o: ../common/rsp-low.c
 common-utils.o: ../common/common-utils.c
        $(COMPILE) $<
        $(POSTCOMPILE)
+posix-strerror.o: ../common/posix-strerror.c
+       $(COMPILE) $<
+       $(POSTCOMPILE)
+mingw-strerror.o: ../common/mingw-strerror.c
+       $(COMPILE) $<
+       $(POSTCOMPILE)
 vec.o: ../common/vec.c
        $(COMPILE) $<
        $(POSTCOMPILE)
index 55bd2c5b83c241eb67f54d88c190f79cdd6295ac..2240b7871b77bd645b5464f65667a39053a7eb4b 100755 (executable)
@@ -5539,6 +5539,10 @@ esac
 
 . ${srcdir}/configure.srv
 
+# Add in the common host objects.
+. ${srcdir}/../common/common.host
+srv_host_obs="$common_host_obs"
+
 if test "${srv_mingwce}" = "yes"; then
   LIBS="$LIBS -lws2"
 elif test "${srv_mingw}" = "yes"; then
@@ -6034,7 +6038,7 @@ $as_echo "#define USE_XML 1" >>confdefs.h
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
 GDBSERVER_LIBS="$srv_libs"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target supports __sync_*_compare_and_swap" >&5
index 39e3a06764d3ab2ea4ed4d5962f5bdc0bfd82aaa..f883adc82ad6a816dd4894dfe7dce13e633b2bf3 100644 (file)
@@ -242,6 +242,10 @@ esac
 
 . ${srcdir}/configure.srv
 
+# Add in the common host objects.
+. ${srcdir}/../common/common.host
+srv_host_obs="$common_host_obs"
+
 if test "${srv_mingwce}" = "yes"; then
   LIBS="$LIBS -lws2"
 elif test "${srv_mingw}" = "yes"; then
@@ -385,7 +389,7 @@ if test "$srv_xmlfiles" != ""; then
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
 GDBSERVER_LIBS="$srv_libs"
 
 dnl Check whether the target supports __sync_*_compare_and_swap.
index c0cc385612f9f53b82a82724d3f607de67cb67ea..a0ed2816e2af3108269ca5a5abe3177590146274 100644 (file)
@@ -35,50 +35,6 @@ static HANDLE sigint_event;
    function.  */
 struct async_signal_handler *sigint_handler;
 
-/* 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;
-}
-
 /* Return an absolute file name of the running GDB, if possible, or
    ARGV0 if not.  The return value is in malloc'ed storage.  */
 
index 13cddbac55b5baaafb99e8eeaa48b7ea5ce0b725..fef5ec1ae872bbc5e032b1e2da93bb09c7a809c5 100644 (file)
 
 #include "gdb_select.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);
-}
-
 /* Wrapper for select.  Nothing special needed on POSIX platforms.  */
 
 int
index 3debde733cd180bc48d501c86d99dec5c4554e4a..e58260c6c57cb10efd6125b41563ffa948cf5e99 100644 (file)
@@ -42,9 +42,6 @@ ULONGEST strtoulst (const char *num, const char **trailer, int base);
 int compare_positive_ints (const void *ap, const void *bp);
 int compare_strings (const void *ap, const void *bp);
 
-/* This is defined in *-hdep.c, e.g., posix-hdep.c.  */
-extern char *safe_strerror (int);
-
 /* A wrapper for bfd_errmsg to produce a more helpful error message
    in the case of bfd_error_file_ambiguously recognized.
    MATCHING, if non-NULL, is the corresponding argument to
This page took 0.055979 seconds and 4 git commands to generate.