]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/symtab] Fix target type of complex long double on arm
authorTom de Vries <tdevries@suse.de>
Wed, 19 Jun 2024 15:32:55 +0000 (17:32 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 19 Jun 2024 15:32:55 +0000 (17:32 +0200)
commitb49c3a37b197f3cc38e8d70db74f9dd58c31cc32
treefe16e64bfab25feaf9402b487730c8e6a7f046d4
parentb84ffc176d3ab90a5dd42e406f84b2207f2782ca
[gdb/symtab] Fix target type of complex long double on arm

When running test-case gdb.base/complex-parts.exp on arm-linux, I get:
...
(gdb) p $_cimag (z3)^M
$6 = 6.5^M
(gdb) PASS: gdb.base/complex-parts.exp: long double imaginary: p $_cimag (z3)
ptype $^M
type = double^M
(gdb) FAIL: gdb.base/complex-parts.exp: long double imaginary: ptype $
...

Given that z3 is a complex long double, the test-case expects the type of the
imaginary part of z3 to be long double, but it's double instead.

This is due to the fact that the dwarf info doesn't specify an explicit target
type:
...
    <5b>   DW_AT_name        : z3
    <60>   DW_AT_type        : <0xa4>
  ...
 <1><a4>: Abbrev Number: 2 (DW_TAG_base_type)
    <a5>   DW_AT_byte_size   : 16
    <a6>   DW_AT_encoding    : 3        (complex float)
    <a7>   DW_AT_name        : complex long double
...
and consequently we're guessing in dwarf2_init_complex_target_type based on
the size:
...
case 64:
  tt = builtin_type (gdbarch)->builtin_double;
  break;
case 96: /* The x86-32 ABI specifies 96-bit long double.  */
case 128:
  tt = builtin_type (gdbarch)->builtin_long_double;
  break;
...

For arm-linux, complex long double is 16 bytes, so the target type is assumed
to be 8 bytes, which is handled by the "case 64", which gets us double
instead of long double.

Fix this by searching for "long" in the name_hint parameter, and using long
double instead.

Note that base types in dwarf are not allowed to contain references to other
types, and the complex types are base types, so the missing explicit target
type is standard-conformant.

A gcc PR was filed to add this as a dwarf extension (
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115272 ).

Tested on arm-linux.
gdb/dwarf2/read.c
gdb/testsuite/gdb.dwarf2/dw2-complex-parts.exp [new file with mode: 0644]