From: Yao Qi <yao@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: [patch 1/2] New gdbarch hook user_register_name
Date: Wed, 15 Dec 2010 10:22:00 -0000 [thread overview]
Message-ID: <4D0896E0.1030707@codesourcery.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1095 bytes --]
Current GDB has a flexible mechanism adding standard register aliases by
backends, and register/alias name is used as a key to find the
corresponding register number. However, this mechanism can't handle the
case if different registers have the same alias name. It sounds a
little bit unreasonable, but 'fp' on ARM/Thumb is this case.
alias 'fp' is assumed to be r11, both in ARM mode and Thumb mode in
current GDB. However, the expected (or correct) behavior is that 'fp'
is r11 on ARM mode, and 'fp' is r7 on Thumb mode, when user types 'p/x
$fp' in GDB.
Existing GDB can't meet such needs, so this patch is to refactor GDB a
little bit. In this patch, a new gdbarch hook user_register_name is
added, and its default implementation is to look for register aliases in
user_regs_data, which is same as before in logic. This patch should not
affect any functions of GDB.
Regression tested on x86_64-unknown-linux. Comments?
Once this patch is applied, we leave more flexibility to backend to
determine what is the correct register number given a register alias.
--
Yao (é½å°§)
[-- Attachment #2: gdbarch_user_register_name_p1.patch --]
[-- Type: text/x-patch, Size: 7756 bytes --]
2010-12-15 Yao Qi <yao@codesourcery.com>
* gdbarch.sh: Add new gdbarch hook user_register_name.
* gdbarch.c: Regenerate.
* gdbarch.h: Likewise.
* user-regs.c (user_reg_map_name_to_regnum): Move some code to ...
(default_user_register_name): ... here. New.
* user-regs.h : Declare default_user_register_name.
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 78e5c48..cca0943 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -45,6 +45,7 @@
#include "gdb_assert.h"
#include "gdb_string.h"
#include "reggroups.h"
+#include "user-regs.h"
#include "osabi.h"
#include "gdb_obstack.h"
#include "observer.h"
@@ -180,6 +181,7 @@ struct gdbarch
int call_dummy_location;
gdbarch_push_dummy_code_ftype *push_dummy_code;
gdbarch_print_registers_info_ftype *print_registers_info;
+ gdbarch_user_register_name_ftype *user_register_name;
gdbarch_print_float_info_ftype *print_float_info;
gdbarch_print_vector_info_ftype *print_vector_info;
gdbarch_register_sim_regno_ftype *register_sim_regno;
@@ -330,6 +332,7 @@ struct gdbarch startup_gdbarch =
0, /* call_dummy_location */
0, /* push_dummy_code */
default_print_registers_info, /* print_registers_info */
+ default_user_register_name, /* user_register_name */
0, /* print_float_info */
0, /* print_vector_info */
legacy_register_sim_regno, /* register_sim_regno */
@@ -474,6 +477,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
gdbarch->deprecated_fp_regnum = -1;
gdbarch->call_dummy_location = AT_ENTRY_POINT;
gdbarch->print_registers_info = default_print_registers_info;
+ gdbarch->user_register_name = default_user_register_name;
gdbarch->register_sim_regno = legacy_register_sim_regno;
gdbarch->cannot_fetch_register = cannot_register_not;
gdbarch->cannot_store_register = cannot_register_not;
@@ -611,6 +615,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of call_dummy_location, invalid_p == 0 */
/* Skip verify of push_dummy_code, has predicate */
/* Skip verify of print_registers_info, invalid_p == 0 */
+ /* Skip verify of user_register_name, invalid_p == 0 */
/* Skip verify of print_float_info, has predicate */
/* Skip verify of print_vector_info, has predicate */
/* Skip verify of register_sim_regno, invalid_p == 0 */
@@ -1226,6 +1231,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
"gdbarch_dump: unwind_sp = <%s>\n",
host_address_to_string (gdbarch->unwind_sp));
fprintf_unfiltered (file,
+ "gdbarch_dump: user_register_name = <%s>\n",
+ host_address_to_string (gdbarch->user_register_name));
+ fprintf_unfiltered (file,
"gdbarch_dump: value_from_register = <%s>\n",
host_address_to_string (gdbarch->value_from_register));
fprintf_unfiltered (file,
@@ -2041,6 +2049,23 @@ set_gdbarch_print_registers_info (struct gdbarch *gdbarch,
}
int
+gdbarch_user_register_name (struct gdbarch *gdbarch, const char *regname, int len)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->user_register_name != NULL);
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_user_register_name called\n");
+ return gdbarch->user_register_name (gdbarch, regname, len);
+}
+
+void
+set_gdbarch_user_register_name (struct gdbarch *gdbarch,
+ gdbarch_user_register_name_ftype user_register_name)
+{
+ gdbarch->user_register_name = user_register_name;
+}
+
+int
gdbarch_print_float_info_p (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 443e1d5..deda8fc 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -322,6 +322,10 @@ typedef void (gdbarch_print_registers_info_ftype) (struct gdbarch *gdbarch, stru
extern void gdbarch_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, struct frame_info *frame, int regnum, int all);
extern void set_gdbarch_print_registers_info (struct gdbarch *gdbarch, gdbarch_print_registers_info_ftype *print_registers_info);
+typedef int (gdbarch_user_register_name_ftype) (struct gdbarch *gdbarch, const char *regname, int len);
+extern int gdbarch_user_register_name (struct gdbarch *gdbarch, const char *regname, int len);
+extern void set_gdbarch_user_register_name (struct gdbarch *gdbarch, gdbarch_user_register_name_ftype *user_register_name);
+
extern int gdbarch_print_float_info_p (struct gdbarch *gdbarch);
typedef void (gdbarch_print_float_info_ftype) (struct gdbarch *gdbarch, struct ui_file *file, struct frame_info *frame, const char *args);
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 5b66116..9291da5 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -462,6 +462,10 @@ v:int:call_dummy_location::::AT_ENTRY_POINT::0
M:CORE_ADDR:push_dummy_code:CORE_ADDR sp, CORE_ADDR funaddr, struct value **args, int nargs, struct type *value_type, CORE_ADDR *real_pc, CORE_ADDR *bp_addr, struct regcache *regcache:sp, funaddr, args, nargs, value_type, real_pc, bp_addr, regcache
m:void:print_registers_info:struct ui_file *file, struct frame_info *frame, int regnum, int all:file, frame, regnum, all::default_print_registers_info::0
+
+# Search REGNAME in user name space, and return register number if found. Return -1 otherwise.
+m:int:user_register_name:const char *regname, int len:regname, len::default_user_register_name::0
+
M:void:print_float_info:struct ui_file *file, struct frame_info *frame, const char *args:file, frame, args
M:void:print_vector_info:struct ui_file *file, struct frame_info *frame, const char *args:file, frame, args
# MAP a GDB RAW register number onto a simulator register number. See
@@ -1245,6 +1249,7 @@ cat <<EOF
#include "gdb_assert.h"
#include "gdb_string.h"
#include "reggroups.h"
+#include "user-regs.h"
#include "osabi.h"
#include "gdb_obstack.h"
#include "observer.h"
diff --git a/gdb/user-regs.c b/gdb/user-regs.c
index 0107377..eb1ef10 100644
--- a/gdb/user-regs.c
+++ b/gdb/user-regs.c
@@ -150,21 +150,28 @@ user_reg_map_name_to_regnum (struct gdbarch *gdbarch, const char *name,
}
}
- /* Search the user name space. */
- {
- struct gdb_user_regs *regs = gdbarch_data (gdbarch, user_regs_data);
- struct user_reg *reg;
- int nr;
+ return gdbarch_user_register_name (gdbarch, name, len);
+}
- for (nr = 0, reg = regs->first; reg != NULL; reg = reg->next, nr++)
- {
- if ((len < 0 && strcmp (reg->name, name))
- || (len == strlen (reg->name)
- && strncmp (reg->name, name, len) == 0))
- return gdbarch_num_regs (gdbarch)
- + gdbarch_num_pseudo_regs (gdbarch) + nr;
- }
- }
+/* Search REGNAME in user name space, and return register number if found,
+ otherwise return -1. */
+
+int
+default_user_register_name (struct gdbarch *gdbarch, const char *regname,
+ int len)
+{
+ struct gdb_user_regs *regs = gdbarch_data (gdbarch, user_regs_data);
+ struct user_reg *reg;
+ int nr;
+
+ for (nr = 0, reg = regs->first; reg != NULL; reg = reg->next, nr++)
+ {
+ if ((len < 0 && strcmp (reg->name, regname))
+ || (len == strlen (reg->name)
+ && strncmp (reg->name, regname, len) == 0))
+ return gdbarch_num_regs (gdbarch)
+ + gdbarch_num_pseudo_regs (gdbarch) + nr;
+ }
return -1;
}
diff --git a/gdb/user-regs.h b/gdb/user-regs.h
index f5fa12e..093ac9d 100644
--- a/gdb/user-regs.h
+++ b/gdb/user-regs.h
@@ -69,4 +69,6 @@ extern void user_reg_add_builtin (const char *name,
extern void user_reg_add (struct gdbarch *gdbarch, const char *name,
user_reg_read_ftype *read, const void *baton);
+extern int default_user_register_name (struct gdbarch *gdbarch,
+ const char *regname, int len);
#endif
next reply other threads:[~2010-12-15 10:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-15 10:22 Yao Qi [this message]
2010-12-15 10:48 ` [patch 2/2] Implement gdbarch hook user_register_name on ARM Yao Qi
2010-12-21 19:07 ` Ulrich Weigand
2010-12-22 17:44 ` Yao Qi
2010-12-22 18:12 ` Mark Kettenis
2010-12-23 7:19 ` Yao Qi
2010-12-23 1:54 ` Ulrich Weigand
2010-12-23 4:10 ` Yao Qi
2010-12-23 18:37 ` Ulrich Weigand
2010-12-24 5:16 ` Yao Qi
2010-12-28 14:52 ` Ulrich Weigand
2010-12-22 17:54 ` Richard Earnshaw
2010-12-23 2:05 ` Ulrich Weigand
2010-12-23 3:37 ` Joel Brobecker
2010-12-23 12:08 ` Mark Kettenis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D0896E0.1030707@codesourcery.com \
--to=yao@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox