This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH, AArch64] Fix bug in hardware watchpoint/breakpoint handling
- From: pinskia at gmail dot com
- To: Marcus Shawcroft <marcus dot shawcroft at gmail dot com>
- Cc: Yufeng Zhang <Yufeng dot Zhang at arm dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>, Marcus Shawcroft <Marcus dot Shawcroft at arm dot com>
- Date: Thu, 19 Dec 2013 02:23:09 -0800
- Subject: Re: [PATCH, AArch64] Fix bug in hardware watchpoint/breakpoint handling
- Authentication-results: sourceware.org; auth=none
- References: <52B1C84F dot 4000102 at arm dot com> <430CEAB7-7F7B-430D-9C37-75F87D1F65AC at gmail dot com> <CAFqB+PyUfWodaTX=jam=dE6ZzE4goj8n4xfc52AsvvMNaj4y+w at mail dot gmail dot com>
> On Dec 19, 2013, at 2:16 AM, Marcus Shawcroft <marcus.shawcroft@gmail.com> wrote:
>
>> On 19 December 2013 07:00, <pinskia@gmail.com> wrote:
>> I think this patch is wrong as the size that is passed is always just one element as sizeof (regs.dbg_regs [count - 1]) is the same as sizeof (regs.dbg_regs [0]). This should have been sizeof (regs.dbg_regs [0])*count instead.
>
>
> + iov.iov_len = (offsetof (struct user_hwdebug_state, dbg_regs[count - 1])
> + + sizeof (regs.dbg_regs [count - 1]));
>
> The offsetof() gives the number of bytes from the start of
> user_hwdebug_state upto and including all of the reg array bar the
> last in use entry. Adding on the sizeof() therefore gives the number
> of bytes from the start of the structure upto and including the last
> in use reg entry.
>
> I agree that the sizeof() could be written either with dbg_regs[0] or
> dbg_regs[count-1] with no change in behavior. But I think Yufengs
> code is functionally correct.
>
> It would have been simpler to write:
> iov.iov_len = (offsetof (struct user_hwdebug_state, dbg_regs[count])
>
> .. but I think that is illegal when count equals the number of
> elements defined in the array.
Oh, I see I think this should have been written using offsetof [0] and then count*sizeof to make easier to understand and fits in with most other code which uses a variable size last element.
Thanks,
Andrew
>
> Cheers
> /Marcus