From 4a72de73660810536e9bb416d41dc8a6128f91da Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 7 Oct 2020 12:07:55 -0600 Subject: Move simple_search_memory to gdbsupport/search.cc This moves the simple_search_memory function to a new file, gdbsupport/search.cc. The API is slightly changed to make it more general. This generality is useful for wiring it to gdbserver, and also for unit testing. gdb/ChangeLog 2020-10-07 Tom Tromey * target.h (simple_search_memory): Don't declare. * target.c (simple_search_memory): Move to gdbsupport. (default_search_memory): Update. * remote.c (remote_target::search_memory): Update. gdbsupport/ChangeLog 2020-10-07 Tom Tromey * Makefile.in: Rebuild. * Makefile.am (libgdbsupport_a_SOURCES): Add search.cc. * search.h: New file. * search.cc: New file. --- gdb/remote.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'gdb/remote.c') diff --git a/gdb/remote.c b/gdb/remote.c index f951486..26ee28d 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -75,6 +75,7 @@ #include "gdbsupport/scoped_restore.h" #include "gdbsupport/environ.h" #include "gdbsupport/byte-vector.h" +#include "gdbsupport/search.h" #include #include #include "async-event.h" @@ -11186,6 +11187,12 @@ remote_target::search_memory (CORE_ADDR start_addr, ULONGEST search_space_len, int found; ULONGEST found_addr; + auto read_memory = [=] (CORE_ADDR addr, gdb_byte *result, size_t len) + { + return (target_read (this, TARGET_OBJECT_MEMORY, NULL, result, addr, len) + == len); + }; + /* Don't go to the target if we don't have to. This is done before checking packet_config_support to avoid the possibility that a success for this edge case means the facility works in @@ -11205,7 +11212,7 @@ remote_target::search_memory (CORE_ADDR start_addr, ULONGEST search_space_len, { /* Target doesn't provided special support, fall back and use the standard support (copy memory and do the search here). */ - return simple_search_memory (this, start_addr, search_space_len, + return simple_search_memory (read_memory, start_addr, search_space_len, pattern, pattern_len, found_addrp); } @@ -11237,7 +11244,7 @@ remote_target::search_memory (CORE_ADDR start_addr, ULONGEST search_space_len, supported. If so, fall back to the simple way. */ if (packet_config_support (packet) == PACKET_DISABLE) { - return simple_search_memory (this, start_addr, search_space_len, + return simple_search_memory (read_memory, start_addr, search_space_len, pattern, pattern_len, found_addrp); } return -1; -- cgit v1.1