Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.fortran / module.exp
CommitLineData
88b9d363 1# Copyright 2009-2022 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
a54a7f13
PA
18if {[skip_fortran_tests]} { return -1 }
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
86cd6bc8
AKS
34if ![fortran_runto_main] then {
35 perror "couldn't run to main"
5d7cb8df
JK
36 continue
37}
38
0b54364d
AB
39set int_type [fortran_int4]
40
41# Test 'info variables' can find module variables.
e515d67e 42set mod_re \
0b54364d 43 [multi_line \
0b54364d
AB
44 "18:\[ \t\]+${int_type} mod1::var_const;" \
45 "17:\[ \t\]+${int_type} mod1::var_i;" \
46 "23:\[ \t\]+${int_type} mod2::var_i;" \
47 "28:\[ \t\]+${int_type} mod3::mod1;" \
48 "27:\[ \t\]+${int_type} mod3::mod2;" \
49 "29:\[ \t\]+${int_type} mod3::var_i;" \
50 "33:\[ \t\]+${int_type} modmany::var_a;" \
51 "33:\[ \t\]+${int_type} modmany::var_b;" \
52 "33:\[ \t\]+${int_type} modmany::var_c;" \
53 "33:\[ \t\]+${int_type} modmany::var_i;" \
54 "37:\[ \t\]+${int_type} moduse::var_x;" \
e515d67e 55 "37:\[ \t\]+${int_type} moduse::var_y;"]
0b54364d 56
e515d67e
TV
57set state 0
58gdb_test_multiple "info variables -n" "" {
59 -re "\r\nAll defined variables:" {
60 if { $state == 0 } { set state 1 }
61 exp_continue
62 }
63 -re "\r\n\r\nFile .*[string_to_regexp $srcfile]:" {
64 if { $state == 1 } { set state 2 }
65 exp_continue
66 }
67 -re $mod_re {
68 if { $state == 2 } { set state 3 }
69 exp_continue
70 }
71 -re "\r\n\r\nFile \[^\r\n\]*:" {
72 exp_continue
73 }
74 -re -wrap "" {
75 if { $state == 3} {
76 pass $gdb_test_name
77 } else {
78 fail $gdb_test_name
79 }
80 }
81}
0b54364d 82
f55ee35c
JK
83# Do not use simple single-letter names as GDB would pick up for expectedly
84# nonexisting symbols some static variables from system libraries debuginfos.
85
86gdb_breakpoint [gdb_get_line_number "i-is-1"]
87gdb_continue_to_breakpoint "i-is-1" ".*i-is-1.*"
88gdb_test "print var_i" " = 1" "print var_i value 1"
89
90gdb_breakpoint [gdb_get_line_number "i-is-2"]
91gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
92gdb_test "print var_i" " = 2" "print var_i value 2"
93
530e8392
KB
94gdb_breakpoint [gdb_get_line_number "i-is-3"]
95gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
96# Ensure that the scope is correctly resolved.
97gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
98gdb_test "p mod2" " = 3" "print mod2"
99gdb_test "p mod1" " = 3" "print mod1"
100
f55ee35c
JK
101gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
102gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
103gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
104gdb_test "print var_b" " = 11"
105gdb_test "print var_c" "No symbol \"var_c\" in current context\\."
106gdb_test "print var_d" " = 12"
107gdb_test "print var_i" " = 14" "print var_i value 14"
32019081
JK
108gdb_test "print var_x" " = 30" "print var_x value 30"
109gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
110gdb_test "print var_z" " = 31" "print var_x value 31"
f55ee35c 111
530e8392 112gdb_test "ptype modmany" "type = module modmany"
f55ee35c
JK
113
114proc complete {expr list} {
115 set cmd "complete p $expr"
116 set expect [join [concat [list $cmd] $list] "\r\np "]
117 gdb_test $cmd $expect "complete $expr"
118}
119set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
530e8392
KB
120complete "modm" "modmany $modmany_list"
121complete "modmany" "modmany $modmany_list"
f55ee35c
JK
122complete "modmany::" $modmany_list
123complete "modmany::var" $modmany_list
124
125# Breakpoint would work in language "c".
126gdb_test "show language" {The current source language is "(auto; currently )?fortran".}
127
86cd6bc8 128# gcc-4.4.2: The main program is always $fmain in .symtab so "runto" above
f55ee35c
JK
129# works. But DWARF DW_TAG_subprogram contains the name specified by
130# the "program" Fortran statement.
131if [gdb_breakpoint "module"] {
132 pass "setting breakpoint at module"
133}
This page took 1.450346 seconds and 4 git commands to generate.