From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11217 invoked by alias); 15 Dec 2010 10:22:40 -0000 Received: (qmail 11207 invoked by uid 22791); 15 Dec 2010 10:22:39 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,TW_EG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Dec 2010 10:22:33 +0000 Received: (qmail 23219 invoked from network); 15 Dec 2010 10:22:30 -0000 Received: from unknown (HELO ?192.168.0.102?) (yao@127.0.0.2) by mail.codesourcery.com with ESMTPA; 15 Dec 2010 10:22:30 -0000 Message-ID: <4D0896E0.1030707@codesourcery.com> Date: Wed, 15 Dec 2010 10:22:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [patch 1/2] New gdbarch hook user_register_name Content-Type: multipart/mixed; boundary="------------050804020004090803030205" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-12/txt/msg00286.txt.bz2 This is a multi-part message in MIME format. --------------050804020004090803030205 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-length: 1089 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 (齐尧) --------------050804020004090803030205 Content-Type: text/x-patch; name="gdbarch_user_register_name_p1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gdbarch_user_register_name_p1.patch" Content-length: 7756 2010-12-15 Yao Qi * 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 <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 --------------050804020004090803030205--