Fix logic selecting a new architecture. Use the sequence:
authorAndrew Cagney <cagney@redhat.com>
Mon, 14 May 2001 16:43:35 +0000 (16:43 +0000)
committerAndrew Cagney <cagney@redhat.com>
Mon, 14 May 2001 16:43:35 +0000 (16:43 +0000)
o provided by INFO
o hard-wired by (gdb) set ...
o reversed engineered from INFO.abfd
o default to previous architecture

gdb/ChangeLog
gdb/gdbarch.c
gdb/gdbarch.h
gdb/gdbarch.sh
gdb/rs6000-tdep.c

index 022495de0f432042e9435a140c7db76363e3a9ec..7ba341631f8c3752ebbf971e236b8bdbca93377c 100644 (file)
@@ -1,3 +1,12 @@
+2001-05-12  Andrew Cagney  <ac131313@redhat.com>
+
+       * gdbarch.sh (struct gdbarch_info): Delete field bfd_architecture.
+       (gdbarch_update_p): Rewrite logic filling in INFO struct.  Use
+       user specified values when available.
+       * rs6000-tdep.c (rs6000_gdbarch_init): Update.  Get the
+       architecture from info.bfd_arch_info.
+       * gdbarch.c, gdbarch.h: Regenerate.
+
 2001-05-12  Fernando Nasser  <fnasser@redhat.com>
 
        * remote-e7000.c (e7000_open): Check for bad baud rate.
index bc2070a5666fb135182a813095807dabbcd88529..2bd957f6e018a66e80b7a73eb9c195a8b413a91a 100644 (file)
@@ -4644,56 +4644,40 @@ gdbarch_update_p (struct gdbarch_info info)
   struct gdbarch_list **list;
   struct gdbarch_registration *rego;
 
-  /* Fill in any missing bits. Most important is the bfd_architecture
-     which is used to select the target architecture. */
-  if (info.bfd_architecture == bfd_arch_unknown)
-    {
-      if (info.bfd_arch_info != NULL)
-       info.bfd_architecture = info.bfd_arch_info->arch;
-      else if (info.abfd != NULL)
-       info.bfd_architecture = bfd_get_arch (info.abfd);
-      /* FIXME - should query BFD for its default architecture. */
-      else
-       info.bfd_architecture = current_gdbarch->bfd_arch_info->arch;
-    }
+  /* Fill in missing parts of the INFO struct using a number of
+     sources: ``set ...''; INFOabfd supplied; existing target.  */
+
+  /* ``(gdb) set architecture ...'' */
+  if (info.bfd_arch_info == NULL
+      && !TARGET_ARCHITECTURE_AUTO)
+    info.bfd_arch_info = TARGET_ARCHITECTURE;
+  if (info.bfd_arch_info == NULL
+      && info.abfd != NULL
+      && bfd_get_arch (info.abfd) != bfd_arch_unknown
+      && bfd_get_arch (info.abfd) != bfd_arch_obscure)
+    info.bfd_arch_info = bfd_get_arch_info (info.abfd);
   if (info.bfd_arch_info == NULL)
-    {
-      if (target_architecture_auto && info.abfd != NULL)
-       info.bfd_arch_info = bfd_get_arch_info (info.abfd);
-      else
-       info.bfd_arch_info = current_gdbarch->bfd_arch_info;
-    }
+    info.bfd_arch_info = TARGET_ARCHITECTURE;
+
+  /* ``(gdb) set byte-order ...'' */
+  if (info.byte_order == 0
+      && !TARGET_BYTE_ORDER_AUTO)
+    info.byte_order = TARGET_BYTE_ORDER;
+  /* From the INFO struct. */
+  if (info.byte_order == 0
+      && info.abfd != NULL)
+    info.byte_order = (bfd_big_endian (info.abfd) ? BIG_ENDIAN
+                      : bfd_little_endian (info.abfd) ? LITTLE_ENDIAN
+                      : 0);
+  /* From the current target. */
   if (info.byte_order == 0)
-    {
-      if (target_byte_order_auto && info.abfd != NULL)
-       info.byte_order = (bfd_big_endian (info.abfd) ? BIG_ENDIAN
-                          : bfd_little_endian (info.abfd) ? LITTLE_ENDIAN
-                          : 0);
-      else
-       info.byte_order = current_gdbarch->byte_order;
-      /* FIXME - should query BFD for its default byte-order. */
-    }
-  /* A default for abfd? */
+    info.byte_order = TARGET_BYTE_ORDER;
 
