Fortran: Testsuite, non-local references in nested functions.
authorBernhard Heckel <bernhard.heckel@intel.com>
Fri, 10 Jun 2016 09:16:49 +0000 (11:16 +0200)
committerBernhard Heckel <bernhard.heckel@intel.com>
Fri, 10 Jun 2016 09:16:49 +0000 (11:16 +0200)
Non-local references in nested functions are usually implemented
by using DWARF static link. This feature was added
with commit 63e43d3aedb8b1112899c2d0ad74cbbee687e5d6
(DWARF: handle non-local references in nested functions) but
a testcase was missing in Fortran.

2016-06-10  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Testsuite/Changelog:
* gdb.fortran/nested-funcs.exp: New.
* gdb.fortran/nested-funcs.f90: New.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/nested-funcs.exp [new file with mode: 0755]
gdb/testsuite/gdb.fortran/nested-funcs.f90 [new file with mode: 0755]

index 19b00a1..eda7b99 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-10  Bernhard Heckel  <bernhard.heckel@intel.com>
+
+       * gdb.fortran/nested-funcs.exp: New.
+       * gdb.fortran/nested-funcs.f90: New.
+
 2016-06-09  Toshihito Kikuchi  <k.toshihito@yahoo.de>
 
        * gdb.base/examine-backward.c: New file.
diff --git a/gdb/testsuite/gdb.fortran/nested-funcs.exp b/gdb/testsuite/gdb.fortran/nested-funcs.exp
new file mode 100755 (executable)
index 0000000..976aa22
--- /dev/null
@@ -0,0 +1,64 @@
+# Copyright 2016 Free Software Foundation, Inc.\r
+\r
+# This program is free software; you can redistribute it and/or modify\r
+# it under the terms of the GNU General Public License as published by\r
+# the Free Software Foundation; either version 3 of the License, or\r
+# (at your option) any later version.\r
+#\r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+# GNU General Public License for more details.\r
+#\r
+# You should have received a copy of the GNU General Public License\r
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+\r
+# This testcase is supposed to test DWARF static link which is usually\r
+# used together with nested functions.  \r
+\r
+if { [skip_fortran_tests] } { return -1 }\r
+\r
+standard_testfile .f90\r
+load_lib "fortran.exp"\r
+\r
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug f90}]} {\r
+    return -1\r
+}\r
+\r
+if ![runto MAIN__] then {\r
+    perror "couldn't run to breakpoint MAIN__"\r
+    continue\r
+}\r
+\r
+# Test if we can access local and\r
+# non-local variables defined one level up.\r
+gdb_breakpoint [gdb_get_line_number "! BP_outer"]\r
+gdb_continue_to_breakpoint "! BP_outer" ".*! BP_outer"\r
+gdb_test "print index" "= 13" "print index at BP_outer"\r
+gdb_test "set index = 42"\r
+gdb_test "print index" "= 42" "print index at BP_outer, manipulated"\r
+gdb_test "print local_int" "= 19" "print local_int in outer function"\r
+\r
+# Non-local variable should be affected in one frame up as well.\r
+gdb_test "up"\r
+gdb_test "print index" "= 42" "print index at BP1, one frame up"\r
+\r
+# Test if we can access local and\r
+# non-local variables defined two level up.\r
+gdb_breakpoint [gdb_get_line_number "! BP_inner"]\r
+gdb_continue_to_breakpoint "! BP_inner" ".*! BP_inner"\r
+gdb_test "print index" "= 42" "print index at BP_inner"\r
+gdb_test "print v_state%code" "= 61" "print v_state%code at BP_inner"\r
+gdb_test "print local_int" "= 17" "print local_int in inner function"\r
+\r
+# Test if local variable is still correct.\r
+gdb_breakpoint [gdb_get_line_number "! BP_outer_2"]\r
+gdb_continue_to_breakpoint "! BP_outer_2" ".*! BP_outer_2"\r
+gdb_test "print local_int" "= 19" \\r
+  "print local_int in outer function, after sub_nested_inner"\r
+\r
+# Sanity check in main.\r
+gdb_breakpoint [gdb_get_line_number "! BP_main"]\r
+gdb_continue_to_breakpoint "! BP_main" ".*! BP_main"\r
+gdb_test "print index" "= 42" "print index at BP_main"\r
+gdb_test "print v_state%code" "= 59" "print v_state%code at BP_main"\r
diff --git a/gdb/testsuite/gdb.fortran/nested-funcs.f90 b/gdb/testsuite/gdb.fortran/nested-funcs.f90
new file mode 100755 (executable)
index 0000000..5501b3b
--- /dev/null
@@ -0,0 +1,50 @@
+! Copyright 2016 Free Software Foundation, Inc.\r
+!\r
+! This program is free software; you can redistribute it and/or modify\r
+! it under the terms of the GNU General Public License as published by\r
+! the Free Software Foundation; either version 3 of the License, or\r
+! (at your option) any later version.\r
+!\r
+! This program is distributed in the hope that it will be useful,\r
+! but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+! GNU General Public License for more details.\r
+!\r
+! You should have received a copy of the GNU General Public License\r
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+\r
+program TestNestedFuncs\r
+\r
+  IMPLICIT NONE\r
+\r
+  TYPE :: t_State\r
+    integer :: code\r
+  END TYPE t_State\r
+\r
+  TYPE (t_State) :: v_state\r
+  integer index\r
+\r
+  index = 13\r
+  CALL sub_nested_outer\r
+  index = 11              ! BP_main\r
+  v_state%code = 27\r
+\r
+CONTAINS\r
+\r
+  SUBROUTINE sub_nested_outer\r
+    integer local_int\r
+    local_int = 19\r
+    v_state%code = index + local_int   ! BP_outer\r
+    call sub_nested_inner\r
+    local_int = 22                     ! BP_outer_2\r
+    RETURN\r
+  END SUBROUTINE sub_nested_outer\r
+\r
+  SUBROUTINE sub_nested_inner\r
+    integer local_int\r
+    local_int = 17\r
+    v_state%code = index + local_int   ! BP_inner\r
+    RETURN\r
+  END SUBROUTINE sub_nested_inner\r
+\r
+end program TestNestedFuncs\r