* target.h (struct section_table): Rename to ...
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
index c1816da67d9a8cf7ca64d13a05525d0bdd863c8c..c1ea9da3636cec98d6b05fdbede3a0ee9e441042 100644 (file)
@@ -1,7 +1,7 @@
 /* Dynamic architecture support for GDB, the GNU debugger.
 
    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-   2008 Free Software Foundation, Inc.
+   2008, 2009 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -146,7 +146,7 @@ core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
 /* Misc helper functions for targets. */
 
 CORE_ADDR
-core_addr_identity (CORE_ADDR addr)
+core_addr_identity (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   return addr;
 }
@@ -466,7 +466,19 @@ set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
 int
 gdbarch_update_p (struct gdbarch_info info)
 {
-  struct gdbarch *new_gdbarch = gdbarch_find_by_info (info);
+  struct gdbarch *new_gdbarch;
+
+  /* Check for the current file.  */
+  if (info.abfd == NULL)
+    info.abfd = exec_bfd;
+  if (info.abfd == NULL)
+    info.abfd = core_bfd;
+
+  /* Check for the current target description.  */
+  if (info.target_desc == NULL)
+    info.target_desc = target_current_description ();
+
+  new_gdbarch = gdbarch_find_by_info (info);
 
   /* If there no architecture by that name, reject the request.  */
   if (new_gdbarch == NULL)
@@ -479,12 +491,12 @@ gdbarch_update_p (struct gdbarch_info info)
 
   /* If it is the same old architecture, accept the request (but don't
      swap anything).  */
-  if (new_gdbarch == current_gdbarch)
+  if (new_gdbarch == target_gdbarch)
     {
       if (gdbarch_debug)
        fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
-                           "Architecture 0x%08lx (%s) unchanged\n",
-                           (long) new_gdbarch,
+                           "Architecture %s (%s) unchanged\n",
+                           host_address_to_string (new_gdbarch),
                            gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
       return 1;
     }
@@ -492,8 +504,8 @@ gdbarch_update_p (struct gdbarch_info info)
   /* It's a new architecture, swap it in.  */
   if (gdbarch_debug)
     fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
-                       "New architecture 0x%08lx (%s) selected\n",
-                       (long) new_gdbarch,
+                       "New architecture %s (%s) selected\n",
+                       host_address_to_string (new_gdbarch),
                        gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
   deprecated_current_gdbarch_select_hack (new_gdbarch);
 
@@ -507,14 +519,6 @@ struct gdbarch *
 gdbarch_from_bfd (bfd *abfd)
 {
   struct gdbarch_info info;
-
-  /* If we call gdbarch_find_by_info without filling in info.abfd,
-     then it will use the global exec_bfd.  That's fine if we don't
-     have one of those either.  And that's the only time we should
-     reach here with a NULL ABFD argument - when we are discarding
-     the executable.  */
-  gdb_assert (abfd != NULL || exec_bfd == NULL);
-
   gdbarch_info_init (&info);
   info.abfd = abfd;
   return gdbarch_find_by_info (info);
@@ -526,9 +530,14 @@ gdbarch_from_bfd (bfd *abfd)
 void
 set_gdbarch_from_file (bfd *abfd)
 {
+  struct gdbarch_info info;
   struct gdbarch *gdbarch;
 
-  gdbarch = gdbarch_from_bfd (abfd);
+  gdbarch_info_init (&info);
+  info.abfd = abfd;
+  info.target_desc = target_current_description ();
+  gdbarch = gdbarch_find_by_info (info);
+
   if (gdbarch == NULL)
     error (_("Architecture of file not recognized."));
   deprecated_current_gdbarch_select_hack (gdbarch);
@@ -620,6 +629,7 @@ initialize_current_architecture (void)
     }
 
   info.byte_order = default_byte_order;
+  info.byte_order_for_code = info.byte_order;
 
   if (! gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__,
@@ -658,6 +668,7 @@ gdbarch_info_init (struct gdbarch_info *info)
 {
   memset (info, 0, sizeof (struct gdbarch_info));
   info->byte_order = BFD_ENDIAN_UNKNOWN;
+  info->byte_order_for_code = info->byte_order;
   info->osabi = GDB_OSABI_UNINITIALIZED;
 }
 
@@ -668,16 +679,6 @@ gdbarch_info_init (struct gdbarch_info *info)
 void
 gdbarch_info_fill (struct gdbarch_info *info)
 {
-  /* Check for the current file.  */
-  if (info->abfd == NULL)
-    info->abfd = exec_bfd;
-  if (info->abfd == NULL)
-    info->abfd = core_bfd;
-
-  /* Check for the current target description.  */
-  if (info->target_desc == NULL)
-    info->target_desc = target_current_description ();
-
   /* "(gdb) set architecture ...".  */
   if (info->bfd_arch_info == NULL
       && target_architecture_user)
@@ -709,6 +710,7 @@ gdbarch_info_fill (struct gdbarch_info *info)
   /* From the default.  */
   if (info->byte_order == BFD_ENDIAN_UNKNOWN)
     info->byte_order = default_byte_order;
+  info->byte_order_for_code = info->byte_order;
 
   /* "(gdb) set osabi ...".  Handled by gdbarch_lookup_osabi.  */
   if (info->osabi == GDB_OSABI_UNINITIALIZED)
This page took 0.029311 seconds and 4 git commands to generate.