This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA/gdbserver] Provide dummy readlink on systems where routine is not available.


Hello,

No sooner did I send the patch that I realized that I forgot to include
the new .h file in gdbserver/hostio.c. No biggie, as compilation warnings
do not seem to be fatal in gdbserver, but easy to fix.

Here is a new version of the patch.

-- 
Joel

This fixes the gdbserver build failure on Windows hosts due to
a missing readlink (not implemented on this system). It does so
by providing a dummy readlink for systems, like Windows, which
do not provide one.  The dummy version returns -1 and sets errno
to ENOSYS (function not implemented).

gdb/ChangeLog:

        * common/gdb_readlink.h, common/gdb_readlink.c: New files.

gdb/gdbserver/ChangeLog:

        * configure.ac: Add checks for readlink function and declaration.
        * configure: Regenerate.
        * config.in: Regenerate.
        * Makefile.in (SFILES): Add gdb_readlink.c.
        (OBS): Add gdb_readlink.o.
        (gdb_readlink_h): New variable.
        (gdb_readlink.o): New rule.
        * hostio.c: #include "gdb_readlink.h".
---
 gdb/common/gdb_readlink.c  |   37 +++++++++++++++++++++++++++++++++++++
 gdb/common/gdb_readlink.h  |   36 ++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/Makefile.in  |    9 +++++++--
 gdb/gdbserver/config.in    |    7 +++++++
 gdb/gdbserver/configure    |   12 +++++++++++-
 gdb/gdbserver/configure.ac |    4 ++--
 gdb/gdbserver/hostio.c     |    1 +
 7 files changed, 101 insertions(+), 5 deletions(-)
 create mode 100644 gdb/common/gdb_readlink.c
 create mode 100644 gdb/common/gdb_readlink.h

diff --git a/gdb/common/gdb_readlink.c b/gdb/common/gdb_readlink.c
new file mode 100644
index 0000000..2e5c8e3
--- /dev/null
+++ b/gdb/common/gdb_readlink.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2012 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 "gdb_readlink.h"
+
+#ifndef HAVE_READLINK
+#include <errno.h>
+
+/* Provide a dummy version of readlink on the systems that do not
+   support this routine.
+
+   This function return -1 (error) and sets errno to ENOSYS to indicate
+   that this function is not implemented.  The caller should be prepared
+   to recover from that.  */
+
+ssize_t
+readlink(const char *path, char *buf, size_t bufsiz)
+{
+  errno = EINVAL;
+  return -1;
+}
+#endif
+
diff --git a/gdb/common/gdb_readlink.h b/gdb/common/gdb_readlink.h
new file mode 100644
index 0000000..6acc6fd
--- /dev/null
+++ b/gdb/common/gdb_readlink.h
@@ -0,0 +1,36 @@
+/* Portable access to `readlink'.
+
+   Copyright (C) 2012 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/>.  */
+
+#ifndef GDB_READLINK_H
+#define GDB_READLINK_H
+
+/* If readlink is available, it should be declared in "unistd.h".  */
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <sys/types.h>
+#include "config.h"
+
+#ifndef HAVE_DECL_READLINK
+extern ssize_t readlink (const char *path, char *buf, size_t bufsiz);
+#endif
+
+#endif
+
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 485e031..cd83507 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -125,7 +125,8 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c \
 	$(srcdir)/hostio.c $(srcdir)/hostio-errno.c \
 	$(srcdir)/common/common-utils.c $(srcdir)/common/xml-utils.c \
 	$(srcdir)/common/linux-osdata.c $(srcdir)/common/ptid.c \
-	$(srcdir)/common/buffer.c
+	$(srcdir)/common/buffer.c \
+	$(srcdir)/common/gdb_readlink.c
 
 DEPFILES = @GDBSERVER_DEPFILES@
 
@@ -137,7 +138,7 @@ TAGFILES = $(SOURCES) ${HFILES} ${ALLPARAM} ${POSSLIBS}
 OBS = inferiors.o regcache.o remote-utils.o server.o signals.o target.o \
 	utils.o version.o \
 	mem-break.o hostio.o event-loop.o tracepoint.o \
