]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/exp] Fix ptype $_creal/$_cimag
authorTom de Vries <tdevries@suse.de>
Wed, 24 Jul 2024 14:32:35 +0000 (16:32 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 24 Jul 2024 14:32:35 +0000 (16:32 +0200)
commit75ece951b544fa1b530340cfa8a04bfb6f5bbaae
treebdca111e435039b44112c81cc03f5f3aa7c2428d
parentde272a5e905afb20ec0a2c192538acf9c9103974
[gdb/exp] Fix ptype $_creal/$_cimag

Consider test.c, compiled with -g:
...
__complex__ float cf = 1 + 2i;
int main (void) { return 0; }
...

The values of cf and its components are:
...
$ gdb -q a.out
Reading symbols from a.out...
(gdb) p cf
$1 = 1 + 2i
(gdb) p $_creal(cf)
$2 = 1
(gdb) p $_cimag(cf)
$3 = 2
...
and their respective types are:
...
(gdb) ptype $1
type = complex float
(gdb) ptype $2
type = float
(gdb) ptype $3
type = float
...

Now let's try that again, using ptype directly:
...
(gdb) ptype cf
type = complex float
(gdb) ptype $_creal(cf)
type = int
(gdb) ptype $_cimag(cf)
type = int
...

The last two types should have been float, not int.

Fix this by extending the internal function handlers creal_internal_fn and
cimag_internal_fn with the noside parameter, such that we get instead:
...
(gdb) ptype $_creal(cf)
type = float
(gdb) ptype $_cimag(cf)
type = float
...

Tested on x86_64-linux.

Reviewed-By: Keith Seitz <keiths@redhat.com>
PR exp/31816
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31816
gdb/testsuite/gdb.base/complex-parts.exp
gdb/value.c