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

Alan Hayward
2017-05-24T10:20:30Z

> On 24 May 2017, at 10:20, Pedro Alves <palves@redhat.com> wrote:
>
> On 05/24/2017 10:07 AM, Alan Hayward wrote:
>
>>> Hmm, I think you may have misunderstood. The main point was to
>>> avoid having to have T/LONGEST temporary at all here:
>
> ...
>
>>>
>>> and maybe the need for all the templating.
>>>
>>
>> Would still need to have eater signed/unsigned versions of the functions,
>> or maybe have “bool signed” parameter.
>
> Parameter sounds fine to me.
>
>> Are you suggesting something like this:
>> (Warning - this snippet may not even compile, and I’m not sure on the endian
>> logic)
>
> Yes, exactly. WDYT?

I’m happy in principle with it (after fix ups)

>
>> Meanwhile raw_collect_integer doesn’t need a signed parameter:
>
> Wouldn't we need to support ADDR_LEN larger than the register size?

This might be me misunderstanding gdb,
But I assumed that addr would always be shorter than the register size.
If addr is bigger than the register size then the most significant bits will
be chopped off (including the sign), which I think would be a bad idea?

>
> On 24 May 2017, at 10:29, Pedro Alves <palves@redhat.com> wrote:
>
> On 05/24/2017 10:07 AM, Alan Hayward wrote:
>> /* Copy COPY_LEN bytes from SOURCE to DEST, then sign extend or zero extend
>> to FILL_LEN bytes. */
>> void copy_and_fill_to_size (const gdb_byte *dest, const gdb_byte *source,
>> int copy_len, int fill_len, bool is_signed,
>> enum bfd_endian byte_order)
>> {
>> signed int len_diff = fill_len - copy_len;
>> gdb_assert (len_diff >= 0);
>>
>> if (byte_order == BFD_ENDIAN_BIG)
>> memcpy (dest+len_diff, source, copy_len);
>> else
>> memcpy (dest, source, copy_len);
>
> Note here I was thinking you'd need to handle truncation as well.
> I.e., only copy fill_len bytes when fill_len is narrower than
> copy_len. So I'd probably rename copy_len/fill_len to dest_len/source_len
> to match 'dest' and 'source', and name the function something
> else that doesn't have "fill" in it.

Agreed (regardless of the outcome for the previous question).

Alan.