1 # Copyright 2009-2020 Free Software Foundation, Inc.
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.
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.
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/>.
16 load_lib "fortran.exp"
18 standard_testfile .f90
20 if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } {
24 # Test automatic language detection before the inferior starts. It tests the
27 # The current source language is "auto; currently fortran".
28 gdb_test "p modmany::var_i" " = 14" "stopped language detection"
30 gdb_test "print mod1::var_const" " = 20" "fully qualified name of DW_TAG_constant"
32 if ![fortran_runto_main] then {
33 perror "couldn't run to main"
37 set int_type [fortran_int4]
39 # Test 'info variables' can find module variables.
42 "18:\[ \t\]+${int_type} mod1::var_const;" \
43 "17:\[ \t\]+${int_type} mod1::var_i;" \
44 "23:\[ \t\]+${int_type} mod2::var_i;" \
45 "28:\[ \t\]+${int_type} mod3::mod1;" \
46 "27:\[ \t\]+${int_type} mod3::mod2;" \
47 "29:\[ \t\]+${int_type} mod3::var_i;" \
48 "33:\[ \t\]+${int_type} modmany::var_a;" \
49 "33:\[ \t\]+${int_type} modmany::var_b;" \
50 "33:\[ \t\]+${int_type} modmany::var_c;" \
51 "33:\[ \t\]+${int_type} modmany::var_i;" \
52 "37:\[ \t\]+${int_type} moduse::var_x;" \
53 "37:\[ \t\]+${int_type} moduse::var_y;"]
56 gdb_test_multiple "info variables -n" "" {
57 -re "\r\nAll defined variables:" {
58 if { $state == 0 } { set state 1 }
61 -re "\r\n\r\nFile .*[string_to_regexp $srcfile]:" {
62 if { $state == 1 } { set state 2 }
66 if { $state == 2 } { set state 3 }
69 -re "\r\n\r\nFile \[^\r\n\]*:" {
81 # Do not use simple single-letter names as GDB would pick up for expectedly
82 # nonexisting symbols some static variables from system libraries debuginfos.
84 gdb_breakpoint [gdb_get_line_number "i-is-1"]
85 gdb_continue_to_breakpoint "i-is-1" ".*i-is-1.*"
86 gdb_test "print var_i" " = 1" "print var_i value 1"
88 gdb_breakpoint [gdb_get_line_number "i-is-2"]
89 gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
90 gdb_test "print var_i" " = 2" "print var_i value 2"
92 gdb_breakpoint [gdb_get_line_number "i-is-3"]
93 gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
94 # Ensure that the scope is correctly resolved.
95 gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
96 gdb_test "p mod2" " = 3" "print mod2"
97 gdb_test "p mod1" " = 3" "print mod1"
99 gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
100 gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
101 gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
102 gdb_test "print var_b" " = 11"
103 gdb_test "print var_c" "No symbol \"var_c\" in current context\\."
104 gdb_test "print var_d" " = 12"
105 gdb_test "print var_i" " = 14" "print var_i value 14"
106 gdb_test "print var_x" " = 30" "print var_x value 30"
107 gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
108 gdb_test "print var_z" " = 31" "print var_x value 31"
110 gdb_test "ptype modmany" "type = module modmany"
112 proc complete {expr list} {
113 set cmd "complete p $expr"
114 set expect [join [concat [list $cmd] $list] "\r\np "]
115 gdb_test $cmd $expect "complete $expr"
117 set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
118 complete "modm" "modmany $modmany_list"
119 complete "modmany" "modmany $modmany_list"
120 complete "modmany::" $modmany_list
121 complete "modmany::var" $modmany_list
123 # Breakpoint would work in language "c".
124 gdb_test "show language" {The current source language is "(auto; currently )?fortran".}
126 # gcc-4.4.2: The main program is always $fmain in .symtab so "runto" above
127 # works. But DWARF DW_TAG_subprogram contains the name specified by
128 # the "program" Fortran statement.
129 if [gdb_breakpoint "module"] {
130 pass "setting breakpoint at module"