* [PATCH] Remove MAX_REGISTER_SIZE from target.c @ 2017-02-24 10:09 Alan Hayward 2017-03-01 17:23 ` Yao Qi 0 siblings, 1 reply; 4+ messages in thread From: Alan Hayward @ 2017-02-24 10:09 UTC (permalink / raw) To: gdb-patches; +Cc: nd Avoid copying the register in debug_print_register by moving the func into regcache. Tested using make check with board files unix and native-gdbserver. Ok to commit? Alan. 2017-02-24 Alan Hayward <alan.hayward@arm.com> * regcache.c (regcache_debug_print_register): New function. * regcache.h (regcache_debug_print_register): New declaration. * target.c (debug_print_register): Remove. (target_fetch_registers): Call regcache_debug_print_register. (target_store_registers): Likewise. diff --git a/gdb/regcache.h b/gdb/regcache.h index e1495f61426f879386b905ab1e97421bdd061bf5..59233308f926ebd52db9958cba168daacc77c1ee 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -232,4 +232,8 @@ extern void regcache_cpy (struct regcache *dest, struct regcache *src); extern void registers_changed (void); extern void registers_changed_ptid (ptid_t); +extern void regcache_debug_print_register (const char *func, + struct regcache *regcache, + int regno); + #endif /* REGCACHE_H */ diff --git a/gdb/regcache.c b/gdb/regcache.c index f190eda0e47c5c03744fc26263505d1c30ea1ee8..31aa1baf7ef69c27c00e45e3c8d4eb3c41dc4203 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1259,6 +1259,42 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc) reinit_frame_cache (); } +void +regcache_debug_print_register (const char *func, struct regcache *regcache, + int regno) +{ + struct gdbarch *gdbarch = get_regcache_arch (regcache); + + fprintf_unfiltered (gdb_stdlog, "%s ", func); + if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) + && gdbarch_register_name (gdbarch, regno) != NULL + && gdbarch_register_name (gdbarch, regno)[0] != '\0') + fprintf_unfiltered (gdb_stdlog, "(%s)", + gdbarch_register_name (gdbarch, regno)); + else + fprintf_unfiltered (gdb_stdlog, "(%d)", regno); + if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)) + { + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + int i, size = register_size (gdbarch, regno); + gdb_byte *buf = register_buffer (regcache, regno); + + regcache_raw_collect (regcache, regno, buf); + fprintf_unfiltered (gdb_stdlog, " = "); + for (i = 0; i < size; i++) + { + fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); + } + if (size <= sizeof (LONGEST)) + { + ULONGEST val = extract_unsigned_integer (buf, size, byte_order); + + fprintf_unfiltered (gdb_stdlog, " %s %s", + core_addr_to_string_nz (val), plongest (val)); + } + } + fprintf_unfiltered (gdb_stdlog, "\n"); +} static void reg_flush_command (char *command, int from_tty) diff --git a/gdb/target.c b/gdb/target.c index 0ff8515d3b731ff5929e5c9c68a20d124c1ecd67..7c286ab6bf821ced42a0c1ac945343b761a37157 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3547,49 +3547,12 @@ target_options_to_string (int target_options) return ret; } -static void -debug_print_register (const char * func, - struct regcache *regcache, int regno) -{ - struct gdbarch *gdbarch = get_regcache_arch (regcache); - - fprintf_unfiltered (gdb_stdlog, "%s ", func); - if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) - && gdbarch_register_name (gdbarch, regno) != NULL - && gdbarch_register_name (gdbarch, regno)[0] != '\0') - fprintf_unfiltered (gdb_stdlog, "(%s)", - gdbarch_register_name (gdbarch, regno)); - else - fprintf_unfiltered (gdb_stdlog, "(%d)", regno); - if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)) - { - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - int i, size = register_size (gdbarch, regno); - gdb_byte buf[MAX_REGISTER_SIZE]; - - regcache_raw_collect (regcache, regno, buf); - fprintf_unfiltered (gdb_stdlog, " = "); - for (i = 0; i < size; i++) - { - fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); - } - if (size <= sizeof (LONGEST)) - { - ULONGEST val = extract_unsigned_integer (buf, size, byte_order); - - fprintf_unfiltered (gdb_stdlog, " %s %s", - core_addr_to_string_nz (val), plongest (val)); - } - } - fprintf_unfiltered (gdb_stdlog, "\n"); -} - void target_fetch_registers (struct regcache *regcache, int regno) { current_target.to_fetch_registers (¤t_target, regcache, regno); if (targetdebug) - debug_print_register ("target_fetch_registers", regcache, regno); + regcache_debug_print_register ("target_fetch_registers", regcache, regno); } void @@ -3601,7 +3564,8 @@ target_store_registers (struct regcache *regcache, int regno) current_target.to_store_registers (¤t_target, regcache, regno); if (targetdebug) { - debug_print_register ("target_store_registers", regcache, regno); + regcache_debug_print_register ("target_store_registers", regcache, + regno); } } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Remove MAX_REGISTER_SIZE from target.c 2017-02-24 10:09 [PATCH] Remove MAX_REGISTER_SIZE from target.c Alan Hayward @ 2017-03-01 17:23 ` Yao Qi 2017-03-24 15:23 ` Alan Hayward 0 siblings, 1 reply; 4+ messages in thread From: Yao Qi @ 2017-03-01 17:23 UTC (permalink / raw) To: Alan Hayward; +Cc: gdb-patches Alan Hayward <Alan.Hayward@arm.com> writes: > +extern void regcache_debug_print_register (const char *func, > + struct regcache *regcache, > + int regno); Comments are needed. > + > #endif /* REGCACHE_H */ > diff --git a/gdb/regcache.c b/gdb/regcache.c > index f190eda0e47c5c03744fc26263505d1c30ea1ee8..31aa1baf7ef69c27c00e45e3c8d4eb3c41dc4203 100644 > --- a/gdb/regcache.c > +++ b/gdb/regcache.c > @@ -1259,6 +1259,42 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc) > reinit_frame_cache (); > } > > +void > +regcache_debug_print_register (const char *func, struct regcache *regcache, > + int regno) > +{ > + struct gdbarch *gdbarch = get_regcache_arch (regcache); > + > + fprintf_unfiltered (gdb_stdlog, "%s ", func); > + if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) > + && gdbarch_register_name (gdbarch, regno) != NULL > + && gdbarch_register_name (gdbarch, regno)[0] != '\0') > + fprintf_unfiltered (gdb_stdlog, "(%s)", > + gdbarch_register_name (gdbarch, regno)); > + else > + fprintf_unfiltered (gdb_stdlog, "(%d)", regno); > + if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)) > + { > + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); > + int i, size = register_size (gdbarch, regno); > + gdb_byte *buf = register_buffer (regcache, regno); > + > + regcache_raw_collect (regcache, regno, buf); Don't need to call regcache_raw_collect, otherwise, the src and dst of copy is at the same address (register_buffer (regcache, regno)). -- Yao (齐尧) ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Remove MAX_REGISTER_SIZE from target.c 2017-03-01 17:23 ` Yao Qi @ 2017-03-24 15:23 ` Alan Hayward 2017-03-24 15:59 ` Yao Qi 0 siblings, 1 reply; 4+ messages in thread From: Alan Hayward @ 2017-03-24 15:23 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches, nd > On 1 Mar 2017, at 17:22, Yao Qi <qiyaoltc@gmail.com> wrote: > > Alan Hayward <Alan.Hayward@arm.com> writes: > >> +extern void regcache_debug_print_register (const char *func, >> + struct regcache *regcache, >> + int regno); > > Comments are needed. > >> + >> #endif /* REGCACHE_H */ >> diff --git a/gdb/regcache.c b/gdb/regcache.c >> index f190eda0e47c5c03744fc26263505d1c30ea1ee8..31aa1baf7ef69c27c00e45e3c8d4eb3c41dc4203 100644 >> --- a/gdb/regcache.c >> +++ b/gdb/regcache.c >> @@ -1259,6 +1259,42 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc) >> reinit_frame_cache (); >> } >> >> +void >> +regcache_debug_print_register (const char *func, struct regcache *regcache, >> + int regno) >> +{ >> + struct gdbarch *gdbarch = get_regcache_arch (regcache); >> + >> + fprintf_unfiltered (gdb_stdlog, "%s ", func); >> + if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) >> + && gdbarch_register_name (gdbarch, regno) != NULL >> + && gdbarch_register_name (gdbarch, regno)[0] != '\0') >> + fprintf_unfiltered (gdb_stdlog, "(%s)", >> + gdbarch_register_name (gdbarch, regno)); >> + else >> + fprintf_unfiltered (gdb_stdlog, "(%d)", regno); >> + if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)) >> + { >> + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); >> + int i, size = register_size (gdbarch, regno); >> + gdb_byte *buf = register_buffer (regcache, regno); >> + >> + regcache_raw_collect (regcache, regno, buf); > > Don't need to call regcache_raw_collect, otherwise, the src and dst of > copy is at the same address (register_buffer (regcache, regno)). > > -- > Yao (齐尧) Patch updated from review comments. Tested using make check with board files unix and native-gdbserver. Ok to commit? Alan. 2017-03-24 Alan Hayward <alan.hayward@arm.com> * regcache.c (regcache_debug_print_register): New function. * regcache.h (regcache_debug_print_register): New declaration. * target.c (debug_print_register): Remove. (target_fetch_registers): Call regcache_debug_print_register. (target_store_registers): Likewise. diff --git a/gdb/regcache.h b/gdb/regcache.h index 63a1a980eb757167fe253164730a534344543948..8b7a0a2afb416df9c03216a203f05d1a2ca0ac8d 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -234,4 +234,10 @@ extern void regcache_cpy (struct regcache *dest, struct regcache *src); extern void registers_changed (void); extern void registers_changed_ptid (ptid_t); +/* Dump the contents of a register from the register cache to the target + debug. */ +extern void regcache_debug_print_register (const char *func, + struct regcache *regcache, + int regno); + #endif /* REGCACHE_H */ diff --git a/gdb/regcache.c b/gdb/regcache.c index 59ee5be14817d61ec1180cae2c19719949af0a03..eb6d09f6cb50ff9347991b7b061f4314c497e018 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1268,6 +1268,41 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc) reinit_frame_cache (); } +void +regcache_debug_print_register (const char *func, struct regcache *regcache, + int regno) +{ + struct gdbarch *gdbarch = get_regcache_arch (regcache); + + fprintf_unfiltered (gdb_stdlog, "%s ", func); + if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) + && gdbarch_register_name (gdbarch, regno) != NULL + && gdbarch_register_name (gdbarch, regno)[0] != '\0') + fprintf_unfiltered (gdb_stdlog, "(%s)", + gdbarch_register_name (gdbarch, regno)); + else + fprintf_unfiltered (gdb_stdlog, "(%d)", regno); + if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)) + { + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + int i, size = register_size (gdbarch, regno); + gdb_byte *buf = register_buffer (regcache, regno); + + fprintf_unfiltered (gdb_stdlog, " = "); + for (i = 0; i < size; i++) + { + fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); + } + if (size <= sizeof (LONGEST)) + { + ULONGEST val = extract_unsigned_integer (buf, size, byte_order); + + fprintf_unfiltered (gdb_stdlog, " %s %s", + core_addr_to_string_nz (val), plongest (val)); + } + } + fprintf_unfiltered (gdb_stdlog, "\n"); +} static void reg_flush_command (char *command, int from_tty) diff --git a/gdb/target.c b/gdb/target.c index 0ff8515d3b731ff5929e5c9c68a20d124c1ecd67..7c286ab6bf821ced42a0c1ac945343b761a37157 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3547,49 +3547,12 @@ target_options_to_string (int target_options) return ret; } -static void -debug_print_register (const char * func, - struct regcache *regcache, int regno) -{ - struct gdbarch *gdbarch = get_regcache_arch (regcache); - - fprintf_unfiltered (gdb_stdlog, "%s ", func); - if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) - && gdbarch_register_name (gdbarch, regno) != NULL - && gdbarch_register_name (gdbarch, regno)[0] != '\0') - fprintf_unfiltered (gdb_stdlog, "(%s)", - gdbarch_register_name (gdbarch, regno)); - else - fprintf_unfiltered (gdb_stdlog, "(%d)", regno); - if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)) - { - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - int i, size = register_size (gdbarch, regno); - gdb_byte buf[MAX_REGISTER_SIZE]; - - regcache_raw_collect (regcache, regno, buf); - fprintf_unfiltered (gdb_stdlog, " = "); - for (i = 0; i < size; i++) - { - fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); - } - if (size <= sizeof (LONGEST)) - { - ULONGEST val = extract_unsigned_integer (buf, size, byte_order); - - fprintf_unfiltered (gdb_stdlog, " %s %s", - core_addr_to_string_nz (val), plongest (val)); - } - } - fprintf_unfiltered (gdb_stdlog, "\n"); -} - void target_fetch_registers (struct regcache *regcache, int regno) { current_target.to_fetch_registers (¤t_target, regcache, regno); if (targetdebug) - debug_print_register ("target_fetch_registers", regcache, regno); + regcache_debug_print_register ("target_fetch_registers", regcache, regno); } void @@ -3601,7 +3564,8 @@ target_store_registers (struct regcache *regcache, int regno) current_target.to_store_registers (¤t_target, regcache, regno); if (targetdebug) { - debug_print_register ("target_store_registers", regcache, regno); + regcache_debug_print_register ("target_store_registers", regcache, + regno); } } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Remove MAX_REGISTER_SIZE from target.c 2017-03-24 15:23 ` Alan Hayward @ 2017-03-24 15:59 ` Yao Qi 0 siblings, 0 replies; 4+ messages in thread From: Yao Qi @ 2017-03-24 15:59 UTC (permalink / raw) To: Alan Hayward; +Cc: gdb-patches Alan Hayward <Alan.Hayward@arm.com> writes: Hi Alan, Patch is good to me, a nit below, > + int i, size = register_size (gdbarch, regno); move "int i" ... > + gdb_byte *buf = register_buffer (regcache, regno); > + > + fprintf_unfiltered (gdb_stdlog, " = "); > + for (i = 0; i < size; i++) ... here, for (int i = 0; .... -- Yao (齐尧) ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-24 15:59 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-02-24 10:09 [PATCH] Remove MAX_REGISTER_SIZE from target.c Alan Hayward 2017-03-01 17:23 ` Yao Qi 2017-03-24 15:23 ` Alan Hayward 2017-03-24 15:59 ` Yao Qi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox