This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [01/15] Introduce get_current_arch () function


> Tom Tromey wrote:
> > >>>>> "Ulrich" == Ulrich Weigand <uweigand@de.ibm.com> writes:
> > 
> > Ulrich> There wouldn't really be much of a difference today, as the architecture
> > Ulrich> of val_args[i] is the architecture of the expression from which it was
> > Ulrich> evaluated, which is likewise get_current_arch ().
> > 
> > Is that true even if the expression is something like "$var"?
> > I did not read the patch series *that* closely, but I would have
> > assumed that the arch of the resulting value would come directly from
> > the convenience variable's value -- which could be anything.
> 
> Ah, you're right.  For convenience variables or values from the
> history, you can get indeed another architecture.

Here's the version of the patch I've just committed -- this does
not use get_current_arch in printcmd.c, as you suggested.

Bye,
Ulrich

ChangeLog:

	* arch-utils.c (selected_byte_order): Return target_byte_order_user.
	(show_endian): Use target_byte_order_user if specified; otherwise
	use get_current_arch () instead of current_gdbarch.
	(show_architecture): Use set_architecture_string if specified;
	otherwise use get_current_arch () instead of current_gdbarch.
	(get_current_arch): New function.
	* arch-utils.h (get_current_arch): Add prototype.

	* osabi.c (show_osabi): Use get_current_arch () instead of
	current_gdbarch.

	* findcmd.c: Include "arch-utils.h".
	(parse_find_args): Add BIG_P argument.  Use it instead of byte order
	of current_gdbarch.
	(find_command): Use get_current_arch () instead of current_gdbarch.
	Pass byte order to parse_find_args.

	* maint.c: Include "arch-utils.h".
	(maintenance_print_architecture): Use get_current_arch () instead
	of current_gdbarch.

	* reggroups.c: Include "arch-utils.h".
	(maintenance_print_reggroups): Use get_current_arch () instead
	of current_gdbarch.

	* symfile.c: Include "arch-utils.h".
	(overlay_load_command): Use get_current_arch () instead of
	current_gdbarch.

	* value.c: Include "arch-utils.h".
	(show_convenience): Use get_current_arch () instead of
	current_gdbarch.

	* tui/tui-regs.c: Include "arch-utils.h".
	(tui_reg_next_command): Use get_current_arch () instead of
	current_gdbarch.

	* mi/mi-main.c: Include "arch-utils.h".
	(mi_cmd_data_read_memory): Use get_current_arch () instead of
	current_gdbarch.

	* parse.c: Include "arch-utils.h".
	(parse_exp_in_context): Use get_current_arch () instead of
	current_gdbarch.


Index: gdb-head/gdb/arch-utils.c
===================================================================
--- gdb-head.orig/gdb/arch-utils.c
+++ gdb-head/gdb/arch-utils.c
@@ -260,10 +260,7 @@ static const char *set_endian_string;
 enum bfd_endian
 selected_byte_order (void)
 {
-  if (target_byte_order_user != BFD_ENDIAN_UNKNOWN)
-    return gdbarch_byte_order (current_gdbarch);
-  else
-    return BFD_ENDIAN_UNKNOWN;
+  return target_byte_order_user;
 }
 
 /* Called by ``show endian''.  */
