* [gdbserver] Make mingw32ce gdbserver build again
@ 2008-01-31 7:03 Pedro Alves
2008-01-31 15:02 ` Daniel Jacobowitz
0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2008-01-31 7:03 UTC (permalink / raw)
To: GDB Patches
[-- Attachment #1: Type: text/plain, Size: 451 bytes --]
This patch makes gdbserver build again when configured for
arm-mingw32ce (Windows CE).
The problem is that Windows CE runtime doesn't have a
notion of errno.
This patch moves the conversion of last error to hostio error
to a target method. The current code was moved to a seperate objfile
which is linked only on targets that use it, which are all but mingw32ce
currently. Windows CE converts from the native Windows error.
OK ?
--
Pedro Alves
[-- Attachment #2: wince_hostio.diff --]
[-- Type: text/x-diff, Size: 15438 bytes --]
gdbserver/
2008-01-31 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.
---
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 <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <unistd.h>
@@ -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 <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 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) \
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [gdbserver] Make mingw32ce gdbserver build again 2008-01-31 7:03 [gdbserver] Make mingw32ce gdbserver build again Pedro Alves @ 2008-01-31 15:02 ` Daniel Jacobowitz 2008-01-31 18:45 ` Pedro Alves 0 siblings, 1 reply; 5+ messages in thread From: Daniel Jacobowitz @ 2008-01-31 15:02 UTC (permalink / raw) To: Pedro Alves; +Cc: GDB Patches On Thu, Jan 31, 2008 at 02:56:22AM +0000, Pedro Alves wrote: > 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); > } > Pretty much anything can change errno. That includes sprintf. So you have to save the value of errno before you call back into the C library, in general, or you might print some other error than the one you want. For now, how about the_target->hostio_last_error which converts to a protocol error and returns that? Then we can call it before sprintf. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gdbserver] Make mingw32ce gdbserver build again 2008-01-31 15:02 ` Daniel Jacobowitz @ 2008-01-31 18:45 ` Pedro Alves 2008-01-31 22:03 ` Daniel Jacobowitz 0 siblings, 1 reply; 5+ messages in thread From: Pedro Alves @ 2008-01-31 18:45 UTC (permalink / raw) To: GDB Patches [-- Attachment #1: Type: text/plain, Size: 1060 bytes --] Daniel Jacobowitz wrote: > On Thu, Jan 31, 2008 at 02:56:22AM +0000, Pedro Alves wrote: >> 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); >> } >> > > Pretty much anything can change errno. That includes sprintf. So you > have to save the value of errno before you call back into the C > library, in general, or you might print some other error than the one > you want. > > For now, how about the_target->hostio_last_error which converts to a > protocol error and returns that? Then we can call it before sprintf. > If you're going to accept my proposed extension to the protocol, then I'd go the other direction and move the sprintf to the target method, because then I'd write two numbers in own_buf; an int return wouldn't suffice. See attached. I'll post the other patch seperatelly. -- Pedro Alves [-- Attachment #2: wince_hostio.diff --] [-- Type: text/x-diff, Size: 14257 bytes --] gdbserver/ 2008-01-31 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. --- gdb/gdbserver/Makefile.in | 4 +- gdb/gdbserver/configure | 2 - gdb/gdbserver/configure.ac | 2 - gdb/gdbserver/configure.srv | 7 ++++ gdb/gdbserver/hostio-errno.c | 64 +++++++++++++++++++++++++++++++++++++ gdb/gdbserver/hostio.c | 74 ++++++------------------------------------- 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 | 69 +++++++++++++++++++++++++++++++++++++++- 11 files changed, 165 insertions(+), 66 deletions(-) Index: src/gdb/gdbserver/hostio.c =================================================================== --- src.orig/gdb/gdbserver/hostio.c 2008-01-31 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/hostio.c 2008-01-31 17:50:02.000000000 +0000 @@ -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,20 @@ 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. In addition to the hostio error, the + target may fill in the original error before mapping to hostio + error, eg. the errno value. */ 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 +292,7 @@ handle_open (char *own_buf) if (fd == -1) { - hostio_error (own_buf, errno); + hostio_error (own_buf); return; } @@ -386,7 +336,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 +384,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 +414,7 @@ handle_close (char *own_buf) if (ret == -1) { - hostio_error (own_buf, errno); + hostio_error (own_buf); return; } @@ -499,7 +449,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 17:50:02.000000000 +0000 @@ -0,0 +1,64 @@ +#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); + errno = error; /* preserve errno */ +} Index: src/gdb/gdbserver/linux-low.c =================================================================== --- src.orig/gdb/gdbserver/linux-low.c 2008-01-31 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/linux-low.c 2008-01-31 17:50:02.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-31 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/server.h 2008-01-31 17:50:02.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-31 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/spu-low.c 2008-01-31 17:50:02.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 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/target.h 2008-01-31 17:50:02.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 an hostio error packet representing 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 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/win32-low.c 2008-01-31 17:50:02.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,66 @@ 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); + SetLastError (winerr); /* preserve last error */ +} +#endif + static struct target_ops win32_target_ops = { win32_create_inferior, win32_attach, @@ -1675,7 +1736,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-31 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/Makefile.in 2008-01-31 17:50:02.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-31 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/configure.ac 2008-01-31 17:50:02.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-31 17:49:59.000000000 +0000 +++ src/gdb/gdbserver/configure.srv 2008-01-31 17:50:02.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-31 17:50:00.000000000 +0000 +++ src/gdb/gdbserver/configure 2008-01-31 17:50:02.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" ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gdbserver] Make mingw32ce gdbserver build again 2008-01-31 18:45 ` Pedro Alves @ 2008-01-31 22:03 ` Daniel Jacobowitz 2008-02-01 0:14 ` Pedro Alves 0 siblings, 1 reply; 5+ messages in thread From: Daniel Jacobowitz @ 2008-01-31 22:03 UTC (permalink / raw) To: Pedro Alves; +Cc: GDB Patches On Thu, Jan 31, 2008 at 05:58:15PM +0000, Pedro Alves wrote: > gdbserver/ > 2008-01-31 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. OK. > 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 17:50:02.000000000 +0000 > @@ -0,0 +1,64 @@ > +#include <errno.h> This file needs a copyright notice. > +{ > + int error = errno; > + int fileio_error = errno_to_fileio_error (error); > + sprintf (buf, "F-1,%x", fileio_error); > + errno = error; /* preserve errno */ No need to preserve errno. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [gdbserver] Make mingw32ce gdbserver build again 2008-01-31 22:03 ` Daniel Jacobowitz @ 2008-02-01 0:14 ` Pedro Alves 0 siblings, 0 replies; 5+ messages in thread From: Pedro Alves @ 2008-02-01 0:14 UTC (permalink / raw) To: GDB Patches Daniel Jacobowitz wrote: > On Thu, Jan 31, 2008 at 05:58:15PM +0000, Pedro Alves wrote: >> gdbserver/ >> 2008-01-31 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. > > OK. Thanks. Checked in after fixing the issues you pointed out. >> Index: src/gdb/gdbserver/hostio-errno.c Since the contents of this file were mostly copied from hostio.c, I used the same the copyright years (2007, 2008). -- Pedro Alves ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-02-01 0:14 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-01-31 7:03 [gdbserver] Make mingw32ce gdbserver build again Pedro Alves 2008-01-31 15:02 ` Daniel Jacobowitz 2008-01-31 18:45 ` Pedro Alves 2008-01-31 22:03 ` Daniel Jacobowitz 2008-02-01 0:14 ` Pedro Alves
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox