From: Daniel Jacobowitz Date: Wed, 19 Sep 2007 14:41:50 +0000 (+0000) Subject: * linux-low.c (O_LARGEFILE): Define. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fd462a61890aa2795a14d98339a4094f97ea7bdb;p=binutils-gdb.git * linux-low.c (O_LARGEFILE): Define. (linux_read_memory): Use /proc/PID/mem. * configure.ac: Use AC_GNU_SOURCE. Check for pread64. * configure, config.in: Regenerated. --- diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 13bb16cfe17..c56f22f87d2 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,10 @@ +2007-09-19 Daniel Jacobowitz + + * linux-low.c (O_LARGEFILE): Define. + (linux_read_memory): Use /proc/PID/mem. + * configure.ac: Use AC_GNU_SOURCE. Check for pread64. + * configure, config.in: Regenerated. + 2007-09-04 Daniel Jacobowitz * linux-low.c (linux_wait_for_event): Do not pass signals while diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in index 675a50c96bc..017a1ed7e24 100644 --- a/gdb/gdbserver/config.in +++ b/gdb/gdbserver/config.in @@ -53,6 +53,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_TCP_H +/* Define to 1 if you have the `pread64' function. */ +#undef HAVE_PREAD64 + /* Define if has prgregset_t. */ #undef HAVE_PRGREGSET_T @@ -160,3 +163,8 @@ /* Define if an XML target description is available. */ #undef USE_XML + +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure index b6834c10251..a283dcfbff6 100755 --- a/gdb/gdbserver/configure +++ b/gdb/gdbserver/configure @@ -2228,6 +2228,12 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu +cat >>confdefs.h <<\_ACEOF +#define _GNU_SOURCE 1 +_ACEOF + + + ac_aux_dir= for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do if test -f $ac_dir/install-sh; then @@ -3093,6 +3099,108 @@ fi done +for ac_func in pread64 +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + have_errno=no echo "$as_me:$LINENO: checking for errno" >&5 echo $ECHO_N "checking for errno... $ECHO_C" >&6 diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac index 8007e148f23..de996ba8d2e 100644 --- a/gdb/gdbserver/configure.ac +++ b/gdb/gdbserver/configure.ac @@ -25,6 +25,7 @@ AC_INIT(server.c) AC_CONFIG_HEADER(config.h:config.in) AC_PROG_CC +AC_GNU_SOURCE AC_CANONICAL_SYSTEM @@ -40,6 +41,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(pread64) have_errno=no AC_MSG_CHECKING(for errno) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index aaa09ef819e..fa5c5b26289 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -40,6 +40,10 @@ # define PTRACE_SETSIGINFO 0x4203 #endif +#ifndef O_LARGEFILE +#define O_LARGEFILE 0 +#endif + #ifdef __UCLIBC__ #if !(defined(__UCLIBC_HAS_MMU__) || defined(__ARCH_HAS_MMU__)) #define HAS_NOMMU @@ -1488,7 +1492,38 @@ linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) /* Allocate buffer of that many longwords. */ register PTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *) alloca (count * sizeof (PTRACE_XFER_TYPE)); + int fd; + char filename[64]; + + /* Try using /proc. Don't bother for one word. */ + if (len >= 3 * sizeof (long)) + { + /* We could keep this file open and cache it - possibly one per + thread. That requires some juggling, but is even faster. */ + sprintf (filename, "/proc/%ld/mem", inferior_pid); + fd = open (filename, O_RDONLY | O_LARGEFILE); + if (fd == -1) + goto no_proc; + + /* If pread64 is available, use it. It's faster if the kernel + supports it (only one syscall), and it's 64-bit safe even on + 32-bit platforms (for instance, SPARC debugging a SPARC64 + application). */ +#ifdef HAVE_PREAD64 + if (pread64 (fd, myaddr, len, memaddr) != len) +#else + if (lseek (fd, memaddr, SEEK_SET) == -1 || read (fd, memaddr, len) != len) +#endif + { + close (fd); + goto no_proc; + } + + close (fd); + return 0; + } + no_proc: /* Read all the longwords */ for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) {