aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.fortran
diff options
context:
space:
mode:
authorRichard Bunt <richard.bunt@linaro.org>2023-08-07 09:12:53 +0100
committerRichard Bunt <richard.bunt@linaro.org>2023-08-07 09:13:14 +0100
commit2f98b09492b33b95afcc1ac22d212ee4a5be0149 (patch)
tree70ae6d99817a818db71e0d990907db068daf6c27 /gdb/testsuite/gdb.fortran
parentad233d0d74661e5206d093e826db1eb4120c5fef (diff)
downloadbinutils-2f98b09492b33b95afcc1ac22d212ee4a5be0149.zip
binutils-2f98b09492b33b95afcc1ac22d212ee4a5be0149.tar.gz
binutils-2f98b09492b33b95afcc1ac22d212ee4a5be0149.tar.bz2
gdb/fortran: Align intrinsic/variable precedence
Fortran allows variables and function to be named after language defined intrinsics as they are not reserved keywords. For example, the abs maths intrinsic can be hidden by a user declaring a variable called abs. The behavior before this patch was to favour the intrinsic, which meant that any variables named, for example "allocated", could not be inspected by GDB. This patch inverts this priority to bring GDB's behaviour closer to the Fortran language, where the user defined symbol can hide the intrinsic. Special care was need to prevent any C symbols from overriding either Fortran intrinsics or user defined variables. This was observed to be the case when GDB has access to symbols for abs from libm. This was solved by only allowing symbols not marked with language_fortran to be overridden. In total this brings the order of precedence to the following (highest first): 1. User defined Fortran variable or function. 2. Fortran intrinsic. 3. Symbols from languages other than Fortran. The sizeof intrinsic is now case insensitive. This is closer to the Fortran language. I believe this change is safe enough as it increases the acceptance of the grammar, rather than restricts it. I.e. it should not break any existing scripts which rely on it. Unless of course they rely on SIZEOF being rejected. GDB built with GCC 13. No test suite regressions detected. Compilers: GCC, ACfL, Intel, Intel LLVM, NVHPC; Platforms: x86_64, aarch64. Existing tests in gdb.fortran cover the invocation of intrinsics including: intrinsics.exp, shape.exp, rank.exp, lbound-ubound.exp. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite/gdb.fortran')
-rw-r--r--gdb/testsuite/gdb.fortran/intrinsic-precedence.c18
-rw-r--r--gdb/testsuite/gdb.fortran/intrinsic-precedence.exp74
-rw-r--r--gdb/testsuite/gdb.fortran/intrinsic-precedence.f9033
3 files changed, 125 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.fortran/intrinsic-precedence.c b/gdb/testsuite/gdb.fortran/intrinsic-precedence.c
new file mode 100644
index 0000000..cec960c
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/intrinsic-precedence.c
@@ -0,0 +1,18 @@
+/* Copyright 2023 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/>. */
+
+int kind (int a) {
+ return 7;
+}
diff --git a/gdb/testsuite/gdb.fortran/intrinsic-precedence.exp b/gdb/testsuite/gdb.fortran/intrinsic-precedence.exp
new file mode 100644
index 0000000..3269033
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/intrinsic-precedence.exp
@@ -0,0 +1,74 @@
+# Copyright 2023 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/>.
+
+require allow_fortran_tests
+require allow_shlib_tests
+
+standard_testfile .f90
+load_lib fortran.exp
+
+set srcfile_lib ${srcdir}/${subdir}/${testfile}.c
+set binfile_lib [standard_output_file ${testfile}.so]
+set lib_flags [list debug]
+set bin_flags [list f90 debug shlib=${binfile_lib}]
+
+if {[gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $lib_flags] != "" } {
+ return -1
+}
+
+if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
+ ${bin_flags}]} {
+ return -1
+}
+
+if ![fortran_runto_main] {
+ return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "all-assigned"]
+gdb_continue_to_breakpoint "all-assigned"
+
+# Variable in source is upper case.
+gdb_test "print LOC" "17"
+gdb_test "print loc" "17"
+
+# Variable in source is lower case
+gdb_test "print UBOUND" "79"
+gdb_test "print ubound" "79"
+
+# Intrinsic hides a C symbol that has debug information. This mimics the abs
+# scenario, where it can exist as a function in C, a Fortran intrinsic and a
+# user defined variable/function.
+gdb_test "print kind(minus)" "4"
+# Confirm that the C symbol is there to be chosen if the precedence order is
+# incorrect.
+gdb_test "set lang c" \
+ "Warning: the current language does not match this frame."
+gdb_test "print kind(3)" "7"
+gdb_test_no_output "set lang fortran"
+
+# User defined abs function hides the intrinsic.
+gdb_breakpoint [gdb_get_line_number "user-abs"]
+gdb_continue_to_breakpoint "user-abs"
+set integer4 [fortran_int4]
+gdb_test "whatis abs" "void \\\(${integer4}(, uinteger\\\*8)?\\\)"
+
+# Test the scenario where the C defined version of kind is not returned by
+# lookup_symbol.
+gdb_test_no_output "set confirm off"
+# breakpoints cannot be reset without symbol information.
+gdb_test_no_output "delete"
+gdb_test "symbol-file" "No symbol file now."
+gdb_test "print kind(0)" "4"
diff --git a/gdb/testsuite/gdb.fortran/intrinsic-precedence.f90 b/gdb/testsuite/gdb.fortran/intrinsic-precedence.f90
new file mode 100644
index 0000000..7b7c3b2
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/intrinsic-precedence.f90
@@ -0,0 +1,33 @@
+! Copyright 2023 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, write to the Free Software
+! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+program intrinsic_precedence
+ implicit none
+ integer(kind=4) LOC, ubound, minus
+ LOC = 17
+ ubound = 79
+ minus = -1
+ print *, minus, LOC, ubound
+ call abs(minus) !all-assigned
+contains
+ subroutine abs(i)
+ integer(kind=4) :: i
+ if(i .lt. 0) then
+ i = -i
+ endif
+ print *, i !user-abs
+ end subroutine abs
+end program intrinsic_precedence