gdb/fortran: Implement la_print_typedef for Fortran
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 9 Jul 2019 14:47:19 +0000 (15:47 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 28 Aug 2019 12:33:54 +0000 (13:33 +0100)
Implement an la_print_typedef method for Fortran, this allows 'info
types' to work for Fortran.  The implementation is just copied from
ada_print_typedef (with the appropriate changes).

To support the testing of this patch I added a new proc,
fortran_character1, to lib/fortran.exp which returns a regexp to match
a 1-byte character type.  The regexp returned is correct for current
versions of gFortran.  All of the other regexp are guesses based on
all of the other support procs in lib/fortran.exp, I haven't tested
them myself.

gdb/ChangeLog:

* f-lang.c (f_language_defn): Use f_print_typedef.
* f-lang.h (f_print_typedef): Declare.
* f-typeprint.c (f_print_typedef): Define.

gdb/testsuite/ChangeLog:

* gdb.fortran/info-types.exp: New file.
* gdb.fortran/info-types.f90: New file.
* lib/fortran.exp (fortran_character1): New proc.

gdb/ChangeLog
gdb/f-lang.c
gdb/f-lang.h
gdb/f-typeprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/info-types.exp [new file with mode: 0644]
gdb/testsuite/gdb.fortran/info-types.f90 [new file with mode: 0644]
gdb/testsuite/lib/fortran.exp

index 002825312c3f1e93f8bf2572b81beaf830d4c779..4767e03b7e083f527457c72fcdde5e884cf9f68b 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-28  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * f-lang.c (f_language_defn): Use f_print_typedef.
+       * f-lang.h (f_print_typedef): Declare.
+       * f-typeprint.c (f_print_typedef): Define.
+
 2019-08-27  Christian Biesinger  <cbiesinger@google.com>
 
        * nat/linux-namespaces.c (mnsh_main): Initialize fd (to -1).
index e93a5f342764fd60439f4a12fb4a44535ae217af..ce7f1471c52d9c6f3338946841d7f4a7e3931d4a 100644 (file)
@@ -644,7 +644,7 @@ extern const struct language_defn f_language_defn =
   f_printstr,                  /* function to print string constant */
   f_emit_char,                 /* Function to print a single character */
   f_print_type,                        /* Print a type using appropriate syntax */
-  default_print_typedef,       /* Print a typedef using appropriate syntax */
+  f_print_typedef,             /* Print a typedef using appropriate syntax */
   f_val_print,                 /* Print a value using appropriate syntax */
   c_value_print,               /* FIXME */
   default_read_var_value,      /* la_read_var_value */
index 1ba529d76c518225e66462f5d69f5cc98c9900a1..cf6024c4454a48bf967545a3035616f36cd1510e 100644 (file)
@@ -28,6 +28,11 @@ struct parser_state;
 
 extern int f_parse (struct parser_state *);
 
+/* Implement the la_print_typedef language method for Fortran.  */
+
+extern void f_print_typedef (struct type *type, struct symbol *new_symbol,
+                            struct ui_file *stream);
+
 extern void f_print_type (struct type *, const char *, struct ui_file *, int,
                          int, const struct type_print_options *);
 
index 17ac02f4ccf7d7592bad79eb07f67264eb1c048f..92b50938740a78ce59a998a9efe40c5984827562 100644 (file)
@@ -45,6 +45,17 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
 void f_type_print_base (struct type *, struct ui_file *, int, int);
 \f
 
+/* See documentation in f-lang.h.  */
+
+void
+f_print_typedef (struct type *type, struct symbol *new_symbol,
+                struct ui_file *stream)
+{
+  type = check_typedef (type);
+  f_print_type (type, "", stream, 0, 0, &type_print_raw_options);
+  fprintf_filtered (stream, "\n");
+}
+
 /* LEVEL is the depth to indent lines by.  */
 
 void
index 7b6793b0a298b49c0b6d82a559050c5985817410..02a3c01667cbdc1af3cd361d14484d36498db62c 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-28  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.fortran/info-types.exp: New file.
+       * gdb.fortran/info-types.f90: New file.
+       * lib/fortran.exp (fortran_character1): New proc.
+
 2019-08-27  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.base/info-fun.exp: Extend to test the -n flag for 'info
diff --git a/gdb/testsuite/gdb.fortran/info-types.exp b/gdb/testsuite/gdb.fortran/info-types.exp
new file mode 100644 (file)
index 0000000..9571dc4
--- /dev/null
@@ -0,0 +1,45 @@
+# 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/>.
+
+# This file tests 'info types' for some Fortran types.
+
+load_lib "fortran.exp"
+
+if { [skip_fortran_tests] } { continue }
+
+standard_testfile .f90
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } {
+    return -1
+}
+
+if { ![runto MAIN__] } {
+    perror "Could not run to breakpoint `MAIN__'."
+    continue
+}
+
+set integer4 [fortran_int4]
+set logical4 [fortran_logical4]
+set character1 [fortran_character1]
+
+gdb_test "info types" \
+    [multi_line \
+        "All defined types:" \
+        "" \
+        "File .*:" \
+        "\[\t \]+${character1}" \
+        "\[\t \]+${integer4}" \
+        "\[\t \]+${logical4}" \
+        "16:\[\t \]+Type s1;" ]
diff --git a/gdb/testsuite/gdb.fortran/info-types.f90 b/gdb/testsuite/gdb.fortran/info-types.f90
new file mode 100644 (file)
index 0000000..21c9d9d
--- /dev/null
@@ -0,0 +1,25 @@
+! 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 2 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 info_types_test
+  type :: s1
+     integer :: a
+  end type s1
+
+  logical :: l
+  type (s1) :: var_a
+  var_a%a = 1
+  l = .FALSE.
+end program info_types_test
index d3a35cd291e36a88da5ae5eca9941df7b408d814..81811dbc3c9d2bc5fa119a7848e36999bdb7f1fc 100644 (file)
@@ -88,3 +88,15 @@ proc fortran_logical4 {} {
        return "unknown"
     }
 }
+
+proc fortran_character1 {} {
+    if {[test_compiler_info {gcc-4-[012]-*}]} {
+       return "character1"
+    } elseif {[test_compiler_info {gcc-*}]} {
+       return "character\\(kind=1\\)"
+    } elseif {[test_compiler_info {icc-*}]} {
+       return "CHARACTER\\(1\\)"
+    } else {
+       return "unknown"
+    }
+}
This page took 0.037546 seconds and 4 git commands to generate.