This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix type casts losing typedefs and reimplement "whatis" typedef stripping
- From: Simon Marchi <simark at simark dot ca>
- To: Yao Qi <qiyaoltc at gmail dot com>, Pedro Alves <palves at redhat dot com>
- Cc: GDB Patches <gdb-patches at sourceware dot org>, Phil Muldoon <pmuldoon at redhat dot com>
- Date: Sat, 18 Nov 2017 17:58:05 -0500
- Subject: Re: [PATCH] Fix type casts losing typedefs and reimplement "whatis" typedef stripping
- Authentication-results: sourceware.org; auth=none
- References: <1498837699-20897-1-git-send-email-palves@redhat.com> <d727c2c0-9e19-9e7e-c1c0-38b3345f0499@redhat.com> <5225ca30-ef69-040d-3f96-be2e5e87b80b@redhat.com> <CAH=s-PMc+bp7rXhwZ0kNdTc5WZ+xL0G1NSE6m3pMM_zFo60b6Q@mail.gmail.com>
On 2017-11-18 03:57 PM, Yao Qi wrote:
> On Mon, Aug 21, 2017 at 11:38 AM, Pedro Alves <palves@redhat.com> wrote:
>
> Hi Pedro,
> The new tests in gdb.base/whatis-ptype-typedefs.exp fail on 32-bit target.
>
> https://gdb-build.sergiodj.net/builders/Ubuntu-AArch32-m32/builds/1175/steps/test%20gdb/logs/stdio
> https://gdb-build.sergiodj.net/builders/Fedora-i686/builds/6867/steps/test%20gdb/logs/stdio
> https://gdb-build.sergiodj.net/builders/Fedora-x86_64-m32/builds/6849/steps/test%20gdb/logs/stdio
>
> Can you take a look?
>
I took a quick look. The issue (at least one of them) boils down to the fact
that on 64 bits, you can't do this:
(gdb) p (float_typedef) v_uchar_array_t_struct_typedef
Invalid cast.
but on 32 bits you can:
(gdb) p (float_typedef) v_uchar_array_t_struct_typedef
$1 = 1.16251721e-41
The expression basically tries to cast an array (which decays to a pointer) to
a float. The cast works on 32 bits (doesn't give Invalid cast) because a float
and a pointer are of the same size, and the execution enters this if branch:
https://github.com/bminor/binutils-gdb/blob/master/gdb/valops.c#L554
On 64 bits, they are not the same size, so it ends up in the invalid cast
branch.
I don't really know what to do from there. Should we leave the behavior as-is
and update the test, or prevent this kind of cast (the compiler doesn't accept
that anyway, and I don't see any real use case to this). This function (value_cast)
is a bit convoluted, I'm always afraid to touch it...
Simon