-	xml-utils.o common-utils.o ptid.o buffer.o \
+	xml-utils.o common-utils.o ptid.o buffer.o gdb_readlink.o \
 	$(XML_BUILTIN) \
 	$(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
@@ -343,6 +344,7 @@ server_h = $(srcdir)/server.h $(regcache_h) config.h $(srcdir)/target.h \
 		$(srcdir)/../common/gdb_locale.h \
 		$(ptid_h) \
 		$(signals_h)
+gdb_readlink_h = $(srcdir)/../common/gdb_readlink.h
 
 linux_low_h = $(srcdir)/linux-low.h
 
@@ -421,6 +423,9 @@ ptid.o: ../common/ptid.c $(ptid_h)
 buffer.o: ../common/buffer.c $(server_h)
 	$(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER
 
+gdb_readlink.o: ../common/gdb_readlink.c $(gdb_readlink_h)
+	$(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER
+
 # We build memmem.c without -Werror because this file is not under
 # our control.  On LynxOS, the compiler generates some warnings
 # because str-two-way.h uses a constant (MAX_SIZE) whose definition
diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index a9472ea..b2a356d 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -30,6 +30,10 @@
    */
 #undef HAVE_DECL_PERROR
 
+/* Define to 1 if you have the declaration of `readlink', and to 0 if you
+   don't. */
+#undef HAVE_DECL_READLINK
+
 /* Define to 1 if you have the declaration of `strerror', and to 0 if you
    don't. */
 #undef HAVE_DECL_STRERROR
@@ -128,6 +132,9 @@
 /* Define to 1 if you have the `pwrite' function. */
 #undef HAVE_PWRITE
 
+/* Define to 1 if you have the `readlink' function. */
+#undef HAVE_READLINK
+
 /* Define to 1 if you have the <sgtty.h> header file. */
 #undef HAVE_SGTTY_H
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index d92a00f..b014254 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -4163,7 +4163,7 @@ fi
 
 done
 
-for ac_func in pread pwrite pread64
+for ac_func in pread pwrite pread64 readlink
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -4458,6 +4458,16 @@ fi
 cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_VSNPRINTF $ac_have_decl
 _ACEOF
+ac_fn_c_check_decl "$LINENO" "readlink" "ac_cv_have_decl_readlink" "$ac_includes_default"
+if test "x$ac_cv_have_decl_readlink" = x""yes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_READLINK $ac_have_decl
+_ACEOF
 
 
 ac_fn_c_check_type "$LINENO" "socklen_t" "ac_cv_type_socklen_t" "#include <sys/types.h>
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 30666ec..0382430 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -43,7 +43,7 @@ AC_CHECK_HEADERS(sgtty.h termio.h termios.h sys/reg.h string.h dnl
 		 errno.h fcntl.h signal.h sys/file.h malloc.h dnl
 		 sys/ioctl.h netinet/in.h sys/socket.h netdb.h dnl
 		 netinet/tcp.h arpa/inet.h sys/wait.h)
-AC_CHECK_FUNCS(pread pwrite pread64)
+AC_CHECK_FUNCS(pread pwrite pread64 readlink)
 AC_REPLACE_FUNCS(memmem vasprintf vsnprintf)
 
 # Check for UST
@@ -161,7 +161,7 @@ AC_TRY_LINK([
   [AC_MSG_RESULT(no)])
 fi
 
-AC_CHECK_DECLS([strerror, perror, memmem, vasprintf, vsnprintf])
+AC_CHECK_DECLS([strerror, perror, memmem, vasprintf, vsnprintf, readlink])
 
 AC_CHECK_TYPES(socklen_t, [], [],
 [#include <sys/types.h>
diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c
index 34e4fa8..370c958 100644
--- a/gdb/gdbserver/hostio.c
+++ b/gdb/gdbserver/hostio.c
@@ -20,6 +20,7 @@
 
 #include "server.h"
 #include "gdb/fileio.h"
+#include "gdb_readlink.h"
 
 #include <fcntl.h>
 #include <limits.h>
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]