From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32498 invoked by alias); 3 Feb 2012 12:31:07 -0000 Received: (qmail 32487 invoked by uid 22791); 3 Feb 2012 12:31:06 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Feb 2012 12:30:52 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id ACAEE2BB4AA; Fri, 3 Feb 2012 07:30:51 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 2YtH8h1RQ1Y5; Fri, 3 Feb 2012 07:30:51 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id C2D012BB4A2; Fri, 3 Feb 2012 07:30:50 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 08FF0145615; Fri, 3 Feb 2012 16:30:31 +0400 (RET) Date: Fri, 03 Feb 2012 12:31:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Cc: palves@redhat.com Subject: Re: [RFA/gdbserver] Provide dummy readlink on systems where routine is not available. Message-ID: <20120203123030.GJ31383@adacore.com> References: <1328269562-19101-1-git-send-email-brobecker@adacore.com> <1328270124-27388-1-git-send-email-brobecker@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="qp4W5+cUSnZs0RIF" Content-Disposition: inline In-Reply-To: <1328270124-27388-1-git-send-email-brobecker@adacore.com> User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-02/txt/msg00049.txt.bz2 --qp4W5+cUSnZs0RIF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 470 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 --qp4W5+cUSnZs0RIF Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="gdb-readlink-gdbserver-v3.diff" Content-length: 8486 commit 8c8b9045fe33cc09d5ee32ae51c5490adbba2e41 Author: Joel Brobecker 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 . */ + +#include "gdb_readlink.h" + +#ifndef HAVE_READLINK +#include + +/* 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 . */ + +#ifndef GDB_READLINK_H +#define GDB_READLINK_H + +/* If readlink is available, it should be declared in "unistd.h". */ +#ifdef HAVE_UNISTD_H +#include +#endif + +#include +#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 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 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 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 #include --qp4W5+cUSnZs0RIF--