gdbserver/ 2008-01-31 Pedro Alves * 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. --- gdb/Makefile.in | 12 +++---- gdb/gdbserver/Makefile.in | 4 +- gdb/gdbserver/configure | 2 - gdb/gdbserver/configure.ac | 2 - gdb/gdbserver/configure.srv | 7 ++++ gdb/gdbserver/hostio-errno.c | 62 +++++++++++++++++++++++++++++++++++++ gdb/gdbserver/hostio.c | 71 +++++-------------------------------------- gdb/gdbserver/linux-low.c | 2 + gdb/gdbserver/server.h | 3 + gdb/gdbserver/spu-low.c | 1 gdb/gdbserver/target.h | 3 + gdb/gdbserver/win32-low.c | 68 ++++++++++++++++++++++++++++++++++++++++- 12 files changed, 165 insertions(+), 72 deletions(-) Index: src/gdb/gdbserver/hostio.c =================================================================== --- src.orig/gdb/gdbserver/hostio.c 2008-01-29 15:37:56.000000000 +0000 +++ src/gdb/gdbserver/hostio.c 2008-01-31 02:47:04.000000000 +0000 @@ -23,7 +23,6 @@ #include "server.h" #include "gdb/fileio.h" -#include #include #include #include @@ -176,69 +175,17 @@ 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; -} - 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); + sprintf (own_buf, "F-1,"); + the_target->hostio_last_error (own_buf + 4); } 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 +289,7 @@ handle_open (char *own_buf) if (fd == -1) { - hostio_error (own_buf, errno); + hostio_error (own_buf); return; } @@ -386,7 +333,7 @@ handle_pread (char *own_buf, int *new_pa if (ret == -1) { - hostio_error (own_buf, errno); + hostio_error (own_buf); free (data); return; } @@ -434,7 +381,7 @@ handle_pwrite (char *own_buf, int packet if (ret == -1) { - hostio_error (own_buf, errno); + hostio_error (own_buf); free (data); return; } @@ -464,7 +411,7 @@ handle_close (char *own_buf) if (ret == -1) { - hostio_error (own_buf, errno); + hostio_error (own_buf); return; } @@ -499,7 +446,7 @@ handle_unlink (char *own_buf) if (ret == -1) { - hostio_error (own_buf, errno); + hostio_error (own_buf); return; } Index: src/gdb/gdbserver/hostio-errno.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ src/gdb/gdbserver/hostio-errno.c 2008-01-31 02:47:04.000000000 +0000 @@ -0,0 +1,62 @@ +#include +#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 fileio_error = errno_to_fileio_error (errno); + sprintf (buf, "%x", fileio_error); +} Index: src/gdb/gdbserver/linux-low.c =================================================================== --- src.orig/gdb/gdbserver/linux-low.c 2008-01-31 02:46:48.000000000 +0000 +++ src/gdb/gdbserver/linux-low.c 2008-01-31 02:47:04.000000000 +0000 @@ -2053,6 +2053,8 @@ static struct target_ops linux_target_op NULL, #endif linux_arch_string, + NULL, + hostio_last_error_from_errno, }; static void Index: src/gdb/gdbserver/server.h =================================================================== --- src.orig/gdb/gdbserver/server.h 2008-01-29 15:37:56.000000000 +0000 +++ src/gdb/gdbserver/server.h 2008-01-31 02:47:04.000000000 +0000 @@ -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: src/gdb/gdbserver/spu-low.c =================================================================== --- src.orig/gdb/gdbserver/spu-low.c 2008-01-29 15:37:56.000000000 +0000 +++ src/gdb/gdbserver/spu-low.c 2008-01-31 02:47:04.000000000 +0000 @@ -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: src/gdb/gdbserver/target.h =================================================================== --- src.orig/gdb/gdbserver/target.h 2008-01-31 02:46:48.000000000 +0000 +++ src/gdb/gdbserver/target.h 2008-01-31 02:47:04.000000000 +0000 @@ -188,6 +188,9 @@ 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 a string representation of the last hostio error. */ + void (*hostio_last_error) (char *buf); }; extern struct target_ops *the_target; Index: src/gdb/gdbserver/win32-low.c =================================================================== --- src.orig/gdb/gdbserver/win32-low.c 2008-01-31 02:46:47.000000000 +0000 +++ src/gdb/gdbserver/win32-low.c 2008-01-31 02:47:04.000000000 +0000 @@ -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, "%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_op 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. */ Index: src/gdb/gdbserver/Makefile.in =================================================================== --- src.orig/gdb/gdbserver/Makefile.in 2008-01-29 15:37:56.000000000 +0000 +++ src/gdb/gdbserver/Makefile.in 2008-01-31 02:47:04.000000000 +0000 @@ -130,7 +130,8 @@ SFILES= $(srcdir)/gdbreplay.c $(srcdir)/ $(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 $(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: src/gdb/gdbserver/configure.ac =================================================================== --- src.orig/gdb/gdbserver/configure.ac 2008-01-29 15:37:56.000000000 +0000 +++ src/gdb/gdbserver/configure.ac 2008-01-31 02:47:04.000000000 +0000 @@ -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: src/gdb/gdbserver/configure.srv =================================================================== --- src.orig/gdb/gdbserver/configure.srv 2008-01-29 15:37:56.000000000 +0000 +++ src/gdb/gdbserver/configure.srv 2008-01-31 02:47:04.000000000 +0000 @@ -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 ;; Index: src/gdb/gdbserver/configure =================================================================== --- src.orig/gdb/gdbserver/configure 2008-01-29 15:37:57.000000000 +0000 +++ src/gdb/gdbserver/configure 2008-01-31 02:47:04.000000000 +0000 @@ -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: src/gdb/Makefile.in =================================================================== --- src.orig/gdb/Makefile.in 2008-01-31 02:46:47.000000000 +0000 +++ src/gdb/Makefile.in 2008-01-31 02:47:04.000000000 +0000 @@ -2614,12 +2614,12 @@ regcache.o: regcache.c $(defs_h) $(infer reggroups.o: reggroups.c $(defs_h) $(reggroups_h) $(gdbtypes_h) \ $(gdb_assert_h) $(regcache_h) $(command_h) $(gdbcmd_h) regset.o: regset.c $(defs_h) $(regset_h) $(gdb_assert_h) -remote.o: remote.c $(defs_h) $(gdb_string_h) $(inferior_h) $(bfd_h) \ - $(symfile_h) $(exceptions_h) $(target_h) $(gdbcmd_h) $(objfiles_h) \ - $(gdb_stabs_h) $(gdbthread_h) $(remote_h) $(regcache_h) $(value_h) \ - $(gdb_assert_h) $(event_loop_h) $(event_top_h) $(inf_loop_h) \ - $(serial_h) $(gdbcore_h) $(remote_fileio_h) $(solib_h) $(observer_h) \ - $(cli_decode_h) $(cli_setshow_h) $(memory_map_h) \ +remote.o: remote.c $(defs_h) $(gdb_string_h) $(safe_ctype_h) $(inferior_h) \ + $(bfd_h) $(symfile_h) $(exceptions_h) $(target_h) $(gdbcmd_h) \ + $(objfiles_h) $(gdb_stabs_h) $(gdbthread_h) $(remote_h) $(regcache_h) \ + $(value_h) $(gdb_assert_h) $(event_loop_h) $(event_top_h) \ + $(inf_loop_h) $(serial_h) $(gdbcore_h) $(remote_fileio_h) $(solib_h) \ + $(observer_h) $(cli_decode_h) $(cli_setshow_h) $(memory_map_h) \ $(target_descriptions_h) $(gdb_fileio_h) remote-fileio.o: remote-fileio.c $(defs_h) $(gdb_string_h) $(gdbcmd_h) \ $(remote_h) $(gdb_fileio_h) $(gdb_wait_h) $(gdb_stat_h) \