change delegation for to_read_description
authorTom Tromey <tromey@redhat.com>
Mon, 13 Jan 2014 16:30:30 +0000 (09:30 -0700)
committerTom Tromey <tromey@redhat.com>
Wed, 19 Feb 2014 14:48:41 +0000 (07:48 -0700)
This switches to_read_description to the "new normal" delegation
scheme.  This one was a bit trickier than the other changes due to the
way that target_read_description handled delegation.  I examined all
the target implementations of to_read_description and changed the ones
returning NULL to instead delegate.

2014-02-19  Tom Tromey  <tromey@redhat.com>

* arm-linux-nat.c (arm_linux_read_description): Delegate when
needed.
* corelow.c (core_read_description): Delegate when needed.
* remote.c (remote_read_description): Delegate when needed.
* target-delegates.c: Rebuild.
* target.c (target_read_description): Rewrite.
* target.h (struct target_ops) <to_read_description>: Update
comment.  Use TARGET_DEFAULT_RETURN.

gdb/ChangeLog
gdb/arm-linux-nat.c
gdb/corelow.c
gdb/remote.c
gdb/target-delegates.c
gdb/target.c
gdb/target.h

index 9db4fd456df3a13bf2a331e042e27f7282884456..37aa3bfb37a79667593775bee1b4bef86c2e2814 100644 (file)
@@ -1,3 +1,14 @@
+2014-02-19  Tom Tromey  <tromey@redhat.com>
+
+       * arm-linux-nat.c (arm_linux_read_description): Delegate when
+       needed.
+       * corelow.c (core_read_description): Delegate when needed.
+       * remote.c (remote_read_description): Delegate when needed.
+       * target-delegates.c: Rebuild.
+       * target.c (target_read_description): Rewrite.
+       * target.h (struct target_ops) <to_read_description>: Update
+       comment.  Use TARGET_DEFAULT_RETURN.
+
 2014-02-19  Tom Tromey  <tromey@redhat.com>
 
        * target-delegates.c: Rebuild.
index 75f58ca49799e2495902a1fcf9140edcb70bcbbc..a92642d0721c435ce8b68f9eed90eb3d175e1404 100644 (file)
@@ -636,7 +636,7 @@ arm_linux_read_description (struct target_ops *ops)
 
   if (target_auxv_search (ops, AT_HWCAP, &arm_hwcap) != 1)
     {
-      return NULL;
+      return ops->beneath->to_read_description (ops->beneath);
     }
 
   if (arm_hwcap & HWCAP_IWMMXT)
@@ -681,7 +681,7 @@ arm_linux_read_description (struct target_ops *ops)
       return result;
     }
 
-  return NULL;
+  return ops->beneath->to_read_description (ops->beneath);
 }
 
 /* Information describing the hardware breakpoint capabilities.  */
index 8a80be36ffa66912934e15acb6b6524a7b44431c..05c3e4ea0c6202320eac5e89167b75255c1230c1 100644 (file)
@@ -913,10 +913,16 @@ static const struct target_desc *
 core_read_description (struct target_ops *target)
 {
   if (core_gdbarch && gdbarch_core_read_description_p (core_gdbarch))
-    return gdbarch_core_read_description (core_gdbarch, 
-                                         target, core_bfd);
+    {
+      const struct target_desc *result;
+
+      result = gdbarch_core_read_description (core_gdbarch, 
+                                             target, core_bfd);
+      if (result != NULL)
+       return result;
+    }
 
-  return NULL;
+  return target->beneath->to_read_description (target->beneath);
 }
 
 static char *
index 2f079ca117adcef8a2cec052796c827432fbe164..537221aa436c6489fa3c99e856617fed8191cc38 100644 (file)
@@ -9434,7 +9434,7 @@ remote_read_description (struct target_ops *target)
   /* Do not try this during initial connection, when we do not know
      whether there is a running but stopped thread.  */
   if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
