]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* hostio.c: Don't include errno.h.
authorPedro Alves <palves@redhat.com>
Fri, 1 Feb 2008 00:08:25 +0000 (00:08 +0000)
committerPedro Alves <palves@redhat.com>
Fri, 1 Feb 2008 00:08:25 +0000 (00:08 +0000)
(errno_to_fileio_errno): Move to hostio-errno.
* hostio.c: (hostio_error): Remove the error parameter.  Defer the
error number outputting to the target->hostio_last_error callback.
(hostio_packet_error): Use FILEIO_EINVAL directly.
(handle_open, handle_pread, hostio_error, handle_unlink): Update
calls to hostio_error.
* hostio-errno.c: New.
* server.h (hostio_last_error_from_errno): Declare.
* target.h (target_ops): Add hostio_last_error member.
* linux-low.c (linux_target_op): Register hostio_last_error_from_errno
as hostio_last_error handler.
* spu-low.c (spu_target_ops): Likewise.
* win32-low.c [_WIN32_WCE] (win32_error_to_fileio_error)
(wince_hostio_last_error): New functions.
(win32_target_ops) [_WIN32_WCE]: Register wince_hostio_last_error
as hostio_last_error handler.
(win32_target_ops) [!_WIN32_WCE]: Register
hostio_last_error_from_errno as hostio_last_error handler.
* Makefile.in (SFILES): Add hostio.c and hostio-errno.c.
(hostio-errno.o): New rule.
* configure.ac (GDBSERVER_DEPFILES): Add $srv_hostio_err_objs.
* configure.srv (srv_hostio_err_objs): New variable.  Default to
hostio-errno.o.
(arm*-*-mingw32ce*): Set srv_hostio_err_objs to "".
* configure: Regenerate.

12 files changed:
gdb/gdbserver/ChangeLog
gdb/gdbserver/Makefile.in
gdb/gdbserver/configure
gdb/gdbserver/configure.ac
gdb/gdbserver/configure.srv
gdb/gdbserver/hostio-errno.c [new file with mode: 0644]
gdb/gdbserver/hostio.c
gdb/gdbserver/linux-low.c
gdb/gdbserver/server.h
gdb/gdbserver/spu-low.c
gdb/gdbserver/target.h
gdb/gdbserver/win32-low.c

index 5a6e7b9e920058135f0c7394ba86d2b98548f918..07f0a447c569c09a54ecf026f07b900ef3f0b096 100644 (file)
@@ -1,3 +1,32 @@
+2008-02-01  Pedro Alves  <pedro_alves@portugalmail.pt>
+
+       * hostio.c: Don't include errno.h.
+       (errno_to_fileio_errno): Move to hostio-errno.
+       * hostio.c: (hostio_error): Remove the error parameter.  Defer the
+       error number outputting to the target->hostio_last_error callback.
+       (hostio_packet_error): Use FILEIO_EINVAL directly.
+       (handle_open, handle_pread, hostio_error, handle_unlink): Update
+       calls to hostio_error.
+       * hostio-errno.c: New.
+       * server.h (hostio_last_error_from_errno): Declare.
+       * target.h (target_ops): Add hostio_last_error member.
+       * linux-low.c (linux_target_op): Register hostio_last_error_from_errno
+       as hostio_last_error handler.
+       * spu-low.c (spu_target_ops): Likewise. 
+       * win32-low.c [_WIN32_WCE] (win32_error_to_fileio_error)
+       (wince_hostio_last_error): New functions.
+       (win32_target_ops) [_WIN32_WCE]: Register wince_hostio_last_error
+       as hostio_last_error handler.
+       (win32_target_ops) [!_WIN32_WCE]: Register
+       hostio_last_error_from_errno as hostio_last_error handler.
+       * Makefile.in (SFILES): Add hostio.c and hostio-errno.c.
+       (hostio-errno.o): New rule.
+       * configure.ac (GDBSERVER_DEPFILES): Add $srv_hostio_err_objs.
+       * configure.srv (srv_hostio_err_objs): New variable.  Default to
+       hostio-errno.o.
+       (arm*-*-mingw32ce*): Set srv_hostio_err_objs to "".
+       * configure: Regenerate.
+
 2008-01-29  Daniel Jacobowitz  <dan@codesourcery.com>
 
        * linux-low.c (linux_attach_lwp): Do not _exit after errors.
index 91e5c1f6f5f9c979a1d71d1f5bfb487fa9ceda7f..d643bdf379cede39c7f33ce464b38b0104b2bb66 100644 (file)
@@ -130,7 +130,8 @@ SFILES=     $(srcdir)/gdbreplay.c $(srcdir)/inferiors.c \
        $(srcdir)/linux-s390-low.c \
        $(srcdir)/linux-sh-low.c $(srcdir)/linux-x86-64-low.c \
        $(srcdir)/win32-arm-low.c $(srcdir)/win32-i386-low.c \
