]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/fortran: better types for components of complex numbers
authorAndrew Burgess <andrew.burgess@embecosm.com>
Sat, 16 Feb 2019 22:45:41 +0000 (22:45 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 30 Apr 2019 09:10:31 +0000 (10:10 +0100)
Currently when using $_creal and $_cimag to access the components of a
complex number the types of these components will have C type names
'float', 'double', etc.  This is because the components of a complex
number are not given type names in DWARF, so GDB has to pick some
suitable names, and currently we always use the C names.

This commit changes the type names used based on the language, so for
Fortran we will now use the Fortran float types, and so will get the
Fortran float type names 'real', 'real*8', etc.

gdb/ChangeLog:

* dwarf2read.c (dwarf2_init_complex_target_type): Use different
types for Fortran.

gdb/testsuite/ChangeLog:

* gdb.fortran/complex.exp: Expand.
* gdb.fortran/complex.f: Renamed to...
* gdb.fortran/complex.f90: ...this, and extended to add more
complex values.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/complex.exp
gdb/testsuite/gdb.fortran/complex.f [deleted file]
gdb/testsuite/gdb.fortran/complex.f90 [new file with mode: 0644]

index f6a1976defffa6939df20b7e2c942d0d4472a170..2ccda008f067a6e388239b6f0e3e07963544405f 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-30  Andrew Burgess  <andrew.burgess@embecosm.com>
+           Chris January  <chris.january@arm.com>
+
+       * dwarf2read.c (dwarf2_init_complex_target_type): Use different
+       types for Fortran.
+
 2019-04-30  Andrew Burgess  <andrew.burgess@embecosm.com>
            Chris January  <chris.january@arm.com>
            David Lecomber  <david.lecomber@arm.com>
index 4259c386b9b21f80a0472106a100d0c2a251668a..571fe1e768d702d8fdff668842fc573e7716e2da 100644 (file)
@@ -17545,17 +17545,37 @@ dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
   /* Try to find a suitable floating point builtin type of size BITS.
      We're going to use the name of this type as the name for the complex
      target type that we are about to create.  */
-  switch (bits)
+  switch (cu->language)
     {
-    case 32:
-      tt = builtin_type (gdbarch)->builtin_float;
-      break;
-    case 64:
-      tt = builtin_type (gdbarch)->builtin_double;
+    case language_fortran:
+      switch (bits)
+       {
+       case 32:
+         tt = builtin_f_type (gdbarch)->builtin_real;
+         break;
+       case 64:
+         tt = builtin_f_type (gdbarch)->builtin_real_s8;
+         break;
+       case 96:        /* The x86-32 ABI specifies 96-bit long double.  */
+       case 128:
+         tt = builtin_f_type (gdbarch)->builtin_real_s16;
+         break;
+       }
       break;
-    case 96:   /* The x86-32 ABI specifies 96-bit long double.  */
-    case 128:
-      tt = builtin_type (gdbarch)->builtin_long_double;
+    default:
+      switch (bits)
+       {
+       case 32:
+         tt = builtin_type (gdbarch)->builtin_float;
+         break;
+       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;
+       }
       break;
     }
 
index 7489ab9ec29c1b6793e1921a86ba120295400bc0..5bbf15185e2f8a4a30da7cb6424ab1c8d088a37e 100644 (file)
@@ -1,3 +1,10 @@
+2019-04-30  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.fortran/complex.exp: Expand.
+       * gdb.fortran/complex.f: Renamed to...
+       * gdb.fortran/complex.f90: ...this, and extended to add more
+       complex values.
+
 2019-04-30  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.fortran/intrinsics.exp: Extend to cover MOD, CEILING, FLOOR,
index 3fbbf7154d9e25f0b6fdeeca437dbae236d69e1a..136f1c4df7912776cda840869da36de184761b08 100644 (file)
@@ -13,7 +13,7 @@
 # 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 .f
+standard_testfile .f90
 
 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90 quiet}]} {
     return -1
@@ -24,13 +24,36 @@ if ![runto MAIN__] then {
     continue
 }
 
-set bp_location [gdb_get_line_number "stop"]
-gdb_test "break $bp_location" \
-    "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \
-    "breakpoint at stop"
 
-gdb_test "continue" \
-    "Continuing\\..*Breakpoint.*" \
-    "continue to breakpoint"
+gdb_breakpoint [gdb_get_line_number "stop"]
+gdb_continue_to_breakpoint "continue"
+
+gdb_test "print c" " = \\(1000,-50\\)"
+gdb_test "print c4" " = \\(1000,-50\\)"
+gdb_test "print c8" " = \\(321,-22\\)"
+gdb_test "print dc" " = \\(321,-22\\)"
+
+setup_kfail gdb/18644 "*-*-*"
+gdb_test "print c16" " = \\(-874,19\\)"
+
+gdb_test "whatis c" "type = complex\\(kind=4\\)"
+gdb_test "print \$_creal (c)" " = 1000"
+gdb_test "whatis \$" " = real"
+
+gdb_test "whatis c4" "type = complex\\(kind=4\\)"
+gdb_test "print \$_creal (c4)" " = 1000"
+gdb_test "whatis \$" " = real"
+
+gdb_test "whatis c8" "type = complex\\(kind=8\\)"
+gdb_test "print \$_creal (c8)" " = 321"
+gdb_test "whatis \$" " = real\\*8"
+
+gdb_test "whatis dc" "type = complex\\(kind=8\\)"
+gdb_test "print \$_creal (dc)" " = 321"
+gdb_test "whatis \$" " = real\\*8"
+
+gdb_test "whatis c16" "type = complex\\(kind=16\\)"
+setup_kfail gdb/18644 "*-*-*"
+gdb_test "print \$_creal (c16)" " = -874"
+gdb_test "whatis \$" " = real\\*16"
 
-gdb_test "print c" "\\\$$decimal = \\(1000,-50\\)"
diff --git a/gdb/testsuite/gdb.fortran/complex.f b/gdb/testsuite/gdb.fortran/complex.f
deleted file mode 100644 (file)
index 2f1a787..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-c Copyright 2007-2019 Free Software Foundation, Inc.
-
-c This program is free software; you can redistribute it and/or modify
-c it under the terms of the GNU General Public License as published by
-c the Free Software Foundation; either version 3 of the License, or
-c (at your option) any later version.
-c
-c This program is distributed in the hope that it will be useful,
-c but WITHOUT ANY WARRANTY; without even the implied warranty of
-c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-c GNU General Public License for more details.
-c
-c You should have received a copy of the GNU General Public License
-c along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-      real*8 a,b
-      complex*16 c
-
-      a = 1000
-      b = -50
-      c = cmplx(a,b)
-      write(*,*) s
-      stop
-      end
diff --git a/gdb/testsuite/gdb.fortran/complex.f90 b/gdb/testsuite/gdb.fortran/complex.f90
new file mode 100644 (file)
index 0000000..2b88c1e
--- /dev/null
@@ -0,0 +1,44 @@
+! Copyright 2007-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/>.
+
+program test_complex
+  real*4 r4a, r4b
+  real*8 r8a, r8b
+  real*16 r16a, r16b
+
+  complex c
+  complex(kind=4) c4
+  complex(kind=8) c8
+  double complex dc
+  complex(kind=16) c16
+
+  r4a = 1000
+  r4b = -50
+  r8a = 321
+  r8b = -22
+  r16a = -874
+  r16b = 19
+
+  c = cmplx(r4a,r4b)
+  c4 = cmplx(r4a,r4b)
+  c8 = cmplx(r8a, r8b)
+  dc = cmplx(r8a, r8b)
+  c16 = cmplx(r16a, r16b)
+
+  print *, c, c4, c8, dc, c16  ! stop
+  print *, r4a, r4b
+  print *, r8a, r8b
+  print *, r16a, r16b
+end program test_complex