--- /dev/null
+# 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
--- /dev/null
+! 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