-       $(srcdir)/win32-low.c $(srcdir)/wincecompat.c
+       $(srcdir)/win32-low.c $(srcdir)/wincecompat.c \
+       $(srcdir)/hostio.c $(srcdir)/hostio-errno.c
 
 DEPFILES = @GDBSERVER_DEPFILES@
 
@@ -278,6 +279,7 @@ server_h = $(srcdir)/server.h $(regcache_h) config.h $(srcdir)/target.h \
                $(srcdir)/mem-break.h
 
 hostio.o: hostio.c $(server_h)
+hostio-errno.o: hostio-errno.c $(server_h)
 inferiors.o: inferiors.c $(server_h)
 mem-break.o: mem-break.c $(server_h)
 proc-service.o: proc-service.c $(server_h) $(gdb_proc_service_h)
index b8b28790826cc3d247659749e7e0998645d7448b..5dad21c15f82f2de2ac937e5cba7a41ebc0e186b 100755 (executable)
@@ -4403,7 +4403,7 @@ _ACEOF
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
 GDBSERVER_LIBS="$srv_libs"
 
 
index 819feade83aaec51b0e58d8b6fd9693cc55986c3..979c92530edaec30b9c5512b54ed2af8fd6c1c05 100644 (file)
@@ -214,7 +214,7 @@ if test "$srv_xmltarget" != ""; then
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
 GDBSERVER_LIBS="$srv_libs"
 
 AC_SUBST(GDBSERVER_DEPFILES)
index 24ee308977689fc23351c18d212032453a730110..b57c8a50ce15187b766235672299012563303c04 100644 (file)
@@ -6,6 +6,8 @@
 #   srv_regobj         The register protocol appropriate for this target.
 #   srv_tgtobj         Any other target-specific modules appropriate
 #                      for this target.
+#   srv_hostio_err     The object implementing the hostio_last_error
+#                      target method.
 #   srv_xmltarget      The XML source file to use for target.xml, if any.
 #   srv_xmlfiles       Any other XML files which should be available for
 #                      gdbserver in this configuration.
@@ -18,6 +20,9 @@
 #   srv_linux_usrregs  Set to "yes" if we can get at registers via
 #                      PTRACE_PEEKUSR / PTRACE_POKEUSR.
 
+# Default hostio_last_error implementation
+srv_hostio_err_objs="hostio-errno.o"
+
 # Input is taken from the "${target}" variable.
 
 case "${target}" in
@@ -36,6 +41,8 @@ case "${target}" in
   arm*-*-mingw32ce*)   srv_regobj=reg-arm.o
                        srv_tgtobj="win32-low.o win32-arm-low.o"
                        srv_tgtobj="${srv_tgtobj} wincecompat.o"
+                       # hostio_last_error implementation is in win32-low.c
+                       srv_hostio_err_objs=""
                        srv_mingw=yes
                        srv_mingwce=yes
                        ;;
diff --git a/gdb/gdbserver/hostio-errno.c b/gdb/gdbserver/hostio-errno.c
new file mode 100644 (file)
index 0000000..140cc64
--- /dev/null
@@ -0,0 +1,88 @@
+/* Host file transfer support for gdbserver.
+   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+
+   Contributed by CodeSourcery.
+
+   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.  */
+
+/* This file implements the hostio_last_error target callback
+   on top of errno.  */
+
+#include <errno.h>
+#include "server.h"
+#include "gdb/fileio.h"
+
+static int
+errno_to_fileio_error (int error)
+{
+  switch (error)
+    {
+    case EPERM:
+      return FILEIO_EPERM;
+    case ENOENT:
+      return FILEIO_ENOENT;
+    case EINTR:
+      return FILEIO_EINTR;
+    case EIO:
+      return FILEIO_EIO;
+    case EBADF:
+      return FILEIO_EBADF;
+    case EACCES:
+      return FILEIO_EACCES;
+    case EFAULT:
+      return FILEIO_EFAULT;
+    case EBUSY:
+      return FILEIO_EBUSY;
+    case EEXIST:
+      return FILEIO_EEXIST;
+    case ENODEV:
+      return FILEIO_ENODEV;
+    case ENOTDIR:
+      return FILEIO_ENOTDIR;
+    case EISDIR:
+      return FILEIO_EISDIR;
+    case EINVAL:
+      return FILEIO_EINVAL;
+    case ENFILE:
+      return FILEIO_ENFILE;
+    case EMFILE:
+      return FILEIO_EMFILE;
+    case EFBIG:
+      return FILEIO_EFBIG;
+    case ENOSPC:
+      return FILEIO_ENOSPC;
+    case ESPIPE:
+      return FILEIO_ESPIPE;
+    case EROFS:
+      return FILEIO_EROFS;
+    case ENOSYS:
+      return FILEIO_ENOSYS;
+    case ENAMETOOLONG:
+      return FILEIO_ENAMETOOLONG;
+    }
+
+  return FILEIO_EUNKNOWN;
+}
+
+void
+hostio_last_error_from_errno (char *buf)
+{
+  int error = errno;
+  int fileio_error = errno_to_fileio_error (error);
+  sprintf (buf, "F-1,%x", fileio_error);
+}
index 3ace72538b2d961799dfa4f622c2479b06adb36f..712deb487e263e9fff110497a7b53a174045b093 100644 (file)
@@ -23,7 +23,6 @@
 #include "server.h"
 #include "gdb/fileio.h"
 