@@ -273,14 +270,14 @@ show_endian (struct ui_file *file, int f
 	     const char *value)
 {
   if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
-    if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+    if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
       fprintf_unfiltered (file, _("The target endianness is set automatically "
 				  "(currently big endian)\n"));
     else
       fprintf_unfiltered (file, _("The target endianness is set automatically "
 			   "(currently little endian)\n"));
   else
-    if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+    if (target_byte_order_user == BFD_ENDIAN_BIG)
       fprintf_unfiltered (file,
 			  _("The target is assumed to be big endian\n"));
     else
@@ -418,14 +415,13 @@ static void
 show_architecture (struct ui_file *file, int from_tty,
 		   struct cmd_list_element *c, const char *value)
 {
-  const char *arch;
-  arch = gdbarch_bfd_arch_info (current_gdbarch)->printable_name;
   if (target_architecture_user == NULL)
     fprintf_filtered (file, _("\
-The target architecture is set automatically (currently %s)\n"), arch);
+The target architecture is set automatically (currently %s)\n"),
+		gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
   else
     fprintf_filtered (file, _("\
-The target architecture is assumed to be %s\n"), arch);
+The target architecture is assumed to be %s\n"), set_architecture_string);
 }
 
 
@@ -720,6 +716,21 @@ gdbarch_info_fill (struct gdbarch_info *
   gdb_assert (info->bfd_arch_info != NULL);
 }
 
+/* Return "current" architecture.  If the target is running, this is the
+   architecture of the selected frame.  Otherwise, the "current" architecture
+   defaults to the target architecture.
+
+   This function should normally be called solely by the command interpreter
+   routines to determine the architecture to execute a command in.  */
+struct gdbarch *
+get_current_arch (void)
+{
+  if (has_stack_frames ())
+    return get_frame_arch (get_selected_frame (NULL));
+  else
+    return target_gdbarch;
+}
+
 /* */
 
 extern initialize_file_ftype _initialize_gdbarch_utils; /* -Wmissing-prototypes */
Index: gdb-head/gdb/arch-utils.h
===================================================================
--- gdb-head.orig/gdb/arch-utils.h
+++ gdb-head/gdb/arch-utils.h
@@ -139,4 +139,12 @@ extern void gdbarch_info_fill (struct gd
 
 extern struct gdbarch *gdbarch_from_bfd (bfd *abfd);
 
+/* Return "current" architecture.  If the target is running, this is the
+   architecture of the selected frame.  Otherwise, the "current" architecture
+   defaults to the target architecture.
+
+   This function should normally be called solely by the command interpreter
+   routines to determine the architecture to execute a command in.  */
+extern struct gdbarch *get_current_arch (void);
+
 #endif
Index: gdb-head/gdb/findcmd.c
===================================================================
--- gdb-head.orig/gdb/findcmd.c
+++ gdb-head/gdb/findcmd.c
@@ -18,6 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include <ctype.h>
 #include "gdb_string.h"
 #include "gdbcmd.h"
@@ -50,7 +51,8 @@ put_bits (bfd_uint64_t data, char *buf, 
 static void
 parse_find_args (char *args, ULONGEST *max_countp,
 		 char **pattern_bufp, ULONGEST *pattern_lenp,
-		 CORE_ADDR *start_addrp, ULONGEST *search_space_lenp)
+		 CORE_ADDR *start_addrp, ULONGEST *search_space_lenp,
+		 bfd_boolean big_p)
 {
   /* Default to using the specified type.  */
   char size = '\0';
@@ -67,7 +69,6 @@ parse_find_args (char *args, ULONGEST *m
   CORE_ADDR start_addr;
   ULONGEST search_space_len;
   char *s = args;
-  bfd_boolean big_p = gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG;
   struct cleanup *old_cleanups;
   struct value *v;
 
@@ -239,6 +240,8 @@ parse_find_args (char *args, ULONGEST *m
 static void
 find_command (char *args, int from_tty)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
+  bfd_boolean big_p = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG;
   /* Command line parameters.
      These are initialized to avoid uninitialized warnings from -Wall.  */
   ULONGEST max_count = 0;
@@ -252,7 +255,7 @@ find_command (char *args, int from_tty)
   struct cleanup *old_cleanups;
 
   parse_find_args (args, &max_count, &pattern_buf, &pattern_len, 
-		   &start_addr, &search_space_len);
+		   &start_addr, &search_space_len, big_p);
 
   old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
 
@@ -294,7 +297,6 @@ find_command (char *args, int from_tty)
   set_internalvar_integer (lookup_internalvar ("numfound"), found_count);
   if (found_count > 0)
     {
-      struct gdbarch *gdbarch = current_gdbarch;
       struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
       set_internalvar (lookup_internalvar ("_"),
 		       value_from_pointer (ptr_type, last_found_addr));
Index: gdb-head/gdb/maint.c
===================================================================
--- gdb-head.orig/gdb/maint.c
+++ gdb-head/gdb/maint.c
@@ -22,6 +22,7 @@
 
 
 #include "defs.h"
+#include "arch-utils.h"
 #include <ctype.h>
 #include <signal.h>
 #include "command.h"
@@ -411,8 +412,10 @@ maintenance_print_statistics (char *args
 static void
 maintenance_print_architecture (char *args, int from_tty)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
+
   if (args == NULL)
-    gdbarch_dump (current_gdbarch, gdb_stdout);
+    gdbarch_dump (gdbarch, gdb_stdout);
   else
     {
       struct cleanup *cleanups;
@@ -420,7 +423,7 @@ maintenance_print_architecture (char *ar
       if (file == NULL)
 	perror_with_name (_("maintenance print architecture"));
       cleanups = make_cleanup_ui_file_delete (file);
-      gdbarch_dump (current_gdbarch, file);    
+      gdbarch_dump (gdbarch, file);
       do_cleanups (cleanups);
     }
 }
Index: gdb-head/gdb/reggroups.c
===================================================================
--- gdb-head.orig/gdb/reggroups.c
+++ gdb-head/gdb/reggroups.c
@@ -20,6 +20,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include "reggroups.h"
 #include "gdbtypes.h"
 #include "gdb_assert.h"
@@ -230,8 +231,10 @@ reggroups_dump (struct gdbarch *gdbarch,
 static void
 maintenance_print_reggroups (char *args, int from_tty)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
+
   if (args == NULL)
-    reggroups_dump (current_gdbarch, gdb_stdout);
+    reggroups_dump (gdbarch, gdb_stdout);
   else
     {
       struct cleanup *cleanups;
@@ -239,7 +242,7 @@ maintenance_print_reggroups (char *args,
       if (file == NULL)
 	perror_with_name (_("maintenance print reggroups"));
       cleanups = make_cleanup_ui_file_delete (file);
-      reggroups_dump (current_gdbarch, file);    
+      reggroups_dump (gdbarch, file);
       do_cleanups (cleanups);
     }
 }
Index: gdb-head/gdb/symfile.c
===================================================================
--- gdb-head.orig/gdb/symfile.c
+++ gdb-head/gdb/symfile.c
@@ -22,6 +22,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include "bfdlink.h"
 #include "symtab.h"
 #include "gdbtypes.h"
@@ -3643,8 +3644,10 @@ overlay_off_command (char *args, int fro
 static void
 overlay_load_command (char *args, int from_tty)
 {
-  if (gdbarch_overlay_update_p (current_gdbarch))
-    gdbarch_overlay_update (current_gdbarch, NULL);
+  struct gdbarch *gdbarch = get_current_arch ();
+
+  if (gdbarch_overlay_update_p (gdbarch))
+    gdbarch_overlay_update (gdbarch, NULL);
   else
     error (_("This target does not know how to read its overlay state."));
 }
Index: gdb-head/gdb/tui/tui-regs.c
===================================================================
--- gdb-head.orig/gdb/tui/tui-regs.c
+++ gdb-head/gdb/tui/tui-regs.c
@@ -21,6 +21,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include "tui/tui.h"
 #include "tui/tui-data.h"
 #include "symtab.h"
@@ -558,14 +559,16 @@ tui_display_register (struct tui_data_el
 static void
 tui_reg_next_command (char *arg, int from_tty)
 {
+  struct gdbarch *gdbarch = get_current_arch ();
+
   if (TUI_DATA_WIN != 0)
     {
       struct reggroup *group
         = TUI_DATA_WIN->detail.data_display_info.current_group;
 
-      group = reggroup_next (current_gdbarch, group);
+      group = reggroup_next (gdbarch, group);
       if (group == 0)
-        group = reggroup_next (current_gdbarch, 0);
+        group = reggroup_next (gdbarch, 0);
 
       if (group)
         tui_show_registers (group);
Index: gdb-head/gdb/osabi.c
===================================================================
--- gdb-head.orig/gdb/osabi.c
+++ gdb-head/gdb/osabi.c
@@ -596,7 +596,7 @@ show_osabi (struct ui_file *file, int fr
   if (user_osabi_state == osabi_auto)
     fprintf_filtered (file,
 		      _("The current OS ABI is \"auto\" (currently \"%s\").\n"),
-		      gdbarch_osabi_name (gdbarch_osabi (current_gdbarch)));
+		      gdbarch_osabi_name (gdbarch_osabi (get_current_arch ())));
   else
     fprintf_filtered (file, _("The current OS ABI is \"%s\".\n"),
 		      gdbarch_osabi_name (user_selected_osabi));
Index: gdb-head/gdb/parse.c
===================================================================
--- gdb-head.orig/gdb/parse.c
+++ gdb-head/gdb/parse.c
@@ -34,6 +34,7 @@
 #include <ctype.h>
 
 #include "defs.h"
+#include "arch-utils.h"
 #include "gdb_string.h"
 #include "symtab.h"
 #include "gdbtypes.h"
@@ -1086,7 +1087,7 @@ parse_exp_in_context (char **stringptr, 
   expout = (struct expression *)
     xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size));
   expout->language_defn = current_language;
-  expout->gdbarch = current_gdbarch;
+  expout->gdbarch = get_current_arch ();
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
Index: gdb-head/gdb/mi/mi-main.c
===================================================================
--- gdb-head.orig/gdb/mi/mi-main.c
+++ gdb-head/gdb/mi/mi-main.c
@@ -23,6 +23,7 @@
 /* Work in progress.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include "target.h"
 #include "inferior.h"
 #include "gdb_string.h"
@@ -828,7 +829,7 @@ mi_cmd_data_evaluate_expression (char *c
 void
 mi_cmd_data_read_memory (char *command, char **argv, int argc)
 {
-  struct gdbarch *gdbarch = current_gdbarch;
+  struct gdbarch *gdbarch = get_current_arch ();
   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
   CORE_ADDR addr;
   long total_bytes;
Index: gdb-head/gdb/value.c
===================================================================
--- gdb-head.orig/gdb/value.c
+++ gdb-head/gdb/value.c
@@ -20,6 +20,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include "gdb_string.h"
 #include "symtab.h"
 #include "gdbtypes.h"
@@ -1448,7 +1449,7 @@ preserve_values (struct objfile *objfile
 static void
 show_convenience (char *ignore, int from_tty)
 {
-  struct gdbarch *gdbarch = current_gdbarch;
+  struct gdbarch *gdbarch = get_current_arch ();
   struct internalvar *var;
   int varseen = 0;
   struct value_print_options opts;

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]