Re: [PATCH v2 3/3] Use partial register read/writes in transfer_regset

Alan Hayward
2018-06-21T19:56:26Z

> On 21 Jun 2018, at 15:14, Simon Marchi <simon.marchi@ericsson.com> wrote:
>
> Hi Alan,
>
> On 2018-06-21 05:38 AM, Alan Hayward wrote:
>> @@ -1013,12 +1077,18 @@ regcache::transfer_regset (const struct regset *regset,
>> if (offs + slot_size > size)
>> break;
>>
>> + /* Use part versions to prevent possible overflow. */
>> if (out_buf)
>
> Can you update the pointer comparisons in the code you touch to use != NULL or != nullptr?
>

Will do.

>> diff --git a/gdb/regcache.h b/gdb/regcache.h
>> index c17ce09dee..a69b67d513 100644
>> --- a/gdb/regcache.h
>> +++ b/gdb/regcache.h
>> @@ -162,6 +162,11 @@ public:
>> void raw_collect_integer (int regnum, gdb_byte *addr, int addr_len,
>> bool is_signed) const;
>>
>> + /* Collect register REGNUM from REGCACHE, starting at offset in REGCACHE,
>> + reading only LEN. If this runs off the end of the register, then fill the
>> + additional space with zeros. */
>
> To have a consistent interface, I would be tempted to use the same behavior as
> read_part and write_part for reads and writes that run off the end of the register
> (not allow it). It would be the responsibility of the caller to ensure that they
> don't overflow. I think it would just be a matter of
>
> std::min (reg_size, slot_size)
>
> ?

I went back and too between doing it this way and the way I posted.
I settled on this way because it made transfer_regset neater. I agree it makes
sense to keep the interface the same. In addition I’d then have to pull the
memset of 0s into transfer_regset. I think it’ll look better if I pull the two
almost identical blobs of code into a helper function.

I’ll switch it around and repost as single V3 tomorrow, with all the unsigned stuff
dropped.

Alan.