convert to_search_memory
authorTom Tromey <tromey@redhat.com>
Thu, 19 Dec 2013 15:12:26 +0000 (08:12 -0700)
committerTom Tromey <tromey@redhat.com>
Wed, 19 Feb 2014 14:48:34 +0000 (07:48 -0700)
2014-02-19  Tom Tromey  <tromey@redhat.com>

* target-delegates.c: Rebuild.
* target.c (default_search_memory): New function.
(simple_search_memory): Update comment.
(target_search_memory): Unconditionally delegate.
* target.h (struct target_ops) <to_search_memory>: Use
TARGET_DEFAULT_FUNC.

gdb/ChangeLog
gdb/target-delegates.c
gdb/target.c
gdb/target.h

index 9c485b7c58302c65e73a455a75000697973e237f..c6cb8b1268d3ac01ea54e0b555fac99733afeb94 100644 (file)
@@ -1,3 +1,12 @@
+2014-02-19  Tom Tromey  <tromey@redhat.com>
+
+       * target-delegates.c: Rebuild.
+       * target.c (default_search_memory): New function.
+       (simple_search_memory): Update comment.
+       (target_search_memory): Unconditionally delegate.
+       * target.h (struct target_ops) <to_search_memory>: Use
+       TARGET_DEFAULT_FUNC.
+
 2014-02-19  Tom Tromey  <tromey@redhat.com>
 
        * auxv.c (default_auxv_parse): No longer static.
index cf5e2d3be956979d66621ff291ae737b7ffa3c36..e0c78333e773572d99c174b4dea29466ae7c83c7 100644 (file)
@@ -789,6 +789,13 @@ delegate_auxv_parse (struct target_ops *self, gdb_byte **arg1, gdb_byte *arg2, C
   return self->to_auxv_parse (self, arg1, arg2, arg3, arg4);
 }
 
+static int
+delegate_search_memory (struct target_ops *self, CORE_ADDR arg1, ULONGEST arg2, const gdb_byte *arg3, ULONGEST arg4, CORE_ADDR *arg5)
+{
+  self = self->beneath;
+  return self->to_search_memory (self, arg1, arg2, arg3, arg4, arg5);
+}
+
 static int
 delegate_can_execute_reverse (struct target_ops *self)
 {
@@ -1603,6 +1610,8 @@ install_delegators (struct target_ops *ops)
     ops->to_get_ada_task_ptid = delegate_get_ada_task_ptid;
   if (ops->to_auxv_parse == NULL)
     ops->to_auxv_parse = delegate_auxv_parse;
+  if (ops->to_search_memory == NULL)
+    ops->to_search_memory = delegate_search_memory;
   if (ops->to_can_execute_reverse == NULL)
     ops->to_can_execute_reverse = delegate_can_execute_reverse;
   if (ops->to_execution_direction == NULL)
@@ -1783,6 +1792,7 @@ install_dummy_methods (struct target_ops *ops)
   ops->to_flash_done = tdefault_flash_done;
   ops->to_get_ada_task_ptid = default_get_ada_task_ptid;
   ops->to_auxv_parse = default_auxv_parse;
+  ops->to_search_memory = default_search_memory;
   ops->to_can_execute_reverse = tdefault_can_execute_reverse;
   ops->to_execution_direction = default_execution_direction;
   ops->to_supports_multi_process = tdefault_supports_multi_process;
index 4b5ec43d113bdb1fde760da574ebfdb3cca1bf33..92be667a93c4e81fc7dd123cd441ebf1d027ad9e 100644 (file)
@@ -66,6 +66,13 @@ static int default_follow_fork (struct target_ops *self, int follow_child,
 
 static void default_mourn_inferior (struct target_ops *self);
 
+static int default_search_memory (struct target_ops *ops,
+                                 CORE_ADDR start_addr,
+                                 ULONGEST search_space_len,
+                                 const gdb_byte *pattern,
+                                 ULONGEST pattern_len,
+                                 CORE_ADDR *found_addrp);
+
 static void tcomplain (void) ATTRIBUTE_NORETURN;
 
 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
@@ -2650,8 +2657,7 @@ target_read_description (struct target_ops *target)
   return NULL;
 }
 
-/* The default implementation of to_search_memory.
-   This implements a basic search of memory, reading target memory and
+/* This implements a basic search of memory, reading target memory and
    performing the search here (as opposed to performing the search in on the
    target side with, for example, gdbserver).  */
 
@@ -2758,6 +2764,20 @@ simple_search_memory (struct target_ops *ops,
   return 0;
 }
 
+/* Default implementation of memory-searching.  */
+
+static int
+default_search_memory (struct target_ops *self,
+                      CORE_ADDR start_addr, ULONGEST search_space_len,
+                      const gdb_byte *pattern, ULONGEST pattern_len,
+                      CORE_ADDR *found_addrp)
+{
+  /* Start over from the top of the target stack.  */
+  return simple_search_memory (current_target.beneath,
+                              start_addr, search_space_len,
+                              pattern, pattern_len, found_addrp);
+}
+
 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
    sequence of bytes in PATTERN with length PATTERN_LEN.
 
@@ -2770,34 +2790,15 @@ target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
                      const gdb_byte *pattern, ULONGEST pattern_len,
                      CORE_ADDR *found_addrp)
 {
-  struct target_ops *t;
   int found;
 
-  /* We don't use INHERIT to set current_target.to_search_memory,
-     so we have to scan the target stack and handle targetdebug
-     ourselves.  */
-
   if (targetdebug)
     fprintf_unfiltered (gdb_stdlog, "target_search_memory (%s, ...)\n",
                        hex_string (start_addr));
 
-  for (t = current_target.beneath; t != NULL; t = t->beneath)
-    if (t->to_search_memory != NULL)
-      break;
-
-  if (t != NULL)
-    {
-      found = t->to_search_memory (t, start_addr, search_space_len,
-                                  pattern, pattern_len, found_addrp);
-    }
-  else
-    {
-      /* If a special version of to_search_memory isn't available, use the
-        simple version.  */
-      found = simple_search_memory (current_target.beneath,
-                                   start_addr, search_space_len,
-                                   pattern, pattern_len, found_addrp);
-    }
+  found = current_target.to_search_memory (&current_target, start_addr,
+                                          search_space_len,
+                                          pattern, pattern_len, found_addrp);
 
   if (targetdebug)
     fprintf_unfiltered (gdb_stdlog, "  = %d\n", found);
index 296ab109bf652b2e3b008f2032f4be740b6ac2ea..4474f431dce4a522d9c7bec531e23325aa1a1515 100644 (file)
@@ -718,7 +718,8 @@ struct target_ops
     int (*to_search_memory) (struct target_ops *ops,
                             CORE_ADDR start_addr, ULONGEST search_space_len,
                             const gdb_byte *pattern, ULONGEST pattern_len,
-                            CORE_ADDR *found_addrp);
+                            CORE_ADDR *found_addrp)
+      TARGET_DEFAULT_FUNC (default_search_memory);
 
     /* Can target execute in reverse?  */
     int (*to_can_execute_reverse) (struct target_ops *)