gdb/fortran: Nested subroutine support
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.fortran / nested-funcs.exp
1 # Copyright 2016-2019 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 if { [skip_fortran_tests] } { return -1 }
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 ![runto MAIN__] then {
29 perror "couldn't run to breakpoint MAIN__"
30 continue
31 }
32
33 # Test if we can set a breakpoint in a nested function
34 gdb_breakpoint "testnestedfuncs::sub_nested_outer"
35 gdb_continue_to_breakpoint "testnestedfuncs::sub_nested_outer" \
36 ".*local_int = 19"
37
38 # Test if we can access local and
39 # non-local variables defined one level up.
40 gdb_breakpoint [gdb_get_line_number "! BP_outer"]
41 gdb_continue_to_breakpoint "! BP_outer" ".*! BP_outer"
42 gdb_test "print index" "= 13" "print index at BP_outer"
43 gdb_test_no_output "set variable index = 42"
44 gdb_test "print index" "= 42" "print index at BP_outer, manipulated"
45 gdb_test "print local_int" "= 19" "print local_int in outer function"
46
47 # Non-local variable should be affected in one frame up as well.
48 gdb_test "up"
49 gdb_test "print index" "= 42" "print index at BP1, one frame up"
50
51 # Test if we can set a breakpoint in a nested function
52 gdb_breakpoint "testnestedfuncs::sub_nested_inner"
53 gdb_continue_to_breakpoint "testnestedfuncs::sub_nested_inner" \
54 ".*local_int = 17"
55
56 # Test if we can access local and
57 # non-local variables defined two level up.
58 gdb_breakpoint [gdb_get_line_number "! BP_inner"]
59 gdb_continue_to_breakpoint "! BP_inner" ".*! BP_inner"
60 gdb_test "print index" "= 42" "print index at BP_inner"
61 gdb_test "print v_state%code" "= 61" "print v_state%code at BP_inner"
62 gdb_test "print local_int" "= 17" "print local_int in inner function"
63
64 # Test if local variable is still correct.
65 gdb_breakpoint [gdb_get_line_number "! BP_outer_2"]
66 gdb_continue_to_breakpoint "! BP_outer_2" ".*! BP_outer_2"
67 gdb_test "print local_int" "= 19" \
68 "print local_int in outer function, after sub_nested_inner"
69
70 # Test if we can set a breakpoint in public routine with the same name
71 # as the internal
72 gdb_breakpoint "sub_nested_outer"
73 gdb_continue_to_breakpoint "sub_nested_outer" \
74 ".*name = 'sub_nested_outer external'"
75
76 # Test if we can set a breakpoint in public routine with the same name
77 # as the internal
78 gdb_breakpoint "sub_with_sub_nested_outer::sub_nested_outer"
79 gdb_continue_to_breakpoint \
80 "sub_with_sub_nested_outer::sub_nested_outer" ".*local_int = 11"
81
82 # Test if we can set a breakpoint in public routine with the same name
83 # as the internal
84 gdb_breakpoint "mod1::sub_nested_outer"
85 gdb_continue_to_breakpoint "mod1::sub_nested_outer" \
86 ".*name = 'sub_nested_outer_mod1'"
87
88 # Sanity check in main.
89 gdb_breakpoint [gdb_get_line_number "! BP_main"]
90 gdb_continue_to_breakpoint "! BP_main" ".*! BP_main"
91 gdb_test "print index" "= 42" "print index at BP_main"
92 gdb_test "print v_state%code" "= 59" "print v_state%code at BP_main"
This page took 0.036949 seconds and 4 git commands to generate.