This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 7/7] gdbserver: add fallback implementation for memmem
- From: Mircea Gherzan <mircea dot gherzan at intel dot com>
- To: tromey at redhat dot com, palves at redhat dot com, jan dot kratochvil at redhat dot com
- Cc: gdb-patches at sourceware dot org, Mircea Gherzan <mircea dot gherzan at intel dot com>
- Date: Thu, 27 Jun 2013 10:43:42 +0200
- Subject: [PATCH 7/7] gdbserver: add fallback implementation for memmem
- References: <1372322622-3216-1-git-send-email-mircea dot gherzan at intel dot com>
The memmem() function is a GNU extension.
2013-06-26 Mircea Gherzan <mircea.gherzan@intel.com>
gdbserver/
* configure.ac (AC_CHECK_FUNCS): Add memmem.
* configure: Rebuild.
* config.in: Rebuild.
* server.c (memmem): New function, included only if it's not
already provided by the system.
Signed-off-by: Mircea Gherzan <mircea.gherzan@intel.com>
---
gdb/gdbserver/config.in | 3 +++
gdb/gdbserver/configure | 2 +-
gdb/gdbserver/configure.ac | 2 +-
gdb/gdbserver/server.c | 23 +++++++++++++++++++++++
4 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index 4a5a51d..5ed56c3 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -97,6 +97,9 @@
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
+/* Define to 1 if you have the `memmem' function. */
+#undef HAVE_MEMMEM
+
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index 5df8fe3..874a899 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -4795,7 +4795,7 @@ fi
done
-for ac_func in pread pwrite pread64 readlink fdwalk pipe2
+for ac_func in pread pwrite pread64 readlink fdwalk pipe2 memmem
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"
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 8142e91..7cbc6ea 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -70,7 +70,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 wait.h sys/un.h dnl
linux/perf_event.h sys/time.h sys/param.h)
-AC_CHECK_FUNCS(pread pwrite pread64 readlink fdwalk pipe2)
+AC_CHECK_FUNCS(pread pwrite pread64 readlink fdwalk pipe2 memmem)
AC_REPLACE_FUNCS(vasprintf vsnprintf)
# Check for UST
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 4a1d1dc..99c2229 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -761,6 +761,29 @@ gdb_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
}
}
+#ifndef HAVE_MEMMEM
+
+/* Find the NEEDLE in the HAYSTACK and return its position. */
+
+static void *
+memmem (const void *haystack, size_t haystack_len, const void *needle,
+ size_t needle_len)
+{
+ size_t i;
+ const gdb_byte *p;
+
+ for (i = 0; i <= haystack_len - needle_len; i++)
+ {
+ p = (gdb_byte *)haystack + i;
+ if (memcmp (p, needle, needle_len) == 0)
+ return p;
+ }
+
+ return NULL;
+}
+
+#endif
+
/* Subroutine of handle_search_memory to simplify it. */
static int
--
1.7.12.4