Index: arch-utils.c =================================================================== RCS file: /cvs/src/src/gdb/arch-utils.c,v retrieving revision 1.204 diff -u -p -r1.204 arch-utils.c --- arch-utils.c 8 Jun 2012 14:24:56 -0000 1.204 +++ arch-utils.c 14 Oct 2012 08:24:04 -0000 @@ -32,6 +32,7 @@ #include "target-descriptions.h" #include "objfiles.h" #include "language.h" +#include "observer.h" #include "version.h" @@ -259,7 +260,7 @@ static const char *const endian_enum[] = endian_auto, NULL, }; -static const char *set_endian_string; +static const char *endian_string; enum bfd_endian selected_byte_order (void) @@ -274,14 +275,14 @@ show_endian (struct ui_file *file, int f const char *value) { if (target_byte_order_user == BFD_ENDIAN_UNKNOWN) - if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG) + if (strcmp (endian_string, endian_big) == 0) 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 (target_byte_order_user == BFD_ENDIAN_BIG) + if (strcmp (endian_string, endian_big) == 0) fprintf_unfiltered (file, _("The target is assumed to be big endian\n")); else @@ -296,14 +297,14 @@ set_endian (char *ignore_args, int from_ gdbarch_info_init (&info); - if (set_endian_string == endian_auto) + if (endian_string == endian_auto) { target_byte_order_user = BFD_ENDIAN_UNKNOWN; if (! gdbarch_update_p (info)) internal_error (__FILE__, __LINE__, _("set_endian: architecture update failed")); } - else if (set_endian_string == endian_little) + else if (endian_string == endian_little) { info.byte_order = BFD_ENDIAN_LITTLE; if (! gdbarch_update_p (info)) @@ -311,7 +312,7 @@ set_endian (char *ignore_args, int from_ else target_byte_order_user = BFD_ENDIAN_LITTLE; } - else if (set_endian_string == endian_big) + else if (endian_string == endian_big) { info.byte_order = BFD_ENDIAN_BIG; if (! gdbarch_update_p (info)) @@ -416,7 +417,7 @@ enum set_arch { set_arch_auto, set_arch_ static const struct bfd_arch_info *target_architecture_user; -static const char *set_architecture_string; +static const char *architecture_string; const char * selected_architecture_name (void) @@ -424,7 +425,7 @@ selected_architecture_name (void) if (target_architecture_user == NULL) return NULL; else - return set_architecture_string; + return architecture_string; } /* Called if the user enters ``show architecture'' without an @@ -437,10 +438,10 @@ show_architecture (struct ui_file *file, if (target_architecture_user == NULL) fprintf_filtered (file, _("The target architecture is set " "automatically (currently %s)\n"), - gdbarch_bfd_arch_info (get_current_arch ())->printable_name); + architecture_string); else fprintf_filtered (file, _("The target architecture is assumed to be %s\n"), - set_architecture_string); + architecture_string); } @@ -454,7 +455,7 @@ set_architecture (char *ignore_args, int gdbarch_info_init (&info); - if (strcmp (set_architecture_string, "auto") == 0) + if (strcmp (architecture_string, "auto") == 0) { target_architecture_user = NULL; if (!gdbarch_update_p (info)) @@ -463,7 +464,7 @@ set_architecture (char *ignore_args, int } else { - info.bfd_arch_info = bfd_scan_arch (set_architecture_string); + info.bfd_arch_info = bfd_scan_arch (architecture_string); if (info.bfd_arch_info == NULL) internal_error (__FILE__, __LINE__, _("set_architecture: bfd_scan_arch failed")); @@ -471,7 +472,7 @@ set_architecture (char *ignore_args, int target_architecture_user = info.bfd_arch_info; else printf_unfiltered (_("Architecture `%s' not recognized.\n"), - set_architecture_string); + architecture_string); } show_architecture (gdb_stdout, from_tty, NULL, NULL); } @@ -579,6 +580,22 @@ static const bfd_target *default_bfd_vec static int default_byte_order = BFD_ENDIAN_UNKNOWN; +static void +set_endian_string (struct gdbarch *arch) +{ + if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG) + endian_string = endian_big; + else + endian_string = endian_little; +} + +static void +on_architecture_change (struct gdbarch *arch) +{ + architecture_string = gdbarch_bfd_arch_info (arch)->printable_name; + set_endian_string (arch); +} + void initialize_current_architecture (void) { @@ -655,19 +672,26 @@ initialize_current_architecture (void) /* Create the ``set architecture'' command appending ``auto'' to the list of architectures. */ { - /* Append ``auto''. */ int nr; + struct gdbarch *arch = get_current_arch (); + + /* Append ``auto''. */ for (nr = 0; arches[nr] != NULL; nr++); arches = xrealloc (arches, sizeof (char*) * (nr + 2)); arches[nr + 0] = "auto"; arches[nr + 1] = NULL; + + architecture_string = gdbarch_bfd_arch_info (arch)->printable_name; + set_endian_string (arch); + add_setshow_enum_cmd ("architecture", class_support, - arches, &set_architecture_string, + arches, &architecture_string, _("Set architecture of target."), _("Show architecture of target."), NULL, set_architecture, show_architecture, &setlist, &showlist); add_alias_cmd ("processor", "architecture", class_support, 1, &setlist); + observer_attach_architecture_changed (on_architecture_change); } } @@ -813,7 +837,7 @@ void _initialize_gdbarch_utils (void) { add_setshow_enum_cmd ("endian", class_support, - endian_enum, &set_endian_string, + endian_enum, &endian_string, _("Set endianness of target."), _("Show endianness of target."), NULL, set_endian, show_endian, Index: testsuite/gdb.python/py-parameter.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-parameter.exp,v retrieving revision 1.6 diff -u -p -r1.6 py-parameter.exp --- testsuite/gdb.python/py-parameter.exp 16 Jan 2012 16:21:52 -0000 1.6 +++ testsuite/gdb.python/py-parameter.exp 14 Oct 2012 08:24:04 -0000 @@ -26,6 +26,8 @@ gdb_reinitialize_dir $srcdir/$subdir # Skip all tests if Python scripting is not enabled. if { [skip_python_tests] } { continue } +gdb_py_test_silent_cmd "python import sys" "Import sys" "" +gdb_test "python print gdb.parameter ('endian') == sys.byteorder" "True" # We use "." here instead of ":" so that this works on win32 too. gdb_test "python print gdb.parameter ('directories')" "$srcdir/$subdir.\\\$cdir.\\\$cwd"