(m32r_handle_align): Declare type of fragp.
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
index d604bd4b020bedaca82ae3d0726c402bc84b7e7c..00aad2f7e2653d0b85071021c6d64c1a8dc599f1 100644 (file)
@@ -41,6 +41,8 @@
 #include "symfile.h"           /* for overlay functions */
 #endif
 
+#include "version.h"
+
 #include "floatformat.h"
 
 /* Convenience macro for allocting typesafe memory. */
@@ -149,17 +151,13 @@ generic_prologue_frameless_p (CORE_ADDR ip)
 /* Helper functions for INNER_THAN */
 
 int
-core_addr_lessthan (lhs, rhs)
-     CORE_ADDR lhs;
-     CORE_ADDR rhs;
+core_addr_lessthan (CORE_ADDR lhs, CORE_ADDR rhs)
 {
   return (lhs < rhs);
 }
 
 int
-core_addr_greaterthan (lhs, rhs)
-     CORE_ADDR lhs;
-     CORE_ADDR rhs;
+core_addr_greaterthan (CORE_ADDR lhs, CORE_ADDR rhs)
 {
   return (lhs > rhs);
 }
@@ -209,21 +207,45 @@ default_double_format (struct gdbarch *gdbarch)
 /* Misc helper functions for targets. */
 
 int
-frame_num_args_unknown (fi)
-     struct frame_info *fi;
+frame_num_args_unknown (struct frame_info *fi)
 {
   return -1;
 }
 
 
 int
-generic_register_convertible_not (num)
-     int num;
+generic_register_convertible_not (int num)
 {
   return 0;
 }
   
 
+int
+default_register_sim_regno (int num)
+{
+  return num;
+}
+
+
+CORE_ADDR
+default_convert_from_func_ptr_addr (CORE_ADDR addr)
+{
+  return addr;
+}
+
+int
+no_op_reg_to_regnum (int reg)
+{
+  return reg;
+}
+
+/* For use by frame_args_address and frame_locals_address.  */
+CORE_ADDR
+default_frame_address (struct frame_info *fi)
+{
+  return fi->frame;
+}
+
 /* Functions to manipulate the endianness of the target.  */
 
 #ifdef TARGET_BYTE_ORDER_SELECTABLE
@@ -246,20 +268,23 @@ generic_register_convertible_not (num)
 #ifndef TARGET_BYTE_ORDER_DEFAULT
 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */
 #endif
+/* ``target_byte_order'' is only used when non- multi-arch.
+   Multi-arch targets obtain the current byte order using
+   TARGET_BYTE_ORDER which is controlled by gdbarch.*. */
 int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
 int target_byte_order_auto = 1;
 
-static char endian_big[] = "big";
-static char endian_little[] = "little";
-static char endian_auto[] = "auto";
-static char *endian_enum[] =
+static const char endian_big[] = "big";
+static const char endian_little[] = "little";
+static const char endian_auto[] = "auto";
+static const char *endian_enum[] =
 {
   endian_big,
   endian_little,
   endian_auto,
   NULL,
 };
-static char *set_endian_string;
+static const char *set_endian_string;
 
 /* Called by ``show endian''.  */
 
@@ -287,26 +312,38 @@ set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
     }
   else if (set_endian_string == endian_little)
     {
-      target_byte_order = LITTLE_ENDIAN;
       target_byte_order_auto = 0;
       if (GDB_MULTI_ARCH)
        {
          struct gdbarch_info info;
          memset (&info, 0, sizeof info);
          info.byte_order = LITTLE_ENDIAN;
-         gdbarch_update (info);
+         if (! gdbarch_update_p (info))
+           {
+             printf_unfiltered ("Little endian target not supported by GDB\n");
+           }
+       }
+      else
+       {
+         target_byte_order = LITTLE_ENDIAN;
        }
     }
   else if (set_endian_string == endian_big)
     {
-      target_byte_order = BIG_ENDIAN;
       target_byte_order_auto = 0;
       if (GDB_MULTI_ARCH)
        {
          struct gdbarch_info info;
          memset (&info, 0, sizeof info);
          info.byte_order = BIG_ENDIAN;
-         gdbarch_update (info);
+         if (! gdbarch_update_p (info))
+           {
+             printf_unfiltered ("Big endian target not supported by GDB\n");
+           }
+       }
+      else
+       {
+         target_byte_order = BIG_ENDIAN;
        }
     }
   else
@@ -319,6 +356,8 @@ set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
 static void
 set_endian_from_file (bfd *abfd)
 {
+  if (GDB_MULTI_ARCH)
+    internal_error ("set_endian_from_file: not for multi-arch");
   if (TARGET_BYTE_ORDER_SELECTABLE_P)
     {
       int want;
@@ -352,7 +391,7 @@ enum set_arch { set_arch_auto, set_arch_manual };
 
 int target_architecture_auto = 1;
 
-char *set_architecture_string;
+const char *set_architecture_string;
 
 /* Old way of changing the current architecture. */
 
@@ -400,7 +439,7 @@ set_arch (const struct bfd_arch_info *arch,
       break;
     }
   if (gdbarch_debug)
-    gdbarch_dump ();
+    gdbarch_dump (current_gdbarch, gdb_stdlog);
 }
 
 /* Set the architecture from arch/machine (deprecated) */
@@ -415,7 +454,7 @@ set_architecture_from_arch_mach (enum bfd_architecture arch,
   if (wanted != NULL)
     set_arch (wanted, set_arch_manual);
   else
-    internal_error ("gdbarch: hardwired architecture/machine not reconized");
+    internal_error ("gdbarch: hardwired architecture/machine not recognized");
 }
 
 /* Set the architecture from a BFD (deprecated) */
@@ -471,10 +510,10 @@ set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
       info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
       if (info.bfd_arch_info == NULL)
        internal_error ("set_architecture: bfd_scan_arch failed");
-      if (gdbarch_update (info))
+      if (gdbarch_update_p (info))
        target_architecture_auto = 0;
       else
-       printf_unfiltered ("Architecture `%s' not reconized.\n",
+       printf_unfiltered ("Architecture `%s' not recognized.\n",
                           set_architecture_string);
     }
   else
@@ -502,7 +541,7 @@ info_architecture (char *args, int from_tty)
        {
          printf_filtered (" %s", *arch);
        }
-      free (arches);
+      xfree (arches);
     }
   else
     {
@@ -522,19 +561,19 @@ info_architecture (char *args, int from_tty)
   printf_filtered ("\n");
 }
 
