public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [RFA 2/3] Import vsnprintf from libiberty if not available.
Date: Wed, 23 Jun 2010 17:46:00 -0000	[thread overview]
Message-ID: <1277315177-17869-3-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1277315177-17869-1-git-send-email-brobecker@adacore.com>

vasprintf and vsnprintf are not available on LynxOS, at least not on
version 4.0.0.  This patch updates the configury to import them from
libiberty if not available out of the box.

The long-term goal in this area is to start using gnulib instead of
libiberty, so I will look at that in the short future.  But in the
meantime, this is a reasonably uninvasive patch that allowed me to
get the missing functions in no time.

gdbserver/
        * Makefile.in (vasprintf.o, vsnprintf.o): New rules.
        * configure.ac: Add check for vasprintf and vsnprintf.
        * configure, config.in: Regenerate.
        * server.h (vasprintf, vsnprintf): Add conditional declarations.

-- 
Joel

---
 gdb/gdbserver/Makefile.in  |    5 +++++
 gdb/gdbserver/config.in    |   14 ++++++++++++++
 gdb/gdbserver/configure    |   44 ++++++++++++++++++++++++++++++++++++--------
 gdb/gdbserver/configure.ac |    4 ++--
 gdb/gdbserver/server.h     |    7 +++++++
 5 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 7c75aed..c2e3ea2 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -340,6 +340,11 @@ signals.o: ../common/signals.c $(server_h)
 memmem.o: ../gnulib/memmem.c
 	$(CC) -o memmem.o -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $<
 
+vasprintf.o: $(srcdir)/../../libiberty/vasprintf.c
+	$(CC) -o vasprintf.o -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $<
+vsnprintf.o: $(srcdir)/../../libiberty/vsnprintf.c
+	$(CC) -o vsnprintf.o -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $<
+
 i386_low_h = $(srcdir)/i386-low.h
 
 i386-low.o: i386-low.c $(i386_low_h) $(server_h) $(target_h)
diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index 1054966..8f446a4 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -15,6 +15,14 @@
    don't. */
 #undef HAVE_DECL_STRERROR
 
+/* Define to 1 if you have the declaration of `vasprintf', and to 0 if you
+   don't. */
+#undef HAVE_DECL_VASPRINTF
+
+/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
+   don't. */
+#undef HAVE_DECL_VSNPRINTF
+
 /* Define to 1 if you have the `dladdr' function. */
 #undef HAVE_DLADDR
 
@@ -154,6 +162,12 @@
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Define to 1 if you have the `vasprintf' function. */
+#undef HAVE_VASPRINTF
+
+/* Define to 1 if you have the `vsnprintf' function. */
+#undef HAVE_VSNPRINTF
+
 /* Checking if errno must be defined */
 #undef MUST_DEFINE_ERRNO
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index c48e7a3..2708f23 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -1747,8 +1747,10 @@ $as_echo "$ac_res" >&6; }
 ac_fn_c_check_decl ()
 {
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $2 is declared" >&5
-$as_echo_n "checking whether $2 is declared... " >&6; }
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
 if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then :
   $as_echo_n "(cached) " >&6
 else
@@ -1758,8 +1760,12 @@ $4
 int
 main ()
 {
-#ifndef $2
-  (void) $2;
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
 #endif
 
   ;
@@ -3798,12 +3804,14 @@ _ACEOF
 fi
 done
 
-for ac_func in memmem
+for ac_func in memmem vasprintf vsnprintf
 do :
-  ac_fn_c_check_func "$LINENO" "memmem" "ac_cv_func_memmem"
-if test "x$ac_cv_func_memmem" = x""yes; then :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+   if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
-#define HAVE_MEMMEM 1
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF
 
 else
@@ -3918,6 +3926,26 @@ fi
 cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_MEMMEM $ac_have_decl
 _ACEOF
+ac_fn_c_check_decl "$LINENO" "vasprintf" "ac_cv_have_decl_vasprintf" "$ac_includes_default"
+if test "x$ac_cv_have_decl_vasprintf" = x""yes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_VASPRINTF $ac_have_decl
+_ACEOF
+ac_fn_c_check_decl "$LINENO" "vsnprintf" "ac_cv_have_decl_vsnprintf" "$ac_includes_default"
+if test "x$ac_cv_have_decl_vsnprintf" = x""yes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_VSNPRINTF $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 729a77a..40d30c4 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
 		 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_REPLACE_FUNCS(memmem)
+AC_REPLACE_FUNCS(memmem vasprintf vsnprintf)
 
 dnl dladdr is glibc-specific.  It is used by thread-db.c but only for
 dnl debugging messages.  It lives in -ldl which is handled below so we don't
@@ -70,7 +70,7 @@ AC_TRY_LINK([
   [AC_MSG_RESULT(no)])
 fi
 
-AC_CHECK_DECLS([strerror, perror, memmem])
+AC_CHECK_DECLS([strerror, perror, memmem, vasprintf, vsnprintf])
 
 AC_CHECK_TYPES(socklen_t, [], [],
 [#include <sys/types.h>
diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h
index 8bdd217..f853fb7 100644
--- a/gdb/gdbserver/server.h
+++ b/gdb/gdbserver/server.h
@@ -54,6 +54,13 @@ extern void perror (const char *);
 extern void *memmem (const void *, size_t , const void *, size_t);
 #endif
 
+#ifndef HAVE_DECL_VASPRINTF
+extern int vasprintf(char **strp, const char *fmt, va_list ap);
+#endif
+#ifndef HAVE_DECL_VSNPRINTF
+int vsnprintf(char *str, size_t size, const char *format, va_list ap);
+#endif
+
 #ifndef ATTR_NORETURN
 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
 #define ATTR_NORETURN __attribute__ ((noreturn))
-- 
1.7.0.4

  reply	other threads:[~2010-06-23 17:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-23 17:46 Add support for ppc-lynxos to GDBserver Joel Brobecker
2010-06-23 17:46 ` Joel Brobecker [this message]
2010-06-23 19:19   ` [RFA 2/3] Import vsnprintf from libiberty if not available Joseph S. Myers
2010-06-24 12:08   ` Pierre Muller
2010-06-24 12:40     ` Pierre Muller
2010-06-23 17:46 ` [RFA 1/3] Generate regformats/rs6000/powerpc-32.dat Joel Brobecker
2010-06-23 17:46 ` [RFA 3/3] gdbserver support for powerpc-lynxos (4.x) Joel Brobecker
2010-07-27 16:13   ` Pedro Alves
2010-08-31 19:38     ` Joel Brobecker
2010-08-31 20:24       ` Pedro Alves
2010-09-01 18:36         ` Joel Brobecker
2010-09-01 18:42           ` Pedro Alves
2010-09-01 19:00             ` 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=1277315177-17869-3-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).