This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfc] Make register_type calls more consistent
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sourceware dot org
- Date: Wed, 10 Jan 2007 16:38:09 -0500
- Subject: [rfc] Make register_type calls more consistent
This was originally a cleanup for the XML-based register support,
but I don't think I'll need it after all. It seems worthwhile anyway,
though - fewer ways to do the same thing is a win in my book. This
summarizes it:
-/* REGISTER_TYPE is a direct replacement for DEPRECATED_REGISTER_VIRTUAL_TYPE. */
+/* Return the type of a register specified by the architecture. Only
+ the register cache should call this function directly; others should
+ use "register_type". */
I just changed all places calling their own foo_register_type method or
gdbarch_register_type to call register_type, and added a comment;
hopefully between the two changes, it won't recur. Calling
register_type is marginally more efficient since it caches the types
without having lots of branches.
OK?
--
Daniel Jacobowitz
CodeSourcery
2007-01-10 Daniel Jacobowitz <dan@codesourcery.com>
* gdbarch.sh (register_type): Update comment.
* gdbarch.h: Regenerated.
* arch-utils.c (generic_register_size): Call register_type.
* ia64-tdep.c (ia64_extract_return_value): Likewise.
* m32c-tdep.c (check_for_saved): Likewise.
* mips-tdep.c (mips_print_register, print_gp_register_row)
(mips_print_registers_info): Likewise.
* sh-tdep.c (sh_pseudo_register_read, sh_pseudo_register_write):
Likewise.
* sh64-tdep.c (sh64_pseudo_register_read, sh64_pseudo_register_write)
(sh64_do_register, sh64_print_register)
(sh64_media_print_registers_info): Likewise.
* tui/tui-regs.c (tui_register_format): Likewise.
---
gdb/arch-utils.c | 2 +-
gdb/gdbarch.h | 4 +++-
gdb/gdbarch.sh | 4 +++-
gdb/ia64-tdep.c | 3 ++-
gdb/m32c-tdep.c | 2 +-
gdb/mips-tdep.c | 10 +++++-----
gdb/sh-tdep.c | 4 ++--
gdb/sh64-tdep.c | 19 ++++++++-----------
gdb/tui/tui-regs.c | 2 +-
9 files changed, 26 insertions(+), 24 deletions(-)
Index: src/gdb/arch-utils.c
===================================================================
--- src.orig/gdb/arch-utils.c 2007-01-09 17:57:40.000000000 -0500
+++ src/gdb/arch-utils.c 2007-01-10 16:22:36.000000000 -0500
@@ -273,7 +273,7 @@ int
generic_register_size (int regnum)
{
gdb_assert (regnum >= 0 && regnum < NUM_REGS + NUM_PSEUDO_REGS);
- return TYPE_LENGTH (gdbarch_register_type (current_gdbarch, regnum));
+ return TYPE_LENGTH (register_type (current_gdbarch, regnum));
}
/* Assume all registers are adjacent. */
Index: src/gdb/gdbarch.h
===================================================================
--- src.orig/gdb/gdbarch.h 2007-01-09 09:27:48.000000000 -0500
+++ src/gdb/gdbarch.h 2007-01-10 16:22:36.000000000 -0500
@@ -469,7 +469,9 @@ extern void set_gdbarch_register_name (s
#define REGISTER_NAME(regnr) (gdbarch_register_name (current_gdbarch, regnr))
#endif
-/* REGISTER_TYPE is a direct replacement for DEPRECATED_REGISTER_VIRTUAL_TYPE. */
+/* Return the type of a register specified by the architecture. Only
+ the register cache should call this function directly; others should
+ use "register_type". */
extern int gdbarch_register_type_p (struct gdbarch *gdbarch);
Index: src/gdb/gdbarch.sh
===================================================================
--- src.orig/gdb/gdbarch.sh 2007-01-09 13:13:20.000000000 -0500
+++ src/gdb/gdbarch.sh 2007-01-10 16:22:36.000000000 -0500
@@ -455,7 +455,9 @@ f:=:int:sdb_reg_to_regnum:int sdb_regnr:
f:=:int:dwarf2_reg_to_regnum:int dwarf2_regnr:dwarf2_regnr::no_op_reg_to_regnum::0
f:=:const char *:register_name:int regnr:regnr
-# REGISTER_TYPE is a direct replacement for DEPRECATED_REGISTER_VIRTUAL_TYPE.
+# Return the type of a register specified by the architecture. Only
+# the register cache should call this function directly; others should
+# use "register_type".
M::struct type *:register_type:int reg_nr:reg_nr
# If the value returned by DEPRECATED_REGISTER_BYTE agrees with the
# register offsets computed using just REGISTER_TYPE, this can be
Index: src/gdb/ia64-tdep.c
===================================================================
--- src.orig/gdb/ia64-tdep.c 2007-01-09 13:13:23.000000000 -0500
+++ src/gdb/ia64-tdep.c 2007-01-10 16:22:36.000000000 -0500
@@ -3034,7 +3034,8 @@ ia64_extract_return_value (struct type *
ULONGEST val;
int offset = 0;
int regnum = IA64_GR8_REGNUM;
- int reglen = TYPE_LENGTH (ia64_register_type (NULL, IA64_GR8_REGNUM));
+ int reglen = TYPE_LENGTH (register_type (get_regcache_arch (regcache),
+ IA64_GR8_REGNUM));
int n = TYPE_LENGTH (type) / reglen;
int m = TYPE_LENGTH (type) % reglen;
Index: src/gdb/m32c-tdep.c
===================================================================
--- src.orig/gdb/m32c-tdep.c 2007-01-09 17:57:42.000000000 -0500
+++ src/gdb/m32c-tdep.c 2007-01-10 16:22:36.000000000 -0500
@@ -1481,7 +1481,7 @@ check_for_saved (void *prologue_untyped,
if (value.reg == tdep->pc->num)
saved_size = tdep->ret_addr_bytes;
- else if (gdbarch_register_type (arch, value.reg)
+ else if (register_type (arch, value.reg)
== tdep->data_addr_reg_type)
saved_size = tdep->push_addr_bytes;
Index: src/gdb/mips-tdep.c
===================================================================
--- src.orig/gdb/mips-tdep.c 2007-01-09 13:13:27.000000000 -0500
+++ src/gdb/mips-tdep.c 2007-01-10 16:22:36.000000000 -0500
@@ -4031,7 +4031,7 @@ mips_print_register (struct ui_file *fil
gdb_byte raw_buffer[MAX_REGISTER_SIZE];
int offset;
- if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
+ if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
{
mips_print_fp_register (file, frame, regnum);
return;
@@ -4063,7 +4063,7 @@ mips_print_register (struct ui_file *fil
offset = 0;
print_scalar_formatted (raw_buffer + offset,
- gdbarch_register_type (gdbarch, regnum), 'x', 0,
+ register_type (gdbarch, regnum), 'x', 0,
file);
}
@@ -4100,7 +4100,7 @@ print_gp_register_row (struct ui_file *f
{
if (*REGISTER_NAME (regnum) == '\0')
continue; /* unused register */
- if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) ==
+ if (TYPE_CODE (register_type (gdbarch, regnum)) ==
TYPE_CODE_FLT)
break; /* end the row: reached FP register */
if (col == 0)
@@ -4126,7 +4126,7 @@ print_gp_register_row (struct ui_file *f
{
if (*REGISTER_NAME (regnum) == '\0')
continue; /* unused register */
- if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) ==
+ if (TYPE_CODE (register_type (gdbarch, regnum)) ==
TYPE_CODE_FLT)
break; /* end row: reached FP register */
/* OK: get the data in raw format. */
@@ -4178,7 +4178,7 @@ mips_print_registers_info (struct gdbarc
regnum = NUM_REGS;
while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
{
- if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) ==
+ if (TYPE_CODE (register_type (gdbarch, regnum)) ==
TYPE_CODE_FLT)
{
if (all) /* true for "INFO ALL-REGISTERS" command */
Index: src/gdb/sh-tdep.c
===================================================================
--- src.orig/gdb/sh-tdep.c 2007-01-09 13:13:31.000000000 -0500
+++ src/gdb/sh-tdep.c 2007-01-10 16:22:36.000000000 -0500
@@ -2004,7 +2004,7 @@ sh_pseudo_register_read (struct gdbarch
base_regnum) * portion));
/* We must pay attention to the endiannes. */
sh_register_convert_to_virtual (reg_nr,
- gdbarch_register_type (gdbarch, reg_nr),
+ register_type (gdbarch, reg_nr),
temp_buffer, buffer);
}
else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
@@ -2044,7 +2044,7 @@ sh_pseudo_register_write (struct gdbarch
base_regnum = dr_reg_base_num (reg_nr);
/* We must pay attention to the endiannes. */
- sh_register_convert_to_raw (gdbarch_register_type (gdbarch, reg_nr),
+ sh_register_convert_to_raw (register_type (gdbarch, reg_nr),
reg_nr, buffer, temp_buffer);
/* Write the real regs for which this one is an alias. */
Index: src/gdb/sh64-tdep.c
===================================================================
--- src.orig/gdb/sh64-tdep.c 2007-01-09 13:13:31.000000000 -0500
+++ src/gdb/sh64-tdep.c 2007-01-10 16:22:36.000000000 -0500
@@ -1597,8 +1597,7 @@ sh64_pseudo_register_read (struct gdbarc
/* We must pay attention to the endianness. */
sh64_register_convert_to_virtual (reg_nr,
- gdbarch_register_type (gdbarch,
- reg_nr),
+ register_type (gdbarch, reg_nr),
temp_buffer, buffer);
}
@@ -1669,8 +1668,7 @@ sh64_pseudo_register_read (struct gdbarc
/* We must pay attention to the endianness. */
sh64_register_convert_to_virtual (reg_nr,
- gdbarch_register_type (gdbarch,
- reg_nr),
+ register_type (gdbarch, reg_nr),
temp_buffer, buffer);
}
@@ -1755,7 +1753,7 @@ sh64_pseudo_register_write (struct gdbar
{
base_regnum = sh64_dr_reg_base_num (reg_nr);
/* We must pay attention to the endianness. */
- sh64_register_convert_to_raw (gdbarch_register_type (gdbarch, reg_nr),
+ sh64_register_convert_to_raw (register_type (gdbarch, reg_nr),
reg_nr,
buffer, temp_buffer);
@@ -1829,8 +1827,7 @@ sh64_pseudo_register_write (struct gdbar
for (portion = 0; portion < 2; portion++)
{
/* We must pay attention to the endianness. */
- sh64_register_convert_to_raw (gdbarch_register_type (gdbarch,
- reg_nr),
+ sh64_register_convert_to_raw (register_type (gdbarch, reg_nr),
reg_nr,
buffer, temp_buffer);
@@ -2084,10 +2081,10 @@ sh64_do_register (struct gdbarch *gdbarc
if (!frame_register_read (frame, regnum, raw_buffer))
fprintf_filtered (file, "*value not available*\n");
- val_print (gdbarch_register_type (gdbarch, regnum), raw_buffer, 0, 0,
+ val_print (register_type (gdbarch, regnum), raw_buffer, 0, 0,
file, 'x', 1, 0, Val_pretty_default);
fprintf_filtered (file, "\t");
- val_print (gdbarch_register_type (gdbarch, regnum), raw_buffer, 0, 0,
+ val_print (register_type (gdbarch, regnum), raw_buffer, 0, 0,
file, 0, 1, 0, Val_pretty_default);
fprintf_filtered (file, "\n");
}
@@ -2102,7 +2099,7 @@ sh64_print_register (struct gdbarch *gdb
else if (regnum >= 0 && regnum < NUM_REGS)
{
- if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
+ if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
sh64_do_fp_register (gdbarch, file, frame, regnum); /* FP regs */
else
sh64_do_register (gdbarch, file, frame, regnum);
@@ -2139,7 +2136,7 @@ sh64_media_print_registers_info (struct
continue;
}
- if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum))
+ if (TYPE_CODE (register_type (gdbarch, regnum))
== TYPE_CODE_FLT)
{
if (fpregs)
Index: src/gdb/tui/tui-regs.c
===================================================================
--- src.orig/gdb/tui/tui-regs.c 2007-01-09 13:13:46.000000000 -0500
+++ src/gdb/tui/tui-regs.c 2007-01-10 16:22:36.000000000 -0500
@@ -654,7 +654,7 @@ tui_register_format (struct gdbarch *gdb
struct cleanup *cleanups;
char *p, *s;
int pos;
- struct type *type = gdbarch_register_type (gdbarch, regnum);
+ struct type *type = register_type (gdbarch, regnum);
name = gdbarch_register_name (gdbarch, regnum);
if (name == 0)