This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFC: fix cast to void
- From: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 28 Nov 2012 22:57:07 +0000
- Subject: Re: RFC: fix cast to void
- References: <87txs9aden.fsf@fleche.redhat.com>
On 11/28/2012 04:41 PM, Tom Tromey wrote:
> This patch fixes a bug I noticed while debugging another problem.
>
> In some cases a cast to void will fail like so:
>
> (gdb) p (void) v_int_pointer
> Attempt to dereference a generic pointer.
>
> The problem is that the check for cast-to-void comes after the
> lval_memory case.
>
> Fixed as appended. New test included.
> Built & regtested on x86-64 Fedora 16.
>
We should move it even before:
else if (TYPE_LENGTH (type) == TYPE_LENGTH (type2))
{
if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
return value_cast_pointers (type, arg2, 0);
arg2 = value_copy (arg2);
deprecated_set_value_type (arg2, type);
set_value_enclosing_type (arg2, type);
set_value_pointed_to_offset (arg2, 0); /* pai: chk_val */
return arg2;
}
because TYPE_LENGTH of void is 1, so with:
char foobar = 1;
this:
(gdb) p (void) foobar
enters that TYPE_LENGTH==TYPE_LENGTH branch, and returns with an arg2 that
has the wrong VALUE_LVAL. Here's a test for that:
(gdb) p & (void) foobar
$6 = (void *) 0xc215d9 <foobar>
This should be an error.
--
Pedro Alves