Re: [PATCH] Fix agent code generate bug of ref

Hui Zhu
2013-03-12T14:48:35Z

On 03/12/13 22:16, Tom Tromey wrote:
>>>>>> "Hui" == Hui Zhu <teawater@gmail.com> writes:
>
> Hui> Sorry for my misunderstand in your mail. Accord to discussion with
> Hui> Yao in IRC. I merge 2 patches together.
> Hui> And I found that gdb_assert of access_memory. It should use nbytes.
>
> Thanks for doing this.
>
> Hui> 2013-03-12 Yao Qi <yao@codesourcery.com>
> Hui> Hui Zhu <hui_zhu@mentor.com>
> Hui> * dwarf2loc.c (access_memory): Change nbits to nbytes in gdb_assert.
> Hui> (dwarf2_compile_expr_to_ax): Call access_memory in DW_OP_deref and
> Hui> DW_OP_deref_size.
>
> Hui> + gdb_assert (nbytes > 0 && nbytes <= sizeof (LONGEST));
>
> Hui> - default:
> Hui> - /* Note that get_DW_OP_name will never return
> Hui> - NULL here. */
> Hui> - error (_("Unsupported size %d in %s"),
> Hui> - size, get_DW_OP_name (op));
> Hui> - }
>
> I think we need a sanity check before calling access_memory.
> Otherwise, bad DWARF will be able to crash gdb.
> The patch is ok with that change.
>
> Tom
>

According to the discussion with Tom in IRC.
I add a check before call access_memory.
+ if (size != 1 && size != 2 && size != 4 && size != 8)
+ error (_("Refn doesn't support size %d"),
+ size * TARGET_CHAR_BIT);

Checked in http://sourceware.org/ml/gdb-cvs/2013-03/msg00102.html

Thanks,
Hui