1# Copyright 2016-2023 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This testcase is supposed to test DWARF static link which is usually 17# used together with nested functions. 18 19if { [skip_fortran_tests] } { return -1 } 20 21standard_testfile .f90 22load_lib "fortran.exp" 23 24if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}]} { 25 return -1 26} 27 28if {![fortran_runto_main]} { 29 continue 30} 31 32# Test if we can set a breakpoint in a nested function 33gdb_breakpoint "testnestedfuncs::sub_nested_outer" 34gdb_continue_to_breakpoint "testnestedfuncs::sub_nested_outer" \ 35 ".*local_int = 19" 36 37# Test if we can access local and 38# non-local variables defined one level up. 39gdb_breakpoint [gdb_get_line_number "! BP_outer"] 40gdb_continue_to_breakpoint "! BP_outer" ".*! BP_outer" 41gdb_test "print index" "= 13" "print index at BP_outer" 42gdb_test_no_output "set variable index = 42" 43gdb_test "print index" "= 42" "print index at BP_outer, manipulated" 44gdb_test "print local_int" "= 19" "print local_int in outer function" 45 46# Non-local variable should be affected in one frame up as well. 47gdb_test "up" 48gdb_test "print index" "= 42" "print index at BP1, one frame up" 49 50# Test if we can set a breakpoint in a nested function 51gdb_breakpoint "testnestedfuncs::sub_nested_inner" 52gdb_continue_to_breakpoint "testnestedfuncs::sub_nested_inner" \ 53 ".*local_int = 17" 54 55# Test if we can access local and 56# non-local variables defined two level up. 57gdb_breakpoint [gdb_get_line_number "! BP_inner"] 58gdb_continue_to_breakpoint "! BP_inner" ".*! BP_inner" 59gdb_test "print index" "= 42" "print index at BP_inner" 60gdb_test "print v_state%code" "= 61" "print v_state%code at BP_inner" 61gdb_test "print local_int" "= 17" "print local_int in inner function" 62 63# Test if local variable is still correct. 64gdb_breakpoint [gdb_get_line_number "! BP_outer_2"] 65gdb_continue_to_breakpoint "! BP_outer_2" ".*! BP_outer_2" 66gdb_test "print local_int" "= 19" \ 67 "print local_int in outer function, after sub_nested_inner" 68 69# Test if we can set a breakpoint in public routine with the same name 70# as the internal 71gdb_breakpoint "sub_nested_outer" 72gdb_continue_to_breakpoint "sub_nested_outer" \ 73 ".*name = 'sub_nested_outer external'" 74 75# Test if we can set a breakpoint in public routine with the same name 76# as the internal 77gdb_breakpoint "sub_with_sub_nested_outer::sub_nested_outer" 78gdb_continue_to_breakpoint \ 79 "sub_with_sub_nested_outer::sub_nested_outer" ".*local_int = 11" 80 81# Test if we can set a breakpoint in public routine with the same name 82# as the internal 83gdb_breakpoint "mod1::sub_nested_outer" 84gdb_continue_to_breakpoint "mod1::sub_nested_outer" \ 85 ".*name = 'sub_nested_outer_mod1'" 86 87# Sanity check in main. 88gdb_breakpoint [gdb_get_line_number "! BP_main"] 89gdb_continue_to_breakpoint "! BP_main" ".*! BP_main" 90gdb_test "print index" "= 42" "print index at BP_main" 91gdb_test "print v_state%code" "= 59" "print v_state%code at BP_main" 92