From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: palves@redhat.com
Subject: Re: [RFA/gdbserver] Provide dummy readlink on systems where routine is not available.
Date: Fri, 03 Feb 2012 12:31:00 -0000 [thread overview]
Message-ID: <20120203123030.GJ31383@adacore.com> (raw)
In-Reply-To: <1328270124-27388-1-git-send-email-brobecker@adacore.com>
[-- Attachment #1: Type: text/plain, Size: 470 bytes --]
It looks like I'm doing sloppy work, today.
Another revised version, with 2 small changes:
- The pre-processor condition used to determine whether we need to
declare readlink in gdb_readlink.h or not was wrong. Somehow,
HAVE_ macros and HAVE_DECL_ macros are handled differently.
- I forgot to update hostio.c's dependency on gdb_readlink.h
in the Makefile.
Both issues now fixed, and new patch attached.
I'm going to stop here for the day.
--
Joel
[-- Attachment #2: gdb-readlink-gdbserver-v3.diff --]
[-- Type: text/x-diff, Size: 8486 bytes --]
commit 8c8b9045fe33cc09d5ee32ae51c5490adbba2e41
Author: Joel Brobecker <brobecker@adacore.com>
Date: Fri Feb 3 14:53:38 2012 +0400
Provide dummy readlink on systems where routine is not available.
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.
(hostio.o): Add dependency on gdb_readlink.h.
(gdb_readlink.o): New rule.
* hostio.c: #include "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..f8afd55
--- /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"
+
+#if !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 6ccf5ae..2c2c8d3 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
@@ -345,6 +346,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
@@ -387,7 +389,7 @@ amd64-linux-ipa.o : amd64-linux.c $(regdef_h)
$(CC) -c $(IPAGENT_CFLAGS) $< -o amd64-linux-ipa.o
event-loop.o: event-loop.c $(server_h)
-hostio.o: hostio.c $(server_h)
+hostio.o: hostio.c $(server_h) $(gdb_readlink_h)
hostio-errno.o: hostio-errno.c $(server_h)
inferiors.o: inferiors.c $(server_h)
mem-break.o: mem-break.c $(server_h)
@@ -423,6 +425,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>
next prev parent reply other threads:[~2012-02-03 12:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-27 3:20 fix build error on MinGW (HAVE_READLINK) undefined asmwarrior
2012-01-27 9:41 ` Eli Zaretskii
2012-01-27 10:28 ` Pedro Alves
2012-01-27 12:22 ` Eli Zaretskii
2012-01-27 12:36 ` Pedro Alves
2012-01-27 12:47 ` Eli Zaretskii
2012-02-03 11:47 ` [RFA/gdbserver] Provide dummy readlink on systems where routine is not available Joel Brobecker
2012-02-03 11:56 ` Joel Brobecker
2012-02-03 12:31 ` Joel Brobecker [this message]
2012-02-03 13:11 ` Eli Zaretskii
2012-02-03 13:26 ` Joel Brobecker
2012-02-09 16:32 ` [RFA/commit] gdbserver: return ENOSYS if readlink not supported Joel Brobecker
2012-02-09 16:41 ` Pedro Alves
2012-02-09 17:32 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120203123030.GJ31383@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox