[PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (2/4)

Yao Qi qiyaoltc@gmail.com
Thu May 25 11:43:00 GMT 2017


Pedro Alves <palves@redhat.com> writes:

> Those manual tests would have been perfect candidates for some
> unit tests.  All you'd need to do is add this at the bottom
> of gdb/findvar.c:
>
> #if GDB_SELF_TEST
> namespace selftests {
> namespace findvar_tests {
>
> static void
> run_test ()
> {
>   // Here, exercise the various code paths of copy_integer_to_size,
>   // calling SELF_CHECK.
> }
>
> } // namespace findvar_test
> } // namespace selftests
>
> #endif
>
> void
> _initialize_findvar (void)
> {
> #if GDB_SELF_TEST
>   register_self_test (selftests::findvar_tests::run_test);
> #endif
> }
>
>

It is great to have a unit test, and that is what I want to suggest.

>> +/* Supply a single register.  The register size might not match, so use
>> +   regcache->raw_supply_integer ().  */
>> 
>>  static void
>>  mips_fbsd_supply_reg (struct regcache *regcache, int regnum, const void *addr,
>>  		      size_t len)
>>  {
>> -  struct gdbarch *gdbarch = get_regcache_arch (regcache);
>> -
>> -  if (register_size (gdbarch, regnum) == len)
>> -    regcache_raw_supply (regcache, regnum, addr);
>> -  else
>> -    {
>> -      enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>> -      gdb_byte buf[MAX_REGISTER_SIZE];
>> -      LONGEST val;
>> -
>> -      val = extract_signed_integer ((const gdb_byte *) addr, len, byte_order);
>> -      store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
>> -			    val);
>> -      regcache_raw_supply (regcache, regnum, buf);
>> -    }
>> +  regcache->raw_supply_integer (regnum, (const gdb_byte *) addr, len, true);
>>  }
>
> Nice!
>

Can we completely remove mips_fbsd_supply_reg? and use
regcache->raw_supply_integer instead?

>> --- a/gdb/mips-linux-tdep.c
>> +++ b/gdb/mips-linux-tdep.c
>> @@ -116,13 +116,7 @@ mips_linux_get_longjmp_target (struct
>> frame_info *frame, CORE_ADDR *pc)
>>  static void
>>  supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
>>  {
>> -  struct gdbarch *gdbarch = get_regcache_arch (regcache);
>> -  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>> -  gdb_byte buf[MAX_REGISTER_SIZE];
>> -  store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
>> -			extract_signed_integer ((const gdb_byte *) addr, 4,
>> -						byte_order));
>> -  regcache_raw_supply (regcache, regnum, buf);
>> +  regcache->raw_supply_integer (regnum, (const gdb_byte *) addr, 4, true);
>>  }
>
> Nice.  :-)
> [snip several "nice"s]
>

Likewise, remove supply_32bit_reg and use regcache->raw_supply_integer.

-- 
Yao (齐尧)



More information about the Gdb-patches mailing list