Re: [PATCH 18/43] Add new register access interface to expr.c

Zoran Zaric via Gdb-patches
2021-04-28T15:42:17Z

On 4/28/21 3:48 PM, Simon Marchi wrote:
> [CAUTION: External Email]
>
>>> Can regsize really be 0?
>>
>> This was part of the previously used API so my guess is that it could :)
>>
>> I didn't want to presume to many things if the previous code handled them.
>
> Ok, it's fine to keep it then, to avoid breaking some potential existing
> use case (we could try to remove it, but as a separate work).
>
> I ask these things because if things are not supposed to happen, it's
> better that we gdb_assert them, rather than handle them like this.
> Otherwise, when somebody comes around to read that code later, they will
> think that regsize == 0 (or frame == NULL in the other case) is a
> possibility, so that makes their mental model unnecessarily more
> complex. It can also cover some bugs which would be exposed by a failed
> assertion.

Agreed. I can go back to this and re-test it as part of a separate patch.

>
>>> I don't understand the code and how it relates to the comment. What
>>> does it mean for a register to be inside an offset? The expression
>>> `offset + length > regsize` checks that the end of the portion we want
>>> to read is beyond the end of the register. But there could be a part of
>>> the portion we want to read that is within the register. The code might
>>> be correct, but the comment needs to express the intention more clearly.
>>
>> This is not allowed in DWARF. The whole length needs to be contained in a register. If only some parts of it are then the location needs to be a composite and that is not covered with this low level interface.
>>
>> I should probably explicitly say that in the comment in the next iteration
>
> Ok, the existing comment makes it sound like "if what we want to read is
> _wholly_ outside of the register, we can return early". So just an
> optimization things. So yeah I think the comments needs to be clearer.

I will change it in the next iteration.

>
>>> Is `numregs < regnum` really useful? When would you encounter that?
>>>
>>> Simon
>>>
>>
>> This check was part of the previous interface as well. Maybe the interface was design to be conservative or maybe there was an use case where compiler generated something that resulted in an invalid regnum?
>>
>> Better safe then sorry I guess but, I can remove it if it doesn't make sense.
>
> If it was already there (I didn't find it though), then it's ok to keep
> it.
>
> Simon
>

Let me reconfirm this to be safe.

Zoran