]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.fortran/module.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.fortran / module.exp
CommitLineData
1d506c26 1# Copyright 2009-2024 Free Software Foundation, Inc.
5d7cb8df
JK
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
0b54364d
AB
16load_lib "fortran.exp"
17
57b7402d 18require allow_fortran_tests
a54a7f13 19
cf09b3e4 20standard_testfile .f90
5d7cb8df 21
5b362f04 22if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } {
5d7cb8df
JK
23 return -1
24}
25
fd5700c7
JK
26# Test automatic language detection before the inferior starts. It tests the
27# effect of expected:
28# (gdb) show language
29# The current source language is "auto; currently fortran".
30gdb_test "p modmany::var_i" " = 14" "stopped language detection"
31
c2b0a229
JK
32gdb_test "print mod1::var_const" " = 20" "fully qualified name of DW_TAG_constant"
33
f9edf608
TV
34# Avoid shared lib symbols.
35gdb_test_no_output "set auto-solib-add off"
36
49bb4744 37if {![fortran_runto_main]} {
cdd42066 38 return
5d7cb8df
JK
39}
40
f9edf608
TV
41# Avoid libc symbols.
42gdb_test "nosharedlibrary"
43
0b54364d
AB
44set int_type [fortran_int4]
45
46# Test 'info variables' can find module variables.
e515d67e 47set mod_re \
0b54364d 48 [multi_line \
0b54364d
AB
49 "18:\[ \t\]+${int_type} mod1::var_const;" \
50 "17:\[ \t\]+${int_type} mod1::var_i;" \
51 "23:\[ \t\]+${int_type} mod2::var_i;" \
52 "28:\[ \t\]+${int_type} mod3::mod1;" \
53 "27:\[ \t\]+${int_type} mod3::mod2;" \
54 "29:\[ \t\]+${int_type} mod3::var_i;" \
55 "33:\[ \t\]+${int_type} modmany::var_a;" \
56 "33:\[ \t\]+${int_type} modmany::var_b;" \
57 "33:\[ \t\]+${int_type} modmany::var_c;" \
58 "33:\[ \t\]+${int_type} modmany::var_i;" \
59 "37:\[ \t\]+${int_type} moduse::var_x;" \
e515d67e 60 "37:\[ \t\]+${int_type} moduse::var_y;"]
0b54364d 61
e515d67e
TV
62set state 0
63gdb_test_multiple "info variables -n" "" {
64 -re "\r\nAll defined variables:" {
65 if { $state == 0 } { set state 1 }
66 exp_continue
67 }
68 -re "\r\n\r\nFile .*[string_to_regexp $srcfile]:" {
69 if { $state == 1 } { set state 2 }
70 exp_continue
71 }
72 -re $mod_re {
73 if { $state == 2 } { set state 3 }
74 exp_continue
75 }
76 -re "\r\n\r\nFile \[^\r\n\]*:" {
77 exp_continue
78 }
79 -re -wrap "" {
80 if { $state == 3} {
81 pass $gdb_test_name
82 } else {
83 fail $gdb_test_name
84 }
85 }
86}
0b54364d 87
f55ee35c
JK
88# Do not use simple single-letter names as GDB would pick up for expectedly
89# nonexisting symbols some static variables from system libraries debuginfos.
90
91gdb_breakpoint [gdb_get_line_number "i-is-1"]
92gdb_continue_to_breakpoint "i-is-1" ".*i-is-1.*"
93gdb_test "print var_i" " = 1" "print var_i value 1"
94
95gdb_breakpoint [gdb_get_line_number "i-is-2"]
96gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
97gdb_test "print var_i" " = 2" "print var_i value 2"
98
530e8392
KB
99gdb_breakpoint [gdb_get_line_number "i-is-3"]
100gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
101# Ensure that the scope is correctly resolved.
102gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
103gdb_test "p mod2" " = 3" "print mod2"
104gdb_test "p mod1" " = 3" "print mod1"
105
f55ee35c
JK
106gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
107gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
108gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
109gdb_test "print var_b" " = 11"
110gdb_test "print var_c" "No symbol \"var_c\" in current context\\."
111gdb_test "print var_d" " = 12"
112gdb_test "print var_i" " = 14" "print var_i value 14"
32019081
JK
113gdb_test "print var_x" " = 30" "print var_x value 30"
114gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
115gdb_test "print var_z" " = 31" "print var_x value 31"
f55ee35c 116
530e8392 117gdb_test "ptype modmany" "type = module modmany"
f55ee35c
JK
118
119proc complete {expr list} {
6b7b705d 120 set n_lines "\(?:\\r\\n.*\)*"
f55ee35c 121 set cmd "complete p $expr"
6b7b705d
NCK
122 set expect [join [concat [list $cmd] $list] $n_lines]
123 gdb_test $cmd "$expect$n_lines" "complete $expr"
f55ee35c
JK
124}
125set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
530e8392
KB
126complete "modm" "modmany $modmany_list"
127complete "modmany" "modmany $modmany_list"
f55ee35c
JK
128complete "modmany::" $modmany_list
129complete "modmany::var" $modmany_list
130
131# Breakpoint would work in language "c".
132gdb_test "show language" {The current source language is "(auto; currently )?fortran".}
133
86cd6bc8 134# gcc-4.4.2: The main program is always $fmain in .symtab so "runto" above
f55ee35c
JK
135# works. But DWARF DW_TAG_subprogram contains the name specified by
136# the "program" Fortran statement.
137if [gdb_breakpoint "module"] {
138 pass "setting breakpoint at module"
139}