This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[01/15] Introduce get_current_arch () function
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 9 Jun 2009 17:14:47 +0200 (CEST)
- Subject: [01/15] Introduce get_current_arch () function
Hello,
even once we're rid of current_gdbarch, the notion of a "current architecture"
will remain in some places. This applies in particular to top-level user
interface routines that operate on implicit current state.
This patch adds a new routine get_current_arch () that can be used in those
places. It checks whether there is selected stack frame at the UI level,
and uses its architecture if so. When there is no frame selected (e.g.
because we don't even have a target yet), it falls back to target_gdbarch.
The patch also goes through some of the affected top-level UI routines
and replaces instances of current_gdbarch with get_current_arch ().
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.
* tui/tui-regs.c: Include "arch-utils.h".
(tui_reg_next_command): Use get_current_arch () instead of
current_gdbarch.
* printcmd.c: Include "arch-utils.h".
(decode_format): Add GDBARCH argument. Use it instead of
current_gdbarch.
(print_command_1): Pass get_current_arch () to decode_format.
(output_command): Likewise.
(x_command): Likewise.
(display_command): Likewise.
(printf_command): 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"
@@ -3640,8 +3641,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/printcmd.c
===================================================================
--- gdb-head.orig/gdb/printcmd.c
+++ gdb-head/gdb/printcmd.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 "frame.h"
#include "symtab.h"
@@ -177,7 +178,8 @@ static void do_one_display (struct displ
past the specification and past all whitespace following it. */
static struct format_data
-decode_format (char **string_ptr, int oformat, int osize)
+decode_format (struct gdbarch *gdbarch,
+ char **string_ptr, int oformat, int osize)
{
struct format_data val;
char *p = *string_ptr;
@@ -233,11 +235,11 @@ decode_format (char **string_ptr, int of
case 'a':
case 's':
/* Pick the appropriate size for an address. */
- if (gdbarch_ptr_bit (current_gdbarch) == 64)
+ if (gdbarch_ptr_bit (gdbarch) == 64)
val.size = osize ? 'g' : osize;
- else if (gdbarch_ptr_bit (current_gdbarch) == 32)
+ else if (gdbarch_ptr_bit (gdbarch) == 32)
val.size = osize ? 'w' : osize;
- else if (gdbarch_ptr_bit (current_gdbarch) == 16)
+ else if (gdbarch_ptr_bit (gdbarch) == 16)
val.size = osize ? 'h' : osize;
else
/* Bad value for gdbarch_ptr_bit. */
@@ -865,6 +867,7 @@ validate_format (struct format_data fmt,
static void
print_command_1 (char *exp, int inspect, int voidprint)
{
+ struct gdbarch *gdbarch = get_current_arch ();
struct expression *expr;
struct cleanup *old_chain = 0;
char format = 0;
@@ -875,7 +878,7 @@ print_command_1 (char *exp, int inspect,
if (exp && *exp == '/')
{
exp++;
- fmt = decode_format (&exp, last_format, 0);
+ fmt = decode_format (gdbarch, &exp, last_format, 0);
validate_format (fmt, "print");
last_format = format = fmt.format;
}
@@ -963,6 +966,7 @@ call_command (char *exp, int from_tty)
void
output_command (char *exp, int from_tty)
{
+ struct gdbarch *gdbarch = get_current_arch ();
struct expression *expr;
struct cleanup *old_chain;
char format = 0;
@@ -976,7 +980,7 @@ output_command (char *exp, int from_tty)
if (exp && *exp == '/')
{
exp++;
- fmt = decode_format (&exp, 0, 0);
+ fmt = decode_format (gdbarch, &exp, 0, 0);
validate_format (fmt, "output");
format = fmt.format;
}
@@ -1318,6 +1322,7 @@ address_info (char *exp, int from_tty)
static void
x_command (char *exp, int from_tty)
{
+ struct gdbarch *gdbarch = get_current_arch ();
struct expression *expr;
struct format_data fmt;
struct cleanup *old_chain;
@@ -1331,7 +1336,7 @@ x_command (char *exp, int from_tty)
if (exp && *exp == '/')
{
exp++;
- fmt = decode_format (&exp, last_format, last_size);
+ fmt = decode_format (gdbarch, &exp, last_format, last_size);
}
/* If we have an expression, evaluate it and use it as the address. */
@@ -1395,6 +1400,7 @@ x_command (char *exp, int from_tty)
static void
display_command (char *exp, int from_tty)
{
+ struct gdbarch *gdbarch = get_current_arch ();
struct format_data fmt;
struct expression *expr;
struct display *new;
@@ -1418,7 +1424,7 @@ display_command (char *exp, int from_tty
if (*exp == '/')
{
exp++;
- fmt = decode_format (&exp, 0, 0);
+ fmt = decode_format (gdbarch, &exp, 0, 0);
if (fmt.size && fmt.format == 0)
fmt.format = 'x';
if (fmt.format == 'i' || fmt.format == 's')
@@ -1887,6 +1893,7 @@ print_variable_and_value (const char *na
static void
printf_command (char *arg, int from_tty)
{
+ struct gdbarch *gdbarch = get_current_arch ();
char *f = NULL;
char *s = arg;
char *string = NULL;
@@ -2272,7 +2279,7 @@ printf_command (char *arg, int from_tty)
CORE_ADDR tem;
int j;
struct type *wctype = lookup_typename (current_language,
- current_gdbarch,
+ gdbarch,
"wchar_t", NULL, 0);
int wcwidth = TYPE_LENGTH (wctype);
gdb_byte *buf = alloca (wcwidth);
@@ -2312,7 +2319,7 @@ printf_command (char *arg, int from_tty)
case wide_char_arg:
{
struct type *wctype = lookup_typename (current_language,
- current_gdbarch,
+ gdbarch,
"wchar_t", NULL, 0);
struct type *valtype;
struct obstack output;
@@ -2348,7 +2355,7 @@ printf_command (char *arg, int from_tty)
/* If format string wants a float, unchecked-convert the value
to floating point of the same size. */
- type = float_type_from_length (current_gdbarch, type);
+ type = float_type_from_length (gdbarch, type);
val = unpack_double (type, value_contents (val_args[i]), &inv);
if (inv)
error (_("Invalid floating value found in program."));
@@ -2365,7 +2372,7 @@ printf_command (char *arg, int from_tty)
/* If format string wants a float, unchecked-convert the value
to floating point of the same size. */
- type = float_type_from_length (current_gdbarch, type);
+ type = float_type_from_length (gdbarch, type);
val = unpack_double (type, value_contents (val_args[i]), &inv);
if (inv)
error (_("Invalid floating value found in program."));
@@ -2447,18 +2454,18 @@ printf_command (char *arg, int from_tty)
if (*sos == 'H')
{
dfp_len = 4;
- dfp_type = builtin_type (current_gdbarch)->builtin_decfloat;
+ dfp_type = builtin_type (gdbarch)->builtin_decfloat;
}
else if (*sos == 'D' && *(sos - 1) == 'D')
{
dfp_len = 16;
- dfp_type = builtin_type (current_gdbarch)->builtin_declong;
+ dfp_type = builtin_type (gdbarch)->builtin_declong;
sos--;
}
else
{
dfp_len = 8;
- dfp_type = builtin_type (current_gdbarch)->builtin_decdouble;
+ dfp_type = builtin_type (gdbarch)->builtin_decdouble;
}
}
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)
{
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com