aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-07-24 16:32:35 +0200
committerTom de Vries <tdevries@suse.de>2024-07-24 16:32:35 +0200
commit75ece951b544fa1b530340cfa8a04bfb6f5bbaae (patch)
treebdca111e435039b44112c81cc03f5f3aa7c2428d /gdb
parentde272a5e905afb20ec0a2c192538acf9c9103974 (diff)
downloadbinutils-75ece951b544fa1b530340cfa8a04bfb6f5bbaae.zip
binutils-75ece951b544fa1b530340cfa8a04bfb6f5bbaae.tar.gz
binutils-75ece951b544fa1b530340cfa8a04bfb6f5bbaae.tar.bz2
[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
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.base/complex-parts.exp24
-rw-r--r--gdb/value.c9
2 files changed, 25 insertions, 8 deletions
diff --git a/gdb/testsuite/gdb.base/complex-parts.exp b/gdb/testsuite/gdb.base/complex-parts.exp
index a0ead3e..40f14f4 100644
--- a/gdb/testsuite/gdb.base/complex-parts.exp
+++ b/gdb/testsuite/gdb.base/complex-parts.exp
@@ -41,33 +41,45 @@ if {[test_compiler_info clang-*-*]} { setup_xfail *-*-* }
gdb_test "ptype z3" " = complex long double"
with_test_prefix "double imaginary" {
- gdb_test {p $_cimag (z1)} " = 4.5"
+ set expr {$_cimag (z1)}
+ gdb_test "p $expr" " = 4.5"
gdb_test {ptype $} " = double"
+ gdb_test "ptype $expr" " = double"
}
with_test_prefix "float imaginary" {
- gdb_test {p $_cimag (z2)} " = -5.5"
+ set expr {$_cimag (z2)}
+ gdb_test "p $expr" " = -5.5"
gdb_test {ptype $} " = float"
+ gdb_test "ptype $expr" " = float"
}
with_test_prefix "long double imaginary" {
- gdb_test {p $_cimag (z3)} " = 6.5"
+ set expr {$_cimag (z3)}
+ gdb_test "p $expr" " = 6.5"
gdb_test {ptype $} " = long double"
+ gdb_test "ptype $expr" " = long double"
}
with_test_prefix "double real" {
- gdb_test {p $_creal (z1)} " = 1.5"
+ set expr {$_creal (z1)}
+ gdb_test "p $expr" " = 1.5"
gdb_test {ptype $} " = double"
+ gdb_test "ptype $expr" " = double"
}
with_test_prefix "float real" {
- gdb_test {p $_creal (z2)} " = 2.5"
+ set expr {$_creal (z2)}
+ gdb_test "p $expr" " = 2.5"
gdb_test {ptype $} " = float"
+ gdb_test "ptype $expr" " = float"
}
with_test_prefix "long double real" {
- gdb_test {p $_creal (z3)} " = 3.5"
+ set expr {$_creal (z3)}
+ gdb_test "p $expr" " = 3.5"
gdb_test {ptype $} " = long double"
+ gdb_test "ptype $expr" " = long double"
}
gdb_test {p $_cimag (d1)} "expected a complex number"
diff --git a/gdb/value.c b/gdb/value.c
index 9435900..09fb19b 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -4295,7 +4295,8 @@ isvoid_internal_fn (struct gdbarch *gdbarch,
static struct value *
creal_internal_fn (struct gdbarch *gdbarch,
const struct language_defn *language,
- void *cookie, int argc, struct value **argv)
+ void *cookie, int argc, struct value **argv,
+ enum noside noside)
{
if (argc != 1)
error (_("You must provide one argument for $_creal."));
@@ -4304,6 +4305,8 @@ creal_internal_fn (struct gdbarch *gdbarch,
type *ctype = check_typedef (cval->type ());
if (ctype->code () != TYPE_CODE_COMPLEX)
error (_("expected a complex number"));
+ if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ return value::zero (ctype->target_type (), not_lval);
return value_real_part (cval);
}
@@ -4314,7 +4317,7 @@ static struct value *
cimag_internal_fn (struct gdbarch *gdbarch,
const struct language_defn *language,
void *cookie, int argc,
- struct value **argv)
+ struct value **argv, enum noside noside)
{
if (argc != 1)
error (_("You must provide one argument for $_cimag."));
@@ -4323,6 +4326,8 @@ cimag_internal_fn (struct gdbarch *gdbarch,
type *ctype = check_typedef (cval->type ());
if (ctype->code () != TYPE_CODE_COMPLEX)
error (_("expected a complex number"));
+ if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ return value::zero (ctype->target_type (), not_lval);
return value_imaginary_part (cval);
}