This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [gdbserver] Make mingw32ce gdbserver build again
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
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"