-/* Set the dynamic target-system-dependant parameters (architecture,
+/* Set the dynamic target-system-dependent parameters (architecture,
    byte-order) using information found in the BFD */
 
 void
-set_gdbarch_from_file (abfd)
-     bfd *abfd;
+set_gdbarch_from_file (bfd *abfd)
 {
   if (GDB_MULTI_ARCH)
     {
       struct gdbarch_info info;
       memset (&info, 0, sizeof info);
       info.abfd = abfd;
-      gdbarch_update (info);
+      if (! gdbarch_update_p (info))
+       error ("Architecture of file not recognized.\n");
     }
   else
     {
@@ -547,32 +586,96 @@ set_gdbarch_from_file (abfd)
    architecture'' command so that it specifies a list of valid
    architectures.  */
 
+#ifdef DEFAULT_BFD_ARCH
+extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
+static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;
+#else
+static const bfd_arch_info_type *default_bfd_arch;
+#endif
+
+#ifdef DEFAULT_BFD_VEC
+extern const bfd_target DEFAULT_BFD_VEC;
+static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;
+#else
+static const bfd_target *default_bfd_vec;
+#endif
+
 void
 initialize_current_architecture (void)
 {
   const char **arches = gdbarch_printable_names ();
-  const char *chosen = arches[0];
 
-  if (GDB_MULTI_ARCH)
+  /* determine a default architecture and byte order. */
+  struct gdbarch_info info;
+  memset (&info, 0, sizeof (info));
+  
+  /* Find a default architecture. */
+  if (info.bfd_arch_info == NULL
+      && default_bfd_arch != NULL)
+    info.bfd_arch_info = default_bfd_arch;
+  if (info.bfd_arch_info == NULL)
     {
+      /* Choose the architecture by taking the first one
+        alphabetically. */
+      const char *chosen = arches[0];
       const char **arch;
-      struct gdbarch_info info;
       for (arch = arches; *arch != NULL; arch++)
        {
-         /* Choose the first architecture alphabetically.  */
          if (strcmp (*arch, chosen) < 0)
            chosen = *arch;
        }
       if (chosen == NULL)
        internal_error ("initialize_current_architecture: No arch");
-      memset (&info, 0, sizeof info);
       info.bfd_arch_info = bfd_scan_arch (chosen);
       if (info.bfd_arch_info == NULL)
        internal_error ("initialize_current_architecture: Arch not found");
-      gdbarch_update (info);
     }
 
-  /* Create the ``set architecture'' command prepending ``auto''. */
+  /* take several guesses at a byte order. */
+  /* NB: can't use TARGET_BYTE_ORDER_DEFAULT as its definition is
+     forced above. */
+  if (info.byte_order == 0
+      && default_bfd_vec != NULL)
+    {
+      /* Extract BFD's default vector's byte order. */
+      switch (default_bfd_vec->byteorder)
+       {
+       case BFD_ENDIAN_BIG:
+         info.byte_order = BIG_ENDIAN;
+         break;
+       case BFD_ENDIAN_LITTLE:
+         info.byte_order = LITTLE_ENDIAN;
+         break;
+       default:
+         break;
+       }
+    }
+  if (info.byte_order == 0)
+    {
+      /* look for ``*el-*'' in the target name. */
+      const char *chp;
+      chp = strchr (target_name, '-');
+      if (chp != NULL
+         && chp - 2 >= target_name
+         && strncmp (chp - 2, "el", 2) == 0)
+       info.byte_order = LITTLE_ENDIAN;
+    }
+  if (info.byte_order == 0)
+    {
+      /* Wire it to big-endian!!! */
+      info.byte_order = BIG_ENDIAN;
+    }
+
+  if (GDB_MULTI_ARCH)
+    {
+      if (! gdbarch_update_p (info))
+       {
+         internal_error ("initialize_current_architecture: Selection of initial architecture failed");
+       }
+    }
+
+  /* Create the ``set architecture'' command appending ``auto'' to the
+     list of architectures. */
   {
     struct cmd_list_element *c;
     /* Append ``auto''. */
@@ -585,7 +688,7 @@ initialize_current_architecture (void)
        of ``const char *''.  We just happen to know that the casts are
        safe. */
     c = add_set_enum_cmd ("architecture", class_support,
-                         (char **) arches, (char **) &set_architecture_string,
+                         arches, &set_architecture_string,
                          "Set architecture of target.",
                          &setlist);
     c->function.sfunc = set_architecture;
This page took 0.027737 seconds and 4 git commands to generate.