[patch/multi-arch] Fix ``set architecture <tab>''.

Andrew Cagney ac131313@cygnus.com
Tue Jun 6 21:27:00 GMT 2000


Hello,

The attatched finishes my gdbarch.* cleanups and (finally) fixes the
``set architecture <tab>'' command.  It rewrite ``set endian'' to use
the same mechanism.

(If you glance at the TODO changes you'll see it is a big jump forward
but with a shakey landing :-)

	Andrew
Wed Jun  7 11:34:54 2000  Andrew Cagney  <cagney@b1.cygnus.com>

	* arch-utils.c (target_byte_order, target_byte_order_auto,
 	show_endian, set_endian, set_endian_big, set_endian_little,
 	set_endian_auto, set_endian_from_file, enum set_arch,
 	target_architecture_auto, set_architecture_string,
 	target_architecture_hook, target_architecture, arch_ok, set_arch,
 	set_architecture_from_arch_mach, set_architecture_from_file,
 	show_architecture, set_architecture, info_architecture,
 	set_gdbarch_from_file, initialize_current_architecture): Copy from
  	gdbarch.c.  Rewrite ``set architecture'' and ``set endian''
 	commands to use enums.
	(_initialize_gdbarch_utils): Fix name.
	* arch-utils.h (set_architecture_from_arch_mach,
 	target_architecture_hook): Copy from gdbarch.h.
	* gdbarch.sh: Update.
	* gdbarch.h, gdbarch.c: Re-generate.

	* TODO: Update.

	* v850-tdep.c, sh3-rom.c, sh-tdep.c, i386-tdep.c: Include
 	"arch-utils.h".
	* Makefile.in (v850-tdep.o): Specify dependencies.
	(i386-tdep.o, sh3-rom.o, sh-tdep.o): Add arch-utils.h to
 	dependency list.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.33
diff -p -r1.33 Makefile.in
*** Makefile.in	2000/05/25 01:50:50	1.33
--- Makefile.in	2000/06/07 04:20:53
*************** v850ice.o: v850ice.c $(defs_h) $(symtab_
*** 1363,1368 ****
--- 1363,1372 ----
  	$(TCL_CFLAGS) $(TK_CFLAGS) $(X11_CFLAGS) $(GDBTK_CFLAGS)\
  		$(srcdir)/v850ice.c
  
+ v850-tdep.o: v850-tdep.c $(defs_h) $(frame_h) $(inferior_h) $(obstack_h) \
+ 	$(target_h) $(value_h) $(bfd_h) $(gdb_string_h) $(gdbcore_h) \
+ 	$(symfile_h) $(arch_utils_h)
+ 
  tracepoint.o: tracepoint.c $(defs_h) $(symtab_h) $(frame_h) $(tracepoint_h) \
  	$(gdbtypes_h) $(expression_h) $(gdbcmd_h) $(value_h) target.h \
  	language.h gdb_string.h $(readline_headers) $(remote_h)
*************** i386gnu-nat.o: gnu-nat.h
*** 1401,1407 ****
  
  i386-tdep.o: i386-tdep.c $(defs_h) gdb_string.h $(frame_h)	\
  	$(inferior_h) $(gdbcore_h) target.h $(floatformat_h)	\
! 	$(symtab_h) $(gdbcmd_h) $(command_h)
  
  i386aix-nat.o: i386aix-nat.c $(defs_h) $(frame_h) $(inferior_h) \
  	language.h $(gdbcore_h) $(floatformat_h) target.h
--- 1405,1411 ----
  
  i386-tdep.o: i386-tdep.c $(defs_h) gdb_string.h $(frame_h)	\
  	$(inferior_h) $(gdbcore_h) target.h $(floatformat_h)	\
! 	$(symtab_h) $(gdbcmd_h) $(command_h) $(arch_utils_h)
  
  i386aix-nat.o: i386aix-nat.c $(defs_h) $(frame_h) $(inferior_h) \
  	language.h $(gdbcore_h) $(floatformat_h) target.h
*************** serial.o: serial.c $(defs_h) serial.h gd
*** 1790,1799 ****
  
  sh-tdep.o: sh-tdep.c $(bfd_h) $(dis-asm_h) \
  	$(srcdir)/../opcodes/sh-opc.h $(defs_h) $(expression_h) $(frame_h) \
! 	$(gdbcmd_h) $(gdbtypes_h) $(symtab_h) $(value_h)
  
  sh3-rom.o: sh3-rom.c monitor.h $(bfd_h) gdb_wait.h $(defs_h) $(gdbcmd_h) \
! 	$(inferior_h) target.h serial.h terminal.h
  
  mon960-rom.o: mon960-rom.c monitor.h $(bfd_h) gdb_wait.h $(defs_h) $(gdbcmd_h) \
  	$(inferior_h) target.h serial.h terminal.h
--- 1794,1803 ----
  
  sh-tdep.o: sh-tdep.c $(bfd_h) $(dis-asm_h) \
  	$(srcdir)/../opcodes/sh-opc.h $(defs_h) $(expression_h) $(frame_h) \
! 	$(gdbcmd_h) $(gdbtypes_h) $(symtab_h) $(value_h) $(arch_utils_h)
  
  sh3-rom.o: sh3-rom.c monitor.h $(bfd_h) gdb_wait.h $(defs_h) $(gdbcmd_h) \
! 	$(inferior_h) target.h serial.h terminal.h $(arch_utils_h)
  
  mon960-rom.o: mon960-rom.c monitor.h $(bfd_h) gdb_wait.h $(defs_h) $(gdbcmd_h) \
  	$(inferior_h) target.h serial.h terminal.h
Index: TODO
===================================================================
RCS file: /cvs/src/src/gdb/TODO,v
retrieving revision 1.30
diff -p -r1.30 TODO
*** TODO	2000/06/05 05:20:58	1.30
--- TODO	2000/06/07 04:20:58
*************** http://sourceware.cygnus.com/ml/gdb/2000
*** 297,303 ****
--- 297,320 ----
  
  --
  
+ Change the parameter ``char *list[]'' (etc) to ``const char (*)[]'' so
+ that dynamic lists from things like gdbarch_printable_names() can be
+ passed.
  
+ --
+ 
+ The ``maintenance deprecate set endian big'' command doesn't notice
+ that it is deprecating ``set endian'' and not ``set endian big'' (big
+ is implemented using an enum).  Is anyone going to notice this?
+ 
+ --
+ 
+ When tab expanding something like ``set arch<tab>'' ignore the
+ deprecated ``set archdebug'' and expand to ``set architecture''.
+ 
+ --
+ 
+ 
  			New Features and Fixes
  			======================
  
*************** Convert GDB build process to AUTOMAKE.
*** 334,339 ****
--- 351,359 ----
  
  See also sub-directory configure below.
  
+ The current convention is (kind of) to use $(<header>_h) in all
+ dependency lists.  It isn't done in a consistent way.
+ 
  --
  
  Cleanup configury support for optional sub-directories.
*************** http://sourceware.cygnus.com/ml/gdb/2000
*** 425,430 ****
--- 445,460 ----
  
  --
  
+ Change the (char *list[]) to (const char (*)[]) so that dynamic lists can
+ be passed.
+ 
+ --
+ 
+ When tab expanding something like ``set arch<tab>'' ignore the
+ deprecated ``set archdebug'' and expand to ``set architecture''.
+ 
+ --
+ 
  Replace the code that uses the host FPU with an emulator of the target
  FPU.
  
*************** Fix BELIEVE_PPC_PROMOTION.  Change it to
*** 881,894 ****
  
  At present there is still #ifdef BELIEVE_PPC_PROMOTION code in the
  symtab file.
- 
- --
- 
- Fix ``set architecture <tab>''
- 
- This command should expand to a list of all supported architectures.
- At present ``info architecture'' needs to be used.  That is simply
- wrong.  It involves the use of add_set_enum_cmd().
  
  --
  
--- 911,916 ----
Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.6
diff -p -r1.6 arch-utils.c
*** arch-utils.c	2000/06/06 06:45:19	1.6
--- arch-utils.c	2000/06/07 04:21:00
*************** generic_register_convertible_not (num)
*** 223,233 ****
    return 0;
  }
    
  /* */
  