-#include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <unistd.h>
@@ -176,69 +175,18 @@ require_valid_fd (int fd)
   return -1;
 }
 
-static int
-errno_to_fileio_errno (int error)
-{
-  switch (error)
-    {
-    case EPERM:
-      return FILEIO_EPERM;
-    case ENOENT:
-      return FILEIO_ENOENT;
-    case EINTR:
-      return FILEIO_EINTR;
-    case EIO:
-      return FILEIO_EIO;
-    case EBADF:
-      return FILEIO_EBADF;
-    case EACCES:
-      return FILEIO_EACCES;
-    case EFAULT:
-      return FILEIO_EFAULT;
-    case EBUSY:
-      return FILEIO_EBUSY;
-    case EEXIST:
-      return FILEIO_EEXIST;
-    case ENODEV:
-      return FILEIO_ENODEV;
-    case ENOTDIR:
-      return FILEIO_ENOTDIR;
-    case EISDIR:
-      return FILEIO_EISDIR;
-    case EINVAL:
-      return FILEIO_EINVAL;
-    case ENFILE:
-      return FILEIO_ENFILE;
-    case EMFILE:
-      return FILEIO_EMFILE;
-    case EFBIG:
-      return FILEIO_EFBIG;
-    case ENOSPC:
-      return FILEIO_ENOSPC;
-    case ESPIPE:
-      return FILEIO_ESPIPE;
-    case EROFS:
-      return FILEIO_EROFS;
-    case ENOSYS:
-      return FILEIO_ENOSYS;
-    case ENAMETOOLONG:
-      return FILEIO_ENAMETOOLONG;
-    }
-  return FILEIO_EUNKNOWN;
-}
-
+/* Fill in own_buf with the last hostio error packet, however it
+   suitable for the target.  */
 static void
-hostio_error (char *own_buf, int error)
+hostio_error (char *own_buf)
 {
-  int fileio_error = errno_to_fileio_errno (error);
-
-  sprintf (own_buf, "F-1,%x", fileio_error);
+  the_target->hostio_last_error (own_buf);
 }
 
 static void
 hostio_packet_error (char *own_buf)
 {
-  hostio_error (own_buf, EINVAL);
+  sprintf (own_buf, "F-1,%x", FILEIO_EINVAL);
 }
 
 static void
@@ -342,7 +290,7 @@ handle_open (char *own_buf)
 
   if (fd == -1)
     {
-      hostio_error (own_buf, errno);
+      hostio_error (own_buf);
       return;
     }
 
@@ -386,7 +334,7 @@ handle_pread (char *own_buf, int *new_packet_len)
 
   if (ret == -1)
     {
-      hostio_error (own_buf, errno);
+      hostio_error (own_buf);
       free (data);
       return;
     }
@@ -434,7 +382,7 @@ handle_pwrite (char *own_buf, int packet_len)
 
   if (ret == -1)
     {
-      hostio_error (own_buf, errno);
+      hostio_error (own_buf);
       free (data);
       return;
     }
@@ -464,7 +412,7 @@ handle_close (char *own_buf)
 
   if (ret == -1)
     {
-      hostio_error (own_buf, errno);
+      hostio_error (own_buf);
       return;
     }
 
@@ -499,7 +447,7 @@ handle_unlink (char *own_buf)
 
   if (ret == -1)
     {
-      hostio_error (own_buf, errno);
+      hostio_error (own_buf);
       return;
     }
 
index f5bf5dce472f411076da572958a7a2adb9678b34..c2b66c34227e97e9fd61f1aaa70c5b5ac82270ee 100644 (file)
@@ -2053,6 +2053,8 @@ static struct target_ops linux_target_ops = {
   NULL,
 #endif
   linux_arch_string,
+  NULL,
+  hostio_last_error_from_errno,
 };
 
 static void
