Better way to get the arch/endianess?

Andrew Cagney ac131313@cygnus.com
Wed Jun 7 05:42:00 GMT 2000


Hello,

When GDB first starts it needs to select a default
architecture/byte-order from the list that it (and BFD) support.  One
obvious way of doing it is to extract that information from BFD. 
Unfortunatly it turns out that extracting teeth is probably easier.

Looking at GAS, I've noticed that it has its own private lookup table in
configure.in.
Looking at the exiting bfd.h interface I can't find anything useful - I
couldn't for instance see how to create a default bfd out of nothing :-/
(1).

Attatched are extracts from the technique I'm using at present.  I'm
wondering if there isn't a better way - something that just returned the
default configured architecture and byte order.

Suggestions?

	Andrew


--

First, configure.in calls config.bfd to find out what it has selected
for the default vec and default architecture:

*** configure.in        2000/06/07 01:14:07     1.33
--- configure.in        2000/06/07 12:26:04
*************** changequote(,)dnl
*** 71,78 ****
--- 71,91 ----
  
  . ${srcdir}/configure.tgt
  
+ targ=${target} ; . ${srcdir}/../bfd/config.bfd
+ 
  dnl
  changequote([,])dnl
+ 
+ dnl use BFD to determine the default architecture and byte order
+ dnl (bfd_vec->byteorder provides the latter).
+ targ=${target}
+ . ${srcdir}/../bfd/config.bfd
+ if test x"${targ_archs}" != x ; then
+     AC_DEFINE_UNQUOTED(DEFAULT_BFD_ARCH, ${targ_archs})
+ fi
+ if test x"${targ_defvec}" != x ; then
+     AC_DEFINE_UNQUOTED(DEFAULT_BFD_VEC, ${targ_defvec})
+ fi
  
  AC_PROG_AWK
  AC_PROG_INSTALL


next arch-utils grubs around in those two entries to extract the
architecture (DEFAULT_BFD_ARCH) and byte-order
(DEFAULT_BFD_VEC->byteorder).


+ extern const bfd_arch_info_type DEFAULT_BFD_ARCH;
+ static const bfd_arch_info_type *default_bfd_arch = &DEFAULT_BFD_ARCH;

+ extern const bfd_target DEFAULT_BFD_VEC;
+ static const bfd_target *default_bfd_vec = &DEFAULT_BFD_VEC;


!   if (info.bfd_arch_info == NULL
!       && default_bfd_arch != NULL)
!     info.bfd_arch_info = default_bfd_arch;

+   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;
+       }
+     }

--

(1)  bfd_create () core dumps unless you give it an existing bfd
(catch22?).  bfd_find_target() does similar.


More information about the Gdb-patches mailing list