2003-11-09 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / arch-utils.c
index 2c564e741f76879ee792a1925f3eac94c426bc79..9483b938377fa9e88f83bfb2550e34873788f06a 100644 (file)
@@ -31,6 +31,8 @@
 #include "gdb_assert.h"
 #include "sim-regno.h"
 
+#include "osabi.h"
+
 #include "version.h"
 
 #include "floatformat.h"
@@ -680,6 +682,54 @@ gdbarch_info_init (struct gdbarch_info *info)
   info->osabi = GDB_OSABI_UNINITIALIZED;
 }
 
+/* Similar it init, but this time fill in the blanks.  Information is
+   obtained from the specified architecture, global "set ..." options,
+   and explicitly initialized INFO fields.  */
+
+void
+gdbarch_info_fill (struct gdbarch *gdbarch, struct gdbarch_info *info)
+{
+  /* "(gdb) set architecture ...".  */
+  if (info->bfd_arch_info == NULL
+      && !target_architecture_auto
+      && gdbarch != NULL)
+    info->bfd_arch_info = gdbarch_bfd_arch_info (gdbarch);
+  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
+      && gdbarch != NULL)
+    info->bfd_arch_info = gdbarch_bfd_arch_info (gdbarch);
+
+  /* "(gdb) set byte-order ...".  */
+  if (info->byte_order == BFD_ENDIAN_UNKNOWN
+      && !target_byte_order_auto
+      && gdbarch != NULL)
+    info->byte_order = gdbarch_byte_order (gdbarch);
+  /* From the INFO struct.  */
+  if (info->byte_order == BFD_ENDIAN_UNKNOWN
+      && info->abfd != NULL)
+    info->byte_order = (bfd_big_endian (info->abfd) ? BFD_ENDIAN_BIG
+                      : bfd_little_endian (info->abfd) ? BFD_ENDIAN_LITTLE
+                      : BFD_ENDIAN_UNKNOWN);
+  /* From the current target.  */
+  if (info->byte_order == BFD_ENDIAN_UNKNOWN
+      && gdbarch != NULL)
+    info->byte_order = gdbarch_byte_order (gdbarch);
+
+  /* "(gdb) set osabi ...".  Handled by gdbarch_lookup_osabi.  */
+  if (info->osabi == GDB_OSABI_UNINITIALIZED)
+    info->osabi = gdbarch_lookup_osabi (info->abfd);
+  if (info->osabi == GDB_OSABI_UNINITIALIZED
+      && gdbarch != NULL)
+    info->osabi = gdbarch_osabi (gdbarch);
+
+  /* Must have at least filled in the architecture.  */
+  gdb_assert (info->bfd_arch_info != NULL);
+}
+
 /* */
 
 extern initialize_file_ftype _initialize_gdbarch_utils; /* -Wmissing-prototypes */
This page took 0.024831 seconds and 4 git commands to generate.