-    return NULL;
+    return target->beneath->to_read_description (target->beneath);
 
   if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
     {
@@ -9453,7 +9453,7 @@ remote_read_description (struct target_ops *target)
         an architecture, but it's too tricky to do safely.  */
     }
 
-  return NULL;
+  return target->beneath->to_read_description (target->beneath);
 }
 
 /* Remote file transfer support.  This is host-initiated I/O, not
index 0ffee5a8b2e4f7914cc68dfea2e0354428e4f572..4585d2592b8fdf811d3b6e5ec97709f9f3ddc0b9 100644 (file)
@@ -801,6 +801,19 @@ tdefault_flash_done (struct target_ops *self)
   tcomplain ();
 }
 
+static const struct target_desc *
+delegate_read_description (struct target_ops *self)
+{
+  self = self->beneath;
+  return self->to_read_description (self);
+}
+
+static const struct target_desc *
+tdefault_read_description (struct target_ops *self)
+{
+  return 0;
+}
+
 static ptid_t
 delegate_get_ada_task_ptid (struct target_ops *self, long arg1, long arg2)
 {
@@ -1700,6 +1713,8 @@ install_delegators (struct target_ops *ops)
     ops->to_flash_erase = delegate_flash_erase;
   if (ops->to_flash_done == NULL)
     ops->to_flash_done = delegate_flash_done;
+  if (ops->to_read_description == NULL)
+    ops->to_read_description = delegate_read_description;
   if (ops->to_get_ada_task_ptid == NULL)
     ops->to_get_ada_task_ptid = delegate_get_ada_task_ptid;
   if (ops->to_auxv_parse == NULL)
@@ -1896,6 +1911,7 @@ install_dummy_methods (struct target_ops *ops)
   ops->to_memory_map = tdefault_memory_map;
   ops->to_flash_erase = tdefault_flash_erase;
   ops->to_flash_done = tdefault_flash_done;
+  ops->to_read_description = tdefault_read_description;
   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;
index 13b2e65292593c8db8eafbaa6c429c4794ea032f..44387da3d68db201c44c9b76f7bbcb3b774422fd 100644 (file)
@@ -748,7 +748,6 @@ update_current_target (void)
            (int (*) (CORE_ADDR, gdb_byte *, int, int,
                      struct mem_attrib *, struct target_ops *))
            nomemory);
-  current_target.to_read_description = NULL;
 
 #undef de_fault
 
@@ -2630,19 +2629,7 @@ target_mourn_inferior (void)
 const struct target_desc *
 target_read_description (struct target_ops *target)
 {
-  struct target_ops *t;
-
-  for (t = target; t != NULL; t = t->beneath)
-    if (t->to_read_description != NULL)
-      {
-       const struct target_desc *tdesc;
-
-       tdesc = t->to_read_description (t);
-       if (tdesc)
-         return tdesc;
-      }
-
-  return NULL;
+  return target->to_read_description (target);
 }
 
 /* This implements a basic search of memory, reading target memory and
index ec15e5b0d4a25ce9132da3b644a1a3fa0e4e198b..34539c16ca55bd30d217ddf979d7f58715a3c3c0 100644 (file)
@@ -690,10 +690,12 @@ struct target_ops
     void (*to_flash_done) (struct target_ops *)
       TARGET_DEFAULT_NORETURN (tcomplain ());
 
-    /* Describe the architecture-specific features of this target.
-       Returns the description found, or NULL if no description
-       was available.  */
-    const struct target_desc *(*to_read_description) (struct target_ops *ops);
+    /* Describe the architecture-specific features of this target.  If
+       OPS doesn't have a description, this should delegate to the
+       "beneath" target.  Returns the description found, or NULL if no
+       description was available.  */
+    const struct target_desc *(*to_read_description) (struct target_ops *ops)
+        TARGET_DEFAULT_RETURN (0);
 
     /* Build the PTID of the thread on which a given task is running,
        based on LWP and THREAD.  These values are extracted from the