Remove path name from test case
[binutils-gdb.git] / gdb / testsuite / gdb.fortran / nested-funcs.exp
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
19 require allow_fortran_tests
20
21 standard_testfile .f90
22 load_lib "fortran.exp"
23
24 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}]} {
25 return -1
26 }
27
28 if {![fortran_runto_main]} {
29 continue
30 }
31
32 # Test if we can set a breakpoint in a nested function
33 gdb_breakpoint "testnestedfuncs::sub_nested_outer"
34 gdb_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.
39 gdb_breakpoint [gdb_get_line_number "! BP_outer"]
40 gdb_continue_to_breakpoint "! BP_outer" ".*! BP_outer"
41 gdb_test "print index" "= 13" "print index at BP_outer"
42 gdb_test_no_output "set variable index = 42"
43 gdb_test "print index" "= 42" "print index at BP_outer, manipulated"
44 gdb_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.
47 gdb_test "up"
48 gdb_test "print index" "= 42" "print index at BP1, one frame up"
49
50 # Test if we can set a breakpoint in a nested function
51 gdb_breakpoint "testnestedfuncs::sub_nested_inner"
52 gdb_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.
57 gdb_breakpoint [gdb_get_line_number "! BP_inner"]
58 gdb_continue_to_breakpoint "! BP_inner" ".*! BP_inner"
59 gdb_test "print index" "= 42" "print index at BP_inner"
60 gdb_test "print v_state%code" "= 61" "print v_state%code at BP_inner"
61 gdb_test "print local_int" "= 17" "print local_int in inner function"
62
63 # Test if local variable is still correct.
64 gdb_breakpoint [gdb_get_line_number "! BP_outer_2"]
65 gdb_continue_to_breakpoint "! BP_outer_2" ".*! BP_outer_2"
66 gdb_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
71 gdb_breakpoint "sub_nested_outer"
72 gdb_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
77 gdb_breakpoint "sub_with_sub_nested_outer::sub_nested_outer"
78 gdb_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
83 gdb_breakpoint "mod1::sub_nested_outer"
84 gdb_continue_to_breakpoint "mod1::sub_nested_outer" \
85 ".*name = 'sub_nested_outer_mod1'"
86
87 # Sanity check in main.
88 gdb_breakpoint [gdb_get_line_number "! BP_main"]
89 gdb_continue_to_breakpoint "! BP_main" ".*! BP_main"
90 gdb_test "print index" "= 42" "print index at BP_main"
91 gdb_test "print v_state%code" "= 59" "print v_state%code at BP_main"