This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix type casts losing typedefs and reimplement "whatis" typedef stripping


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]