! extern initialize_file_ftype __initialize_gdbarch_utils;
  
  void
! __initialize_gdbarch_utils (void)
  {
  }
--- 223,621 ----
    return 0;
  }
    
+ 
+ /* Functions to manipulate the endianness of the target.  */
+ 
+ #ifdef TARGET_BYTE_ORDER_SELECTABLE
+ /* compat - Catch old targets that expect a selectable byte-order to
+    default to BIG_ENDIAN */
+ #ifndef TARGET_BYTE_ORDER_DEFAULT
+ #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
+ #endif
+ #endif
+ #if !TARGET_BYTE_ORDER_SELECTABLE_P
+ #ifndef TARGET_BYTE_ORDER_DEFAULT
+ /* compat - Catch old non byte-order selectable targets that do not
+    define TARGET_BYTE_ORDER_DEFAULT and instead expect
+    TARGET_BYTE_ORDER to be used as the default.  For targets that
+    defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
+    below will get a strange compiler warning. */
+ #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
+ #endif
+ #endif
+ #ifndef TARGET_BYTE_ORDER_DEFAULT
+ #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */
+ #endif
+ 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[] =
+ {
+   endian_big,
+   endian_little,
+   endian_auto,
+   NULL,
+ };
+ static char *set_endian_string;
+ 
+ /* Called by ``show endian''.  */
+ 
+ static void
+ show_endian (char *args, int from_tty)
+ {
+   if (TARGET_BYTE_ORDER_AUTO)
+     printf_unfiltered ("The target endianness is set automatically (currently %s endian)\n",
+ 		       (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"));
+   else
+     printf_unfiltered ("The target is assumed to be %s endian\n",
+ 		       (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"));
+ }
+ 
+ static void
+ set_endian (char *ignore_args, int from_tty, struct cmd_list_element *c)
+ {
+   if (!TARGET_BYTE_ORDER_SELECTABLE_P)
+     {
+       printf_unfiltered ("Byte order is not selectable.");
+     }
+   else if (set_endian_string == endian_auto)
+     {
+       target_byte_order_auto = 1;
+     }
+   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);
+ 	}
+     }
+   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);
+ 	}
+     }
+   else
+     internal_error ("set_endian: bad value");
+   show_endian (NULL, from_tty);
+ }
+ 
+ /* Set the endianness from a BFD.  */
+ 
+ static void
+ set_endian_from_file (bfd *abfd)
+ {
+   if (TARGET_BYTE_ORDER_SELECTABLE_P)
+     {
+       int want;
+       
+       if (bfd_big_endian (abfd))
+ 	want = BIG_ENDIAN;
+       else
+ 	want = LITTLE_ENDIAN;
+       if (TARGET_BYTE_ORDER_AUTO)
+ 	target_byte_order = want;
+       else if (TARGET_BYTE_ORDER != want)
+ 	warning ("%s endian file does not match %s endian target.",
+ 		 want == BIG_ENDIAN ? "big" : "little",
+ 		 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+     }
+   else
+     {
+       if (bfd_big_endian (abfd)
+ 	  ? TARGET_BYTE_ORDER != BIG_ENDIAN
+ 	  : TARGET_BYTE_ORDER == BIG_ENDIAN)
+ 	warning ("%s endian file does not match %s endian target.",
+ 		 bfd_big_endian (abfd) ? "big" : "little",
+ 		 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+     }
+ }
+ 
+ 
+ /* Functions to manipulate the architecture of the target */
+ 
+ enum set_arch { set_arch_auto, set_arch_manual };
+ 
+ int target_architecture_auto = 1;
+ 
+ char *set_architecture_string;
+ 
+ /* Old way of changing the current architecture. */
+ 
+ extern const struct bfd_arch_info bfd_default_arch_struct;
+ const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct;
+ int (*target_architecture_hook) (const struct bfd_arch_info *ap);
+ 
+ static int
+ arch_ok (const struct bfd_arch_info *arch)
+ {
+   if (GDB_MULTI_ARCH)
+     internal_error ("arch_ok: not multi-arched");
+   /* Should be performing the more basic check that the binary is
+      compatible with GDB. */
+   /* Check with the target that the architecture is valid. */
+   return (target_architecture_hook == NULL
+ 	  || target_architecture_hook (arch));
+ }
+ 
+ static void
+ set_arch (const struct bfd_arch_info *arch,
+           enum set_arch type)
+ {
+   if (GDB_MULTI_ARCH)
+     internal_error ("set_arch: not multi-arched");
+   switch (type)
+     {
+     case set_arch_auto:
+       if (!arch_ok (arch))
+ 	warning ("Target may not support %s architecture",
+ 		 arch->printable_name);
+       target_architecture = arch;
+       break;
+     case set_arch_manual:
+       if (!arch_ok (arch))
+ 	{
+ 	  printf_unfiltered ("Target does not support `%s' architecture.\n",
+ 			     arch->printable_name);
+ 	}
+       else
+ 	{
+ 	  target_architecture_auto = 0;
+ 	  target_architecture = arch;
+ 	}
+       break;
+     }
+   if (gdbarch_debug)
+     gdbarch_dump ();
+ }
+ 
+ /* Set the architecture from arch/machine (deprecated) */
+ 
+ void
+ set_architecture_from_arch_mach (enum bfd_architecture arch,
+ 				 unsigned long mach)
+ {
+   const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach);
+   if (GDB_MULTI_ARCH)
+     internal_error ("set_architecture_from_arch_mach: not multi-arched");
+   if (wanted != NULL)
+     set_arch (wanted, set_arch_manual);
+   else
+     internal_error ("gdbarch: hardwired architecture/machine not reconized");
+ }
+ 
+ /* Set the architecture from a BFD (deprecated) */
+ 
+ static void
+ set_architecture_from_file (bfd *abfd)
+ {
+   const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd);
+   if (GDB_MULTI_ARCH)
+     internal_error ("set_architecture_from_file: not multi-arched");
+   if (target_architecture_auto)
+     {
+       set_arch (wanted, set_arch_auto);
+     }
+   else if (wanted != target_architecture)
+     {
+       warning ("%s architecture file may be incompatible with %s target.",
+ 	       wanted->printable_name,
+ 	       target_architecture->printable_name);
+     }
+ }
+ 
+ 
+ /* Called if the user enters ``show architecture'' without an
+    argument. */
+ 
+ static void
+ show_architecture (char *args, int from_tty)
+ {
+   const char *arch;
+   arch = TARGET_ARCHITECTURE->printable_name;
+   if (target_architecture_auto)
+     printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
+   else
+     printf_filtered ("The target architecture is assumed to be %s\n", arch);
+ }
+ 
+ 
+ /* Called if the user enters ``set architecture'' with or without an
+    argument. */
+ 
+ static void
+ set_architecture (char *ignore_args, int from_tty, struct cmd_list_element *c)
+ {
+   if (strcmp (set_architecture_string, "auto") == 0)
+     {
+       target_architecture_auto = 1;
+     }
+   else if (GDB_MULTI_ARCH)
+     {
+       struct gdbarch_info info;
+       memset (&info, 0, sizeof info);
+       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))
+ 	target_architecture_auto = 0;
+       else
+ 	printf_unfiltered ("Architecture `%s' not reconized.\n",
+ 			   set_architecture_string);
+     }
+   else
+     {
+       const struct bfd_arch_info *arch
+ 	= bfd_scan_arch (set_architecture_string);
+       if (arch == NULL)
+ 	internal_error ("set_architecture: bfd_scan_arch failed");
+       set_arch (arch, set_arch_manual);
+     }
+   show_architecture (NULL, from_tty);
+ }
+ 
+ /* Called if the user enters ``info architecture'' without an argument. */
+ 
+ static void
+ info_architecture (char *args, int from_tty)
+ {
+   printf_filtered ("Available architectures are:\n");
+   if (GDB_MULTI_ARCH)
+     {
+       const char **arches = gdbarch_printable_names ();
+       const char **arch;
+       for (arch = arches; *arch != NULL; arch++)
+ 	{
+ 	  printf_filtered (" %s", *arch);
+ 	}
+       free (arches);
+     }
+   else
+     {
+       enum bfd_architecture a;
+       for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
+ 	{
+ 	  const struct bfd_arch_info *ap;
+ 	  for (ap = bfd_lookup_arch (a, 0);
+ 	       ap != NULL;
+ 	       ap = ap->next)
+ 	    {
+ 	      printf_filtered (" %s", ap->printable_name);
+ 	      ap = ap->next;
+ 	    }
+ 	}
+     }
+   printf_filtered ("\n");
+ }
+ 
+ /* Set the dynamic target-system-dependant parameters (architecture,
+    byte-order) using information found in the BFD */
+ 
+ void
+ set_gdbarch_from_file (abfd)
+      bfd *abfd;
+ {
+   if (GDB_MULTI_ARCH)
+     {
+       struct gdbarch_info info;
+       memset (&info, 0, sizeof info);
+       info.abfd = abfd;
+       gdbarch_update (info);
+     }
+   else
+     {
+       set_architecture_from_file (abfd);
+       set_endian_from_file (abfd);
+     }
+ }
+ 
+ /* Initialize the current architecture.  Update the ``set
+    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''. */
+     int nr;
+     for (nr = 0; arches[nr] != NULL; nr++);
+     arches = xrealloc (arches, sizeof (char*) * (nr + 2));
+     arches[nr + 0] = "auto";
+     arches[nr + 1] = NULL;
+     /* FIXME: add_set_enum_cmd() uses an array of ``char *'' instead
+        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,
+ 			  "Set architecture of target.",
+ 			  &setlist);
+     c->function.sfunc = set_architecture;
+     add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
+     /* Don't use set_from_show - need to print both auto/manual and
+        current setting. */
+     add_cmd ("architecture", class_support, show_architecture,
+ 	     "Show the current target architecture", &showlist);
+     c = add_cmd ("architecture", class_support, info_architecture,
+ 		 "List supported target architectures", &infolist);
+     deprecate_cmd (c, "set architecture");
+   }
+ }
+ 
+ 
  /* */
  
