* [01/15] Introduce get_current_arch () function
@ 2009-06-09 15:15 Ulrich Weigand
2009-06-09 17:04 ` Tom Tromey
0 siblings, 1 reply; 9+ messages in thread
From: Ulrich Weigand @ 2009-06-09 15:15 UTC (permalink / raw)
To: gdb-patches
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [01/15] Introduce get_current_arch () function
2009-06-09 15:15 [01/15] Introduce get_current_arch () function Ulrich Weigand
@ 2009-06-09 17:04 ` Tom Tromey
2009-06-10 15:36 ` Ulrich Weigand
0 siblings, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2009-06-09 17:04 UTC (permalink / raw)
To: Ulrich Weigand; +Cc: gdb-patches
>>>>> "Ulrich" == Ulrich Weigand <uweigand@de.ibm.com> writes:
Ulrich> printf_command (char *arg, int from_tty)
Ulrich> {
Ulrich> + struct gdbarch *gdbarch = get_current_arch ();
I think that perhaps the printf command should use the arch from the
values it is trying to print.
Ulrich> struct type *wctype = lookup_typename (current_language,
Ulrich> - current_gdbarch,
Ulrich> + gdbarch,
Ulrich> "wchar_t", NULL, 0);
E.g., here it could use the architecture from val_args[i].
The benefit here would be that you could print out two wide strings,
each from a different architecture, using a single printf. This seems
like a reasonable thing to want to do.
Tom
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [01/15] Introduce get_current_arch () function
2009-06-09 17:04 ` Tom Tromey
@ 2009-06-10 15:36 ` Ulrich Weigand
2009-06-10 16:40 ` Tom Tromey
2009-06-10 16:49 ` Pedro Alves
0 siblings, 2 replies; 9+ messages in thread
From: Ulrich Weigand @ 2009-06-10 15:36 UTC (permalink / raw)
To: tromey; +Cc: gdb-patches
Tom Tromey wrote:
> >>>>> "Ulrich" == Ulrich Weigand <uweigand@de.ibm.com> writes:
>
> Ulrich> printf_command (char *arg, int from_tty)
> Ulrich> {
> Ulrich> + struct gdbarch *gdbarch = get_current_arch ();
>
> I think that perhaps the printf command should use the arch from the
> values it is trying to print.
>
> Ulrich> struct type *wctype = lookup_typename (current_language,
> Ulrich> - current_gdbarch,
> Ulrich> + gdbarch,
> Ulrich> "wchar_t", NULL, 0);
>
> E.g., here it could use the architecture from val_args[i].
>
> The benefit here would be that you could print out two wide strings,
> each from a different architecture, using a single printf. This seems
> like a reasonable thing to want to do.
There wouldn't really be much of a difference today, as the architecture
of val_args[i] is the architecture of the expression from which it was
evaluated, which is likewise get_current_arch ().
However, you're right that it would be more straightforward to use the
value arch here, in case we might later decide to allow evaluation of
an expression to return values in a different arch.
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [01/15] Introduce get_current_arch () function
2009-06-10 15:36 ` Ulrich Weigand
@ 2009-06-10 16:40 ` Tom Tromey
2009-06-10 18:14 ` Ulrich Weigand
2009-06-10 16:49 ` Pedro Alves
1 sibling, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2009-06-10 16:40 UTC (permalink / raw)
To: Ulrich Weigand; +Cc: gdb-patches
>>>>> "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.
Tom
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [01/15] Introduce get_current_arch () function
2009-06-10 15:36 ` Ulrich Weigand
2009-06-10 16:40 ` Tom Tromey
@ 2009-06-10 16:49 ` Pedro Alves
2009-06-10 18:27 ` Ulrich Weigand
1 sibling, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2009-06-10 16:49 UTC (permalink / raw)
To: gdb-patches; +Cc: Ulrich Weigand, tromey
On Wednesday 10 June 2009 16:36:14, Ulrich Weigand wrote:
> Tom Tromey wrote:
> > >>>>> "Ulrich" == Ulrich Weigand <uweigand@de.ibm.com> writes:
> >
> > Ulrich> printf_command (char *arg, int from_tty)
> > Ulrich> {
> > Ulrich> + struct gdbarch *gdbarch = get_current_arch ();
> >
> > I think that perhaps the printf command should use the arch from the
> > values it is trying to print.
> >
> > Ulrich> struct type *wctype = lookup_typename (current_language,
> > Ulrich> - current_gdbarch,
> > Ulrich> + gdbarch,
> > Ulrich> "wchar_t", NULL, 0);
> >
> > E.g., here it could use the architecture from val_args[i].
> >
> > The benefit here would be that you could print out two wide strings,
> > each from a different architecture, using a single printf. This seems
> > like a reasonable thing to want to do.
>
> There wouldn't really be much of a difference today, as the architecture
> of val_args[i] is the architecture of the expression from which it was
> evaluated, which is likewise get_current_arch ().
>
> However, you're right that it would be more straightforward to use the
> value arch here, in case we might later decide to allow evaluation of
> an expression to return values in a different arch.
I haven't actually studied the patch set, so sorry if this sounds
way off, but Tom's remark made me wonder how does this interact with
re-printing values from the history ($1, $2, $nnn) or convenience
variables? As in, what would be the arch used to print $nnn? Should it
be the current arch, or the arch that was used when the value was produced? A
simple example where it can be a different arch is if you debug
inferior/target foo, print something, kill/disconnect, debug
inferior/target 2, reprint value from history.
I see from the hunk above that the language used is always the
current language, so it may be right to always use the current arch...
--
Pedro Alves
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [01/15] Introduce get_current_arch () function
2009-06-10 16:40 ` Tom Tromey
@ 2009-06-10 18:14 ` Ulrich Weigand
2009-07-02 17:04 ` Ulrich Weigand
0 siblings, 1 reply; 9+ messages in thread
From: Ulrich Weigand @ 2009-06-10 18:14 UTC (permalink / raw)
To: tromey; +Cc: gdb-patches
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.
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [01/15] Introduce get_current_arch () function
2009-06-10 16:49 ` Pedro Alves
@ 2009-06-10 18:27 ` Ulrich Weigand
2009-06-10 19:23 ` Pedro Alves
0 siblings, 1 reply; 9+ messages in thread
From: Ulrich Weigand @ 2009-06-10 18:27 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches, tromey
Pedro Alves wrote:
> I haven't actually studied the patch set, so sorry if this sounds
> way off, but Tom's remark made me wonder how does this interact with
> re-printing values from the history ($1, $2, $nnn) or convenience
> variables? As in, what would be the arch used to print $nnn? Should it
> be the current arch, or the arch that was used when the value was produced? A
> simple example where it can be a different arch is if you debug
> inferior/target foo, print something, kill/disconnect, debug
> inferior/target 2, reprint value from history.
Typically, the architecture is consulted to retrieve properties the
value inherently has, so using the arch used at value creation seems
correct. However, I'm sure there will be places where using a value
from one arch in the context of another current arch may not work
quite as expected yet ... I didn't attempt to address all these
issues with the current patch series yet.
> I see from the hunk above that the language used is always the
> current language, so it may be right to always use the current arch...
Actually, I'm not sure using the current language is correct
here either ... (In this particular piece of code, it doesn't
seem to matter either way right now, because lookup_typename
only depends on lang/arch when searching for primitive types,
which wchar_t isn't.)
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [01/15] Introduce get_current_arch () function
2009-06-10 18:27 ` Ulrich Weigand
@ 2009-06-10 19:23 ` Pedro Alves
0 siblings, 0 replies; 9+ messages in thread
From: Pedro Alves @ 2009-06-10 19:23 UTC (permalink / raw)
To: Ulrich Weigand; +Cc: gdb-patches, tromey
On Wednesday 10 June 2009 19:26:04, Ulrich Weigand wrote:
> Typically, the architecture is consulted to retrieve properties the
> value inherently has, so using the arch used at value creation seems
> correct. However, I'm sure there will be places where using a value
> from one arch in the context of another current arch may not work
> quite as expected yet ...
Yeah. Just 'p func($1)' or 'p $2 + 1.1f' are some "simple"
examples.
> I didn't attempt to address all these
> issues with the current patch series yet.
You're doing an Herculian job already!
--
Pedro Alves
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [01/15] Introduce get_current_arch () function
2009-06-10 18:14 ` Ulrich Weigand
@ 2009-07-02 17:04 ` Ulrich Weigand
0 siblings, 0 replies; 9+ messages in thread
From: Ulrich Weigand @ 2009-07-02 17:04 UTC (permalink / raw)
To: Ulrich Weigand; +Cc: tromey, gdb-patches
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-07-02 17:04 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-09 15:15 [01/15] Introduce get_current_arch () function Ulrich Weigand
2009-06-09 17:04 ` Tom Tromey
2009-06-10 15:36 ` Ulrich Weigand
2009-06-10 16:40 ` Tom Tromey
2009-06-10 18:14 ` Ulrich Weigand
2009-07-02 17:04 ` Ulrich Weigand
2009-06-10 16:49 ` Pedro Alves
2009-06-10 18:27 ` Ulrich Weigand
2009-06-10 19:23 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox