aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/complex-parts.c50
-rw-r--r--gdb/testsuite/gdb.base/complex-parts.exp62
-rw-r--r--gdb/testsuite/gdb.base/default.exp2
4 files changed, 119 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index b429149..7d603ad 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-01 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.base/complex-parts.c: New file.
+ * gdb.base/complex-parts.exp: New file.
+
2019-04-01 Tom Tromey <tromey@adacore.com>
PR symtab/23331:
diff --git a/gdb/testsuite/gdb.base/complex-parts.c b/gdb/testsuite/gdb.base/complex-parts.c
new file mode 100644
index 0000000..243caee
--- /dev/null
+++ b/gdb/testsuite/gdb.base/complex-parts.c
@@ -0,0 +1,50 @@
+/* Copyright 2019 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Unlike the other 'complex.c' test, this one uses the "standard" header
+ file to pull in the complex types. The testing is around printing the
+ complex numbers, and using the convenience function $_cimag and $_creal
+ to extract the parts of the complex numbers. */
+
+#include <complex.h>
+
+void
+keep_around (volatile void *ptr)
+{
+ asm ("" ::: "memory");
+}
+
+int
+main (void)
+{
+ double complex z1 = 1.5 + 4.5 * I;
+ float complex z2 = 2.5 - 5.5 * I;
+ long double complex z3 = 3.5 + 6.5 * I;
+
+ double d1 = 1.5;
+ float f1 = 2.5;
+ int i1 = 3;
+
+ keep_around (&z1);
+ keep_around (&z2);
+ keep_around (&z3);
+ keep_around (&d1);
+ keep_around (&f1);
+ keep_around (&i1);
+
+ return 0; /* Break Here. */
+}
diff --git a/gdb/testsuite/gdb.base/complex-parts.exp b/gdb/testsuite/gdb.base/complex-parts.exp
new file mode 100644
index 0000000..ce8f427
--- /dev/null
+++ b/gdb/testsuite/gdb.base/complex-parts.exp
@@ -0,0 +1,62 @@
+# Copyright 2019 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+}
+
+if { ![runto_main] } then {
+ fail "can't run to main"
+ return 0
+}
+
+gdb_breakpoint [gdb_get_line_number "Break Here"]
+gdb_continue_to_breakpoint "breakpt" ".* Break Here\\. .*"
+
+gdb_test "p z1" " = 1.5 \\+ 4.5 \\* I"
+gdb_test "p z2" " = 2.5 \\+ -5.5 \\* I"
+gdb_test "p z3" " = 3.5 \\+ 6.5 \\* I"
+
+gdb_test "ptype z1" " = complex double"
+gdb_test "ptype z2" " = complex float"
+gdb_test "ptype z3" " = complex long double"
+
+gdb_test "p \$_cimag (z1)" " = 4.5"
+gdb_test "ptype \$" " = double"
+
+gdb_test "p \$_cimag (z2)" " = -5.5"
+gdb_test "ptype \$" " = float"
+
+gdb_test "p \$_cimag (z3)" " = 6.5"
+gdb_test "ptype \$" " = long double"
+
+gdb_test "p \$_creal (z1)" " = 1.5"
+gdb_test "ptype \$" " = double"
+
+gdb_test "p \$_creal (z2)" " = 2.5"
+gdb_test "ptype \$" " = float"
+
+gdb_test "p \$_creal (z3)" " = 3.5"
+gdb_test "ptype \$" " = long double"
+
+gdb_test "p \$_cimag (d1)" "expected a complex number"
+gdb_test "p \$_cimag (f1)" "expected a complex number"
+gdb_test "p \$_cimag (i1)" "expected a complex number"
+
+gdb_test "p \$_creal (d1)" "expected a complex number"
+gdb_test "p \$_creal (f1)" "expected a complex number"
+gdb_test "p \$_creal (i1)" "expected a complex number"
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index 9ff5144..56ec917 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -601,6 +601,8 @@ set show_conv_list \
{$_probe_arg9 = <error: No frame selected>} \
{$_probe_arg10 = <error: No frame selected>} \
{$_probe_arg11 = <error: No frame selected>} \
+ {$_cimag = <internal function _cimag>} \
+ {$_creal = <internal function _creal>} \
{$_isvoid = <internal function _isvoid>} \
{$_gdb_major = 8} \
{$_gdb_minor = 4} \