! extern initialize_file_ftype _initialize_gdbarch_utils;
  
  void
! _initialize_gdbarch_utils (void)
  {
+   struct cmd_list_element *c;
+   c = add_set_enum_cmd ("endian", class_support,
+ 			endian_enum, &set_endian_string,
+ 			"Set endianness of target.",
+ 			&setlist);
+   c->function.sfunc = set_endian;
+   /* Don't use set_from_show - need to print both auto/manual and
+      current setting. */
+   add_cmd ("endian", class_support, show_endian,
+ 	   "Show the current byte-order", &showlist);
  }
Index: arch-utils.h
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.h,v
retrieving revision 1.6
diff -p -r1.6 arch-utils.h
*** arch-utils.h	2000/06/06 06:45:19	1.6
--- arch-utils.h	2000/06/07 04:21:00
*************** extern const struct floatformat *default
*** 72,75 ****
--- 72,91 ----
  extern int frame_num_args_unknown (struct frame_info *fi);
  
  
+ /* The following DEPRECATED interfaces are for pre- multi-arch legacy
+    targets. */
+ 
+ /* DEPRECATED pre- multi-arch interface.  Explicitly set the dynamic
+    target-system-dependant parameters based on bfd_architecture and
+    machine.  This function is deprecated, use
+    set_gdbarch_from_arch_machine(). */
+ 
+ extern void set_architecture_from_arch_mach (enum bfd_architecture, unsigned long);
+ 
+ /* DEPRECATED pre- multi-arch interface.  Notify the target dependant
+    backend of a change to the selected architecture. A zero return
+    status indicates that the target did not like the change. */
+ 
+ extern int (*target_architecture_hook) (const struct bfd_arch_info *);
+ 
  #endif
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.26
diff -p -r1.26 gdbarch.sh
*** gdbarch.sh	2000/06/06 06:45:19	1.26
--- gdbarch.sh	2000/06/07 04:21:09
*************** typedef struct gdbarch *(gdbarch_init_ft
*** 702,707 ****
--- 702,715 ----
  extern void register_gdbarch_init (enum bfd_architecture architecture, gdbarch_init_ftype *);
  
  
+ /* Return a freshly allocated, NULL terminated, array of the valid
+    architecture names.  Since architectures are registered during the
+    _initialize phase this function only returns useful information
+    once initialization has been completed. */
+ 
+ extern const char **gdbarch_printable_names (void);
+ 
+ 
  /* Helper function.  Search the list of ARCHES for a GDBARCH that
     matches the information provided by INFO. */
  
*************** extern const struct bfd_arch_info *targe
*** 832,844 ****
  #define TARGET_ARCHITECTURE (target_architecture + 0)
  #endif
  
- /* Notify the target dependant backend of a change to the selected
-    architecture. A zero return status indicates that the target did
-    not like the change. */
- 
- extern int (*target_architecture_hook) (const struct bfd_arch_info *);
- 
- 
  
  /* The target-system-dependant disassembler is semi-dynamic */
  
--- 840,845 ----
*************** extern disassemble_info tm_print_insn_in
*** 887,898 ****
  extern void set_gdbarch_from_file (bfd *);
  
  
- /* Explicitly set the dynamic target-system-dependant parameters based
-    on bfd_architecture and machine. */
- 
- extern void set_architecture_from_arch_mach (enum bfd_architecture, unsigned long);
- 
- 
  /* Initialize the current architecture to the "first" one we find on
     our list.  */
  
--- 888,893 ----
*************** struct gdbarch_init_registration
*** 1516,1521 ****
--- 1511,1560 ----
  
  static struct gdbarch_init_registration *gdbarch_init_registrary = NULL;
  
+ static void
+ append_name (const char ***buf, int *nr, const char *name)
+ {
+   *buf = xrealloc (*buf, sizeof (char**) * (*nr + 1));
+   (*buf)[*nr] = name;
+   *nr += 1;
+ }
+ 
+ const char **
+ gdbarch_printable_names (void)
+ {
+   if (GDB_MULTI_ARCH)
+     {
+       /* Accumulate a list of names based on the registed list of
+          architectures. */
+       enum bfd_architecture a;
+       int nr_arches = 0;
+       const char **arches = NULL;
+       struct gdbarch_init_registration *rego;
+       for (rego = gdbarch_init_registrary;
+ 	   rego != NULL;
+ 	   rego = rego->next)
+ 	{
+ 	  const struct bfd_arch_info *ap;
+ 	  ap = bfd_lookup_arch (rego->bfd_architecture, 0);
+ 	  if (ap == NULL)
+ 	    internal_error ("gdbarch_architecture_names: multi-arch unknown");
+ 	  do
+ 	    {
+ 	      append_name (&arches, &nr_arches, ap->printable_name);
+ 	      ap = ap->next;
+ 	    }
+ 	  while (ap != NULL);
+ 	}
+       append_name (&arches, &nr_arches, NULL);
+       return arches;
+     }
+   else
+     /* Just return all the architectures that BFD knows.  Assume that
+        the legacy architecture framework supports them. */
+     return bfd_arch_list ();
+ }
+ 
+ 
  void
  register_gdbarch_init (enum bfd_architecture bfd_architecture,
                         gdbarch_init_ftype *init)
*************** register_gdbarch_init (enum bfd_architec
*** 1549,1555 ****
    (*curr)->arches = NULL;
    (*curr)->next = NULL;
  }
-   
  
  
  /* Look for an architecture using gdbarch_info.  Base search on only
--- 1588,1593 ----
*************** gdbarch_update (struct gdbarch_info info
*** 1723,2065 ****
  
  
  
- /* Functions to manipulate the endianness of the target.  */
- 
- #ifdef TARGET_BYTE_ORDER_SELECTABLE
- /* compat - Catch old targets that expect a selectable byte-order to
-    default to BIG_ENDIAN */
- #ifndef TARGET_BYTE_ORDER_DEFAULT
- #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
- #endif
- #endif
- #if !TARGET_BYTE_ORDER_SELECTABLE_P
- #ifndef TARGET_BYTE_ORDER_DEFAULT
- /* compat - Catch old non byte-order selectable targets that do not
-    define TARGET_BYTE_ORDER_DEFAULT and instead expect
-    TARGET_BYTE_ORDER to be used as the default.  For targets that
-    defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
-    below will get a strange compiler warning. */
- #define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
- #endif
- #endif
- #ifndef TARGET_BYTE_ORDER_DEFAULT
- #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */
- #endif
- int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
- int target_byte_order_auto = 1;
- 
- /* Chain containing the \"set endian\" commands.  */
- static struct cmd_list_element *endianlist = NULL;
- 
- /* Called by \`\`show endian''.  */
- static void
- show_endian (char *args, int from_tty)
- {
-   char *msg =
-     (TARGET_BYTE_ORDER_AUTO
-      ? "The target endianness is set automatically (currently %s endian)\n"
-      : "The target is assumed to be %s endian\n");
-   printf_unfiltered (msg, (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"));
- }
- 
- /* Called if the user enters \`\`set endian'' without an argument.  */
- static void
- set_endian (char *args, int from_tty)
- {
-   printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
-   show_endian (args, from_tty);
- }
- 
- /* Called by \`\`set endian big''.  */
- static void
- set_endian_big (char *args, int from_tty)
- {
-   if (TARGET_BYTE_ORDER_SELECTABLE_P)
-     {
-       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);
- 	}
-     }
-   else
-     {
-       printf_unfiltered ("Byte order is not selectable.");
-       show_endian (args, from_tty);
-     }
- }
- 
- /* Called by \`\`set endian little''.  */
- static void
- set_endian_little (char *args, int from_tty)
- {
-   if (TARGET_BYTE_ORDER_SELECTABLE_P)
-     {
-       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);
- 	}
-     }
-   else
-     {
-       printf_unfiltered ("Byte order is not selectable.");
-       show_endian (args, from_tty);
-     }
- }
- 
- /* Called by \`\`set endian auto''.  */
- static void
- set_endian_auto (char *args, int from_tty)
- {
-   if (TARGET_BYTE_ORDER_SELECTABLE_P)
-     {
-       target_byte_order_auto = 1;
-     }
-   else
-     {
-       printf_unfiltered ("Byte order is not selectable.");
-       show_endian (args, from_tty);
-     }
- }
- 
- /* Set the endianness from a BFD.  */
- static void
- set_endian_from_file (bfd *abfd)
- {
-   if (TARGET_BYTE_ORDER_SELECTABLE_P)
-     {
-       int want;
-       
-       if (bfd_big_endian (abfd))
- 	want = BIG_ENDIAN;
-       else
- 	want = LITTLE_ENDIAN;
-       if (TARGET_BYTE_ORDER_AUTO)
- 	target_byte_order = want;
-       else if (TARGET_BYTE_ORDER != want)
- 	warning ("%s endian file does not match %s endian target.",
- 		 want == BIG_ENDIAN ? "big" : "little",
- 		 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
-     }
-   else
-     {
-       if (bfd_big_endian (abfd)
- 	  ? TARGET_BYTE_ORDER != BIG_ENDIAN
- 	  : TARGET_BYTE_ORDER == BIG_ENDIAN)
- 	warning ("%s endian file does not match %s endian target.",
- 		 bfd_big_endian (abfd) ? "big" : "little",
- 		 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
-     }
- }
- 
- 
- 
- /* Functions to manipulate the architecture of the target */
- 
- enum set_arch { set_arch_auto, set_arch_manual };
- 
- int target_architecture_auto = 1;
- extern const struct bfd_arch_info bfd_default_arch_struct;
- const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct;
- int (*target_architecture_hook) (const struct bfd_arch_info *ap);
- 
- static void show_endian (char *, int);
- static void set_endian (char *, int);
- static void set_endian_big (char *, int);
- static void set_endian_little (char *, int);
- static void set_endian_auto (char *, int);
- static void set_endian_from_file (bfd *);
- static int arch_ok (const struct bfd_arch_info *arch);
- static void set_arch (const struct bfd_arch_info *arch, enum set_arch type);
- static void show_architecture (char *, int);
- static void set_architecture (char *, int);
- static void info_architecture (char *, int);
- static void set_architecture_from_file (bfd *);
- 
- /* Do the real work of changing the current architecture */
- 
- static int
- arch_ok (const struct bfd_arch_info *arch)
- {
-   /* Should be performing the more basic check that the binary is
-      compatible with GDB. */
-   /* Check with the target that the architecture is valid. */
-   return (target_architecture_hook == NULL
- 	  || target_architecture_hook (arch));
- }
- 
- static void
- set_arch (const struct bfd_arch_info *arch,
-           enum set_arch type)
- {
-   switch (type)
-     {
-     case set_arch_auto:
-       if (!arch_ok (arch))
- 	warning ("Target may not support %s architecture",
- 		 arch->printable_name);
-       target_architecture = arch;
-       break;
-     case set_arch_manual:
-       if (!arch_ok (arch))
- 	{
- 	  printf_unfiltered ("Target does not support \`%s' architecture.\n",
- 			     arch->printable_name);
- 	}
-       else
- 	{
- 	  target_architecture_auto = 0;
- 	  target_architecture = arch;
- 	}
-       break;
-     }
-   if (gdbarch_debug)
-     gdbarch_dump ();
- }
- 
- /* Called if the user enters \`\`show architecture'' without an argument. */
- static void
- show_architecture (char *args, int from_tty)
- {
-   const char *arch;
-   arch = TARGET_ARCHITECTURE->printable_name;
-   if (target_architecture_auto)
-     printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
-   else
-     printf_filtered ("The target architecture is assumed to be %s\n", arch);
- }
- 
- /* Called if the user enters \`\`set architecture'' with or without an
-    argument. */
- static void
- set_architecture (char *args, int from_tty)
- {
-   if (args == NULL)
-     {
-       printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
-     }
-   else if (strcmp (args, "auto") == 0)
-     {
-       target_architecture_auto = 1;
-     }
-   else if (GDB_MULTI_ARCH)
-     {
-       const struct bfd_arch_info *arch = bfd_scan_arch (args);
-       if (arch == NULL)
- 	printf_unfiltered ("Architecture \`%s' not reconized.\n", args);
-       else
- 	{
- 	  struct gdbarch_info info;
- 	  memset (&info, 0, sizeof info);
- 	  info.bfd_arch_info = arch;
- 	  if (gdbarch_update (info))
- 	    target_architecture_auto = 0;
- 	  else
- 	    printf_unfiltered ("Architecture \`%s' not reconized.\n", args);
- 	}
-     }
-   else
-     {
-       const struct bfd_arch_info *arch = bfd_scan_arch (args);
-       if (arch != NULL)
- 	set_arch (arch, set_arch_manual);
-       else
- 	printf_unfiltered ("Architecture \`%s' not reconized.\n", args);
-     }
- }
- 
- /* Called if the user enters \`\`info architecture'' without an argument. */
- static void
- info_architecture (char *args, int from_tty)
- {
-   enum bfd_architecture a;
-   if (GDB_MULTI_ARCH)
-     {
-       if (gdbarch_init_registrary != NULL)
- 	{
- 	  struct gdbarch_init_registration *rego;
- 	  printf_filtered ("Available architectures are:\n");
- 	  for (rego = gdbarch_init_registrary;
- 	       rego != NULL;
- 	       rego = rego->next)
- 	    {
- 	      const struct bfd_arch_info *ap;
- 	      ap = bfd_lookup_arch (rego->bfd_architecture, 0);
- 	      if (ap != NULL)
- 		{
- 		  do
- 		    {
- 		      printf_filtered (" %s", ap->printable_name);
- 		      ap = ap->next;
- 		    }
- 		  while (ap != NULL);
- 		  printf_filtered ("\n");
- 		}
- 	    }
- 	}
-       else
- 	{
- 	  printf_filtered ("There are no available architectures.\n");
- 	}
-       return;
-     }
-   printf_filtered ("Available architectures are:\n");
-   for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
-     {
-       const struct bfd_arch_info *ap = bfd_lookup_arch (a, 0);
-       if (ap != NULL)
- 	{
- 	  do
- 	    {
- 	      printf_filtered (" %s", ap->printable_name);
- 	      ap = ap->next;
- 	    }
- 	  while (ap != NULL);
- 	  printf_filtered ("\n");
- 	}
-     }
- }
- 
- /* Set the architecture from arch/machine */
- void
- set_architecture_from_arch_mach (arch, mach)
-      enum bfd_architecture arch;
-      unsigned long mach;
- {
-   const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach);
-   if (wanted != NULL)
-     set_arch (wanted, set_arch_manual);
-   else
-     internal_error ("gdbarch: hardwired architecture/machine not reconized");
- }
- 
- /* Set the architecture from a BFD */
- static void
- set_architecture_from_file (bfd *abfd)
- {
-   const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd);
-   if (target_architecture_auto)
-     {
-       set_arch (wanted, set_arch_auto);
-     }
-   else if (wanted != target_architecture)
-     {
-       warning ("%s architecture file may be incompatible with %s target.",
- 	       wanted->printable_name,
- 	       target_architecture->printable_name);
-     }
- }
- 
- 
  /* Disassembler */
  
  /* Pointer to the target-dependent disassembly function.  */