-  /* Find the target that knows about this architecture. */
-  for (rego = gdbarch_registry;
-       rego != NULL;
-       rego = rego->next)
-    if (rego->bfd_architecture == info.bfd_architecture)
-      break;
-  if (rego == NULL)
-    {
-      if (gdbarch_debug)
-       fprintf_unfiltered (gdb_stdlog, "gdbarch_update: No matching architecture\n");
-      return 0;
-    }
+  /* Must have found some sort of architecture. */
+  gdb_assert (info.bfd_arch_info != NULL);
 
   if (gdbarch_debug)
     {
-      fprintf_unfiltered (gdb_stdlog,
-                         "gdbarch_update: info.bfd_architecture %d (%s)\n",
-                         info.bfd_architecture,
-                         bfd_lookup_arch (info.bfd_architecture, 0)->printable_name);
       fprintf_unfiltered (gdb_stdlog,
                          "gdbarch_update: info.bfd_arch_info %s\n",
                          (info.bfd_arch_info != NULL
@@ -4713,6 +4697,19 @@ gdbarch_update_p (struct gdbarch_info info)
                          (long) info.tdep_info);
     }
 
+  /* Find the target that knows about this architecture. */
+  for (rego = gdbarch_registry;
+       rego != NULL;
+       rego = rego->next)
+    if (rego->bfd_architecture == info.bfd_arch_info->arch)
+      break;
+  if (rego == NULL)
+    {
+      if (gdbarch_debug)
+       fprintf_unfiltered (gdb_stdlog, "gdbarch_update: No matching architecture\n");
+      return 0;
+    }
+
   /* Ask the target for a replacement architecture. */
   new_gdbarch = rego->init (info, rego->arches);
 
index e2982746794e6073b5a008665d7f598380c2bdfd..5b2bcacdfd504785a4ef4e59f9688c92e918ec2b 100644 (file)
@@ -1607,9 +1607,6 @@ struct gdbarch_list
 
 struct gdbarch_info
 {
-  /* Use default: bfd_arch_unknown (ZERO). */
-  enum bfd_architecture bfd_architecture;
-
   /* Use default: NULL (ZERO). */
   const struct bfd_arch_info *bfd_arch_info;
 
@@ -1663,16 +1660,12 @@ extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gd
 extern void gdbarch_free (struct gdbarch *);
 
 
-/* Helper function. Force an update of the current architecture.  Used
-   by legacy targets that have added their own target specific
-   architecture manipulation commands.
+/* Helper function. Force an update of the current architecture.
 
-   The INFO parameter shall be fully initialized (``memset (&INFO,
-   sizeof (info), 0)'' set relevant fields) before gdbarch_update_p()
-   is called.  gdbarch_update_p() shall initialize any ``default''
-   fields using information obtained from the previous architecture or
-   INFO.ABFD (if specified) before calling the corresponding
-   architectures INIT function.
+   The actual architecture selected is determined by INFO, ``(gdb) set
+   architecture'' et.al., the existing architecture and BFD's default
+   architecture.  INFO should be initialized to zero and then selected
+   fields should be updated.
 
    Returns non-zero if the update succeeds */
 
index ed7b878be07ef5c0239e146f777e20928e9c92c5..14e88c30a83f12724de977dca7877379427805f9 100755 (executable)
@@ -838,9 +838,6 @@ struct gdbarch_list
 
 struct gdbarch_info
 {
-  /* Use default: bfd_arch_unknown (ZERO). */
-  enum bfd_architecture bfd_architecture;
-
   /* Use default: NULL (ZERO). */
   const struct bfd_arch_info *bfd_arch_info;
 
@@ -894,16 +891,12 @@ extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gd
 extern void gdbarch_free (struct gdbarch *);
 
 
-/* Helper function. Force an update of the current architecture.  Used
-   by legacy targets that have added their own target specific
-   architecture manipulation commands.
+/* Helper function. Force an update of the current architecture.
 
-   The INFO parameter shall be fully initialized (\`\`memset (&INFO,
-   sizeof (info), 0)'' set relevant fields) before gdbarch_update_p()
-   is called.  gdbarch_update_p() shall initialize any \`\`default''
-   fields using information obtained from the previous architecture or
-   INFO.ABFD (if specified) before calling the corresponding
-   architectures INIT function.
+   The actual architecture selected is determined by INFO, \`\`(gdb) set
+   architecture'' et.al., the existing architecture and BFD's default
+   architecture.  INFO should be initialized to zero and then selected
+   fields should be updated.
 
    Returns non-zero if the update succeeds */
 
@@ -1945,75 +1938,72 @@ gdbarch_update_p (struct gdbarch_info info)
   struct gdbarch_list **list;
   struct gdbarch_registration *rego;
 
-  /* Fill in any missing bits. Most important is the bfd_architecture
-     which is used to select the target architecture. */
-  if (info.bfd_architecture == bfd_arch_unknown)
-    {
-      if (info.bfd_arch_info != NULL)
-       info.bfd_architecture = info.bfd_arch_info->arch;
-      else if (info.abfd != NULL)
-       info.bfd_architecture = bfd_get_arch (info.abfd);
-      /* FIXME - should query BFD for its default architecture. */
-      else
-       info.bfd_architecture = current_gdbarch->bfd_arch_info->arch;
-    }
+  /* Fill in missing parts of the INFO struct using a number of
+     sources: \`\`set ...''; INFOabfd supplied; existing target.  */
+
+  /* \`\`(gdb) set architecture ...'' */
+  if (info.bfd_arch_info == NULL
+      && !TARGET_ARCHITECTURE_AUTO)
+    info.bfd_arch_info = TARGET_ARCHITECTURE;
+  if (info.bfd_arch_info == NULL
+      && info.abfd != NULL
+      && bfd_get_arch (info.abfd) != bfd_arch_unknown
+      && bfd_get_arch (info.abfd) != bfd_arch_obscure)
+    info.bfd_arch_info = bfd_get_arch_info (info.abfd);
   if (info.bfd_arch_info == NULL)
-    {
-      if (target_architecture_auto && info.abfd != NULL)
-       info.bfd_arch_info = bfd_get_arch_info (info.abfd);
-      else
-       info.bfd_arch_info = current_gdbarch->bfd_arch_info;
-    }
+    info.bfd_arch_info = TARGET_ARCHITECTURE;
+
+  /* \`\`(gdb) set byte-order ...'' */
+  if (info.byte_order == 0
+      && !TARGET_BYTE_ORDER_AUTO)
+    info.byte_order = TARGET_BYTE_ORDER;
+  /* From the INFO struct. */
+  if (info.byte_order == 0
+      && info.abfd != NULL)
+    info.byte_order = (bfd_big_endian (info.abfd) ? BIG_ENDIAN
+                      : bfd_little_endian (info.abfd) ? LITTLE_ENDIAN
+                      : 0);
+  /* From the current target. */
   if (info.byte_order == 0)
-    {
-      if (target_byte_order_auto && info.abfd != NULL)
-       info.byte_order = (bfd_big_endian (info.abfd) ? BIG_ENDIAN
-                          : bfd_little_endian (info.abfd) ? LITTLE_ENDIAN
-                          : 0);
-      else
-       info.byte_order = current_gdbarch->byte_order;
-      /* FIXME - should query BFD for its default byte-order. */
-    }
-  /* A default for abfd? */
+    info.byte_order = TARGET_BYTE_ORDER;
 
-  /* Find the target that knows about this architecture. */
-  for (rego = gdbarch_registry;
-       rego != NULL;
-       rego = rego->next)
-    if (rego->bfd_architecture == info.bfd_architecture)
-      break;
-  if (rego == NULL)
-    {
-      if (gdbarch_debug)
-       fprintf_unfiltered (gdb_stdlog, "gdbarch_update: No matching architecture\\n");
-      return 0;
-    }
+  /* Must have found some sort of architecture. */
+  gdb_assert (info.bfd_arch_info != NULL);
 
   if (gdbarch_debug)
     {
       fprintf_unfiltered (gdb_stdlog,
-                         "gdbarch_update: info.bfd_architecture %d (%s)\\n",
-                         info.bfd_architecture,
-                         bfd_lookup_arch (info.bfd_architecture, 0)->printable_name);
-      fprintf_unfiltered (gdb_stdlog,
-                         "gdbarch_update: info.bfd_arch_info %s\\n",
+                         "gdbarch_update: info.bfd_arch_info %s\n",
                          (info.bfd_arch_info != NULL
                           ? info.bfd_arch_info->printable_name
                           : "(null)"));
       fprintf_unfiltered (gdb_stdlog,
-                         "gdbarch_update: info.byte_order %d (%s)\\n",
+                         "gdbarch_update: info.byte_order %d (%s)\n",
                          info.byte_order,
                          (info.byte_order == BIG_ENDIAN ? "big"
                           : info.byte_order == LITTLE_ENDIAN ? "little"
                           : "default"));
       fprintf_unfiltered (gdb_stdlog,
-                         "gdbarch_update: info.abfd 0x%lx\\n",
+                         "gdbarch_update: info.abfd 0x%lx\n",
                          (long) info.abfd);
       fprintf_unfiltered (gdb_stdlog,
-                         "gdbarch_update: info.tdep_info 0x%lx\\n",
+                         "gdbarch_update: info.tdep_info 0x%lx\n",
                          (long) info.tdep_info);
     }
 
+  /* Find the target that knows about this architecture. */
+  for (rego = gdbarch_registry;
+       rego != NULL;
+       rego = rego->next)
+    if (rego->bfd_architecture == info.bfd_arch_info->arch)
+      break;
+  if (rego == NULL)
+    {
+      if (gdbarch_debug)
+       fprintf_unfiltered (gdb_stdlog, "gdbarch_update: No matching architecture\\n");
+      return 0;
+    }
+
   /* Ask the target for a replacement architecture. */
   new_gdbarch = rego->init (info, rego->arches);
 
index 3c0a7b9ad5aef076acfe7950116d9e9996abbca7..864345dd17728e872a0113333501b6c8abf868a2 100644 (file)
@@ -2210,7 +2210,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   if (!from_xcoff_exec)
     {
-      arch = info.bfd_architecture;
+      arch = info.bfd_arch_info->arch;
       mach = info.bfd_arch_info->mach;
     }
   else