Better way to get the arch/endianess?
Andrew Cagney
ac131313@cygnus.com
Wed Jun 7 21:03:00 GMT 2000
Andrew Cagney wrote:
>
> 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.
FYI,
I've committed the attatched and put down getting a BFD change on the
TODO list.
This only affects multi-arch targets.
Andrew
Wed Jun 7 18:27:51 2000 Andrew Cagney <cagney@b1.cygnus.com>
* configure.in (DEFAULT_BFD_ARCH, DEFAULT_BFD_VEC): Use config.bfd
to determine the default architecture / target.
* acconfig (DEFAULT_BFD_ARCH, DEFAULT_BFD_VEC): Add.
* configure, config.in: Regenerate.
* arch-utils.c (set_endian): Better separate multi-arch and non-
multi-arch cases.
(set_endian_from_file): Call internal_error when multi-arch.
(initialize_current_architecture): Rewrite logic selecting a byte
order. Use DEFAULT_BFD_ARCH DEFAULT_BFD_VEC.
(version.h): Include.
* config/mips/tm-mips.h, config/mips/tm-bigmips64.h,
config/mips/tm-bigmips.h: Delete definition of
TARGET_BYTE_ORDER_DEFAULT.
Index: TODO
===================================================================
RCS file: /cvs/src/src/gdb/TODO,v
retrieving revision 1.33
diff -p -r1.33 TODO
*** TODO 2000/06/08 00:52:56 1.33
--- TODO 2000/06/08 03:30:26
*************** http://sourceware.cygnus.com/ml/gdb-patc
*** 109,114 ****
--- 109,124 ----
--
+ Find something better than DEFAULT_BFD_ARCH, DEFAULT_BFD_VEC to
+ determine the default isa/byte-order.
+
+ --
+
+ Rely on BFD_BIG_ENDIAN and BFD_LITTLE_ENDIAN instead of host dependant
+ BIG_ENDIAN and LITTLE_ENDIAN.
+
+ --
+
Code Cleanups: General
======================
Index: acconfig.h
===================================================================
RCS file: /cvs/src/src/gdb/acconfig.h,v
retrieving revision 1.8
diff -p -r1.8 acconfig.h
*** acconfig.h 2000/06/05 18:59:40 1.8
--- acconfig.h 2000/06/08 03:30:26
***************
*** 115,117 ****
--- 115,123 ----
/* Define if gnu-regex.c included with GDB should be used. */
#undef USE_INCLUDED_REGEX
+
+ /* BFD's default architecture. */
+ #undef DEFAULT_BFD_ARCH
+
+ /* BFD's default target vector. */
+ #undef DEFAULT_BFD_VEC
Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.8
diff -p -r1.8 arch-utils.c
*** arch-utils.c 2000/06/08 00:52:56 1.8
--- arch-utils.c 2000/06/08 03:30:31
***************
*** 41,46 ****
--- 41,48 ----
#include "symfile.h" /* for overlay functions */
#endif
+ #include "version.h"
+
#include "floatformat.h"
/* Convenience macro for allocting typesafe memory. */
*************** generic_register_convertible_not (num)
*** 246,251 ****
--- 248,256 ----
#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;
*************** set_endian (char *ignore_args, int from_
*** 287,293 ****
}
else if (set_endian_string == endian_little)
{
- target_byte_order = LITTLE_ENDIAN;
target_byte_order_auto = 0;
if (GDB_MULTI_ARCH)
{
--- 292,297 ----
*************** set_endian (char *ignore_args, int from_
*** 296,305 ****
info.byte_order = LITTLE_ENDIAN;
gdbarch_update (info);
}
}
else if (set_endian_string == endian_big)
{
- target_byte_order = BIG_ENDIAN;
target_byte_order_auto = 0;
if (GDB_MULTI_ARCH)
{
--- 300,312 ----
info.byte_order = LITTLE_ENDIAN;
gdbarch_update (info);
}
+ else
+ {
+ target_byte_order = LITTLE_ENDIAN;
+ }
}
else if (set_endian_string == endian_big)
{
target_byte_order_auto = 0;
if (GDB_MULTI_ARCH)
{
*************** set_endian (char *ignore_args, int from_
*** 308,313 ****
--- 315,324 ----
info.byte_order = BIG_ENDIAN;
gdbarch_update (info);
}
+ else
+ {
+ target_byte_order = BIG_ENDIAN;
+ }
}
else
internal_error ("set_endian: bad value");
*************** set_endian (char *ignore_args, int from_
*** 319,324 ****
--- 330,337 ----
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;
*************** set_gdbarch_from_file (abfd)
*** 547,578 ****
architecture'' command so that it specifies a list of valid
architectures. */
void
initialize_current_architecture (void)
{
const char **arches = gdbarch_printable_names ();
- const char *chosen = arches[0];
! if (GDB_MULTI_ARCH)
! {
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''. */
{
struct cmd_list_element *c;
/* Append ``auto''. */
--- 560,652 ----
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 ();
! /* 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;
for (arch = arches; *arch != NULL; arch++)
{
if (strcmp (*arch, chosen) < 0)
chosen = *arch;
}
if (chosen == NULL)
internal_error ("initialize_current_architecture: No arch");
info.bfd_arch_info = bfd_scan_arch (chosen);
if (info.bfd_arch_info == NULL)
internal_error ("initialize_current_architecture: Arch not found");
+ }
+
+ /* 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)
+ {
gdbarch_update (info);
}
! /* Create the ``set architecture'' command appending ``auto'' to the
! list of architectures. */
{
struct cmd_list_element *c;
/* Append ``auto''. */
Index: config.in
===================================================================
RCS file: /cvs/src/src/gdb/config.in,v
retrieving revision 1.13
diff -p -r1.13 config.in
*** config.in 2000/06/05 18:59:40 1.13
--- config.in 2000/06/08 03:30:31
***************
*** 135,140 ****
--- 135,146 ----
/* Define if gnu-regex.c included with GDB should be used. */
#undef USE_INCLUDED_REGEX
+ /* BFD's default architecture. */
+ #undef DEFAULT_BFD_ARCH
+
+ /* BFD's default target vector. */
+ #undef DEFAULT_BFD_VEC
+
/* Define if you have the __argz_count function. */
#undef HAVE___ARGZ_COUNT
Index: configure.in
===================================================================
RCS file: /cvs/src/src/gdb/configure.in,v
retrieving revision 1.33
diff -p -r1.33 configure.in
*** configure.in 2000/06/07 01:14:07 1.33
--- configure.in 2000/06/08 03:31:27
*************** 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
Index: config/mips/tm-bigmips.h
===================================================================
RCS file: /cvs/src/src/gdb/config/mips/tm-bigmips.h,v
retrieving revision 1.1.1.2
diff -p -r1.1.1.2 tm-bigmips.h
*** tm-bigmips.h 1999/07/07 20:15:20 1.1.1.2
--- tm-bigmips.h 2000/06/08 03:31:34
***************
*** 1,4 ****
! /* Copyright (C) 1990 Free Software Foundation, Inc.
This file is part of GDB.
--- 1,4 ----
! /* Copyright (C) 1990, 2000 Free Software Foundation, Inc.
This file is part of GDB.
***************
*** 16,22 ****
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-
- #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
#include "mips/tm-mips.h"
--- 16,20 ----
Index: config/mips/tm-bigmips64.h
===================================================================
RCS file: /cvs/src/src/gdb/config/mips/tm-bigmips64.h,v
retrieving revision 1.1.1.2
diff -p -r1.1.1.2 tm-bigmips64.h
*** tm-bigmips64.h 1999/07/07 20:15:21 1.1.1.2
--- tm-bigmips64.h 2000/06/08 03:31:34
***************
*** 1,5 ****
/* Target machine parameters for MIPS r4000
! Copyright 1994 Free Software Foundation, Inc.
Contributed by Ian Lance Taylor (ian@cygnus.com)
This file is part of GDB.
--- 1,5 ----
/* Target machine parameters for MIPS r4000
! Copyright 1994, 2000 Free Software Foundation, Inc.
Contributed by Ian Lance Taylor (ian@cygnus.com)
This file is part of GDB.
***************
*** 18,24 ****
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-
- #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
#include "mips/tm-mips64.h"
--- 18,22 ----
Index: config/mips/tm-mips.h
===================================================================
RCS file: /cvs/src/src/gdb/config/mips/tm-mips.h,v
retrieving revision 1.9
diff -p -r1.9 tm-mips.h
*** tm-mips.h 2000/06/06 07:00:45 1.9
--- tm-mips.h 2000/06/08 03:31:44
*************** struct value;
*** 33,42 ****
#include "coff/sym.h" /* Needed for PDR below. */
#include "coff/symconst.h"
- #if !defined (TARGET_BYTE_ORDER_DEFAULT)
- #define TARGET_BYTE_ORDER_DEFAULT LITTLE_ENDIAN
- #endif
-
#if !defined (GDB_TARGET_IS_MIPS64)
#define GDB_TARGET_IS_MIPS64 0
#endif
--- 33,38 ----
More information about the Gdb-patches
mailing list