--- 1761,1766 ----
*************** int (*tm_print_insn) (bfd_vma, disassemb
*** 2067,2147 ****
  disassemble_info tm_print_insn_info;
  
  
- 
- /* Set the dynamic target-system-dependant parameters (architecture,
-    byte-order) using information found in the BFD */
- 
- void
- set_gdbarch_from_file (abfd)
-      bfd *abfd;
- {
-   if (GDB_MULTI_ARCH)
-     {
-       struct gdbarch_info info;
-       memset (&info, 0, sizeof info);
-       info.abfd = abfd;
-       gdbarch_update (info);
-       return;
-     }
-   set_architecture_from_file (abfd);
-   set_endian_from_file (abfd);
- }
- 
- 
- /* Initialize the current architecture.  */
- void
- initialize_current_architecture ()
- {
-   if (GDB_MULTI_ARCH)
-     {
-       struct gdbarch_init_registration *rego;
-       const struct bfd_arch_info *chosen = NULL;
-       for (rego = gdbarch_init_registrary; rego != NULL; rego = rego->next)
- 	{
- 	  const struct bfd_arch_info *ap
- 	    = bfd_lookup_arch (rego->bfd_architecture, 0);
- 
- 	  /* Choose the first architecture alphabetically.  */
- 	  if (chosen == NULL
- 	      || strcmp (ap->printable_name, chosen->printable_name) < 0)
- 	    chosen = ap;
- 	}
- 
-       if (chosen != NULL)
- 	{
- 	  struct gdbarch_info info;
- 	  memset (&info, 0, sizeof info);
- 	  info.bfd_arch_info = chosen;
- 	  gdbarch_update (info);
- 	}
-     }
- }
- 
  extern void _initialize_gdbarch (void);
  void
  _initialize_gdbarch ()
  {
    struct cmd_list_element *c;
- 
-   add_prefix_cmd ("endian", class_support, set_endian,
- 		  "Set endianness of target.",
- 		  &endianlist, "set endian ", 0, &setlist);
-   add_cmd ("big", class_support, set_endian_big,
- 	   "Set target as being big endian.", &endianlist);
-   add_cmd ("little", class_support, set_endian_little,
- 	   "Set target as being little endian.", &endianlist);
-   add_cmd ("auto", class_support, set_endian_auto,
- 	   "Select target endianness automatically.", &endianlist);
-   add_cmd ("endian", class_support, show_endian,
- 	   "Show endianness of target.", &showlist);
- 
-   add_cmd ("architecture", class_support, set_architecture,
- 	   "Set architecture of target.", &setlist);
-   add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
-   add_cmd ("architecture", class_support, show_architecture,
- 	   "Show architecture of target.", &showlist);
-   add_cmd ("architecture", class_support, info_architecture,
- 	   "List supported target architectures", &infolist);
  
    INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
    tm_print_insn_info.flavour = bfd_target_unknown_flavour;
--- 1768,1779 ----
  disassemble_info tm_print_insn_info;
  
  
  extern void _initialize_gdbarch (void);
+ 
  void
  _initialize_gdbarch ()
  {
    struct cmd_list_element *c;
  
    INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
    tm_print_insn_info.flavour = bfd_target_unknown_flavour;
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.11
diff -p -r1.11 i386-tdep.c
*** i386-tdep.c	2000/05/28 01:12:27	1.11
--- i386-tdep.c	2000/06/07 04:21:11
***************
*** 29,34 ****
--- 29,35 ----
  #include "symtab.h"
  #include "gdbcmd.h"
  #include "command.h"
+ #include "arch-utils.h"
  
  static long i386_get_frame_setup (CORE_ADDR);
  
Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.5
diff -p -r1.5 sh-tdep.c
*** sh-tdep.c	2000/05/15 21:12:42	1.5
--- sh-tdep.c	2000/06/07 04:21:14
***************
*** 1,5 ****
  /* Target-dependent code for Hitachi Super-H, for GDB.
!    Copyright 1993, 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
  
     This file is part of GDB.
  
--- 1,6 ----
  /* Target-dependent code for Hitachi Super-H, for GDB.
!    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 2000 Free Software
!    Foundation, Inc.
  
     This file is part of GDB.
  
***************
*** 35,40 ****
--- 36,42 ----
  #include "dis-asm.h"
  #include "inferior.h"		/* for BEFORE_TEXT_END etc. */
  #include "gdb_string.h"
+ #include "arch-utils.h"
  
  /* A set of original names, to be used when restoring back to generic
     registers from a specific set.  */
Index: sh3-rom.c
===================================================================
RCS file: /cvs/src/src/gdb/sh3-rom.c,v
retrieving revision 1.2
diff -p -r1.2 sh3-rom.c
*** sh3-rom.c	2000/05/28 01:12:29	1.2
--- sh3-rom.c	2000/06/07 04:21:14
***************
*** 1,5 ****
  /* Remote target glue for the Hitachi SH-3 ROM monitor.
!    Copyright 1995, 1996 Free Software Foundation, Inc.
  
     This file is part of GDB.
  
--- 1,5 ----
  /* Remote target glue for the Hitachi SH-3 ROM monitor.
!    Copyright 1995, 1996, 2000 Free Software Foundation, Inc.
  
     This file is part of GDB.
  
***************
*** 24,29 ****
--- 24,30 ----
  #include "monitor.h"
  #include "serial.h"
  #include "srec.h"
+ #include "arch-utils.h"
  
  static serial_t parallel;
  static int parallel_in_use;
Index: v850-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/v850-tdep.c,v
retrieving revision 1.2
diff -p -r1.2 v850-tdep.c
*** v850-tdep.c	2000/05/28 01:12:33	1.2
--- v850-tdep.c	2000/06/07 04:21:16
***************
*** 1,5 ****
  /* Target-dependent code for the NEC V850 for GDB, the GNU debugger.
!    Copyright 1996, Free Software Foundation, Inc.
  
     This file is part of GDB.
  
--- 1,5 ----
  /* Target-dependent code for the NEC V850 for GDB, the GNU debugger.
!    Copyright 1996, 2000 Free Software Foundation, Inc.
  
     This file is part of GDB.
  
***************
*** 28,33 ****
--- 28,34 ----
  #include "gdb_string.h"
  #include "gdbcore.h"
  #include "symfile.h"
+ #include "arch-utils.h"
  
  
  static char *v850_generic_reg_names[] = REGISTER_NAMES;


More information about the Gdb-patches mailing list