index 745d7b63f4b85ad0d22f599ffe004e9fa358a665..107813b83984b8f800f5c449b6d2b81eb162fc72 100644 (file)
@@ -159,6 +159,9 @@ extern jmp_buf toplevel;
 /* Functions from hostio.c.  */
 extern int handle_vFile (char *, int, int *);
 
+/* Functions from hostio-errno.c.  */
+extern void hostio_last_error_from_errno (char *own_buf);
+
 /* From remote-utils.c */
 
 extern int remote_debug;
index 8579e8be46cee670c3a6db232c5509f5be5d6303..bba7c193be63afb2f6a94de7bd949ad3e3dd1990 100644 (file)
@@ -590,6 +590,7 @@ static struct target_ops spu_target_ops = {
   NULL,
   spu_arch_string,
   spu_proc_xfer_spu,
+  hostio_last_error_from_errno,
 };
 
 void
index 4f6377d6fe05849cf9db748e93c4cc54aaab2188..8bb7a07b3d7ded469ad32e2f239e2e4930e31a3b 100644 (file)
@@ -188,6 +188,10 @@ struct target_ops
    /* Read/Write from/to spufs using qXfer packets.  */
   int (*qxfer_spu) (const char *annex, unsigned char *readbuf,
                    unsigned const char *writebuf, CORE_ADDR offset, int len);
+
+  /* Fill BUF with an hostio error packet representing the last hostio
+     error.  */
+  void (*hostio_last_error) (char *buf);
 };
 
 extern struct target_ops *the_target;
index a47ba89f826ebe387ceae9b5bc88d0e27697ec12..141403d81f1aa8a5167ae3661f134f7a58fcd545 100644 (file)
@@ -21,6 +21,7 @@
 #include "server.h"
 #include "regcache.h"
 #include "gdb/signals.h"
+#include "gdb/fileio.h"
 #include "mem-break.h"
 #include "win32-low.h"
 
@@ -1653,6 +1654,65 @@ win32_arch_string (void)
   return the_low_target.arch_string;
 }
 
+#ifdef _WIN32_WCE
+int
+win32_error_to_fileio_error (DWORD err)
+{
+  switch (err)
+    {
+    case ERROR_BAD_PATHNAME:
+    case ERROR_FILE_NOT_FOUND:
+    case ERROR_INVALID_NAME:
+    case ERROR_PATH_NOT_FOUND:
+      return FILEIO_ENOENT;
+    case ERROR_CRC:
+    case ERROR_IO_DEVICE:
+    case ERROR_OPEN_FAILED:
+      return FILEIO_EIO;
+    case ERROR_INVALID_HANDLE:
+      return FILEIO_EBADF;
+    case ERROR_ACCESS_DENIED:
+    case ERROR_SHARING_VIOLATION:
+      return FILEIO_EACCES;
+    case ERROR_NOACCESS:
+      return FILEIO_EFAULT;
+    case ERROR_BUSY:
+      return FILEIO_EBUSY;
+    case ERROR_ALREADY_EXISTS:
+    case ERROR_FILE_EXISTS:
+      return FILEIO_EEXIST;
+    case ERROR_BAD_DEVICE:
+      return FILEIO_ENODEV;
+    case ERROR_DIRECTORY:
+      return FILEIO_ENOTDIR;
+    case ERROR_FILENAME_EXCED_RANGE:
+    case ERROR_INVALID_DATA:
+    case ERROR_INVALID_PARAMETER:
+    case ERROR_NEGATIVE_SEEK:
+      return FILEIO_EINVAL;
+    case ERROR_TOO_MANY_OPEN_FILES:
+      return FILEIO_EMFILE;
+    case ERROR_HANDLE_DISK_FULL:
+    case ERROR_DISK_FULL:
+      return FILEIO_ENOSPC;
+    case ERROR_WRITE_PROTECT:
+      return FILEIO_EROFS;
+    case ERROR_NOT_SUPPORTED:
+      return FILEIO_ENOSYS;
+    }
+
+  return FILEIO_EUNKNOWN;
+}
+
+static void
+wince_hostio_last_error (char *buf)
+{
+  DWORD winerr = GetLastError ();
+  int fileio_err = win32_error_to_fileio_error (winerr);
+  sprintf (buf, "F-1,%x", fileio_err);
+}
+#endif
+
 static struct target_ops win32_target_ops = {
   win32_create_inferior,
   win32_attach,
@@ -1675,7 +1735,13 @@ static struct target_ops win32_target_ops = {
   NULL,
   NULL,
   NULL,
-  win32_arch_string
+  win32_arch_string,
+  NULL,
+#ifdef _WIN32_WCE
+  wince_hostio_last_error,
+#else
+  hostio_last_error_from_errno,
+#endif
 };
 
 /* Initialize the Win32 backend.  */