aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.fortran/module.exp
blob: a2aff3cb7c73a3b58258eafb7541fa3b5d4320a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2009-2019 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

load_lib "fortran.exp"

standard_testfile .f90

if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } {
    return -1
}

# Test automatic language detection before the inferior starts.  It tests the
# effect of expected:
# (gdb) show language 
# The current source language is "auto; currently fortran".
gdb_test "p modmany::var_i" " = 14" "stopped language detection"

gdb_test "print mod1::var_const" " = 20" "fully qualified name of DW_TAG_constant"

if ![runto MAIN__] then {
    perror "couldn't run to breakpoint MAIN__"
    continue
}

set int_type [fortran_int4]

# Test 'info variables' can find module variables.
gdb_test "info variables -n" \
    [multi_line \
	 "All defined variables:" \
	 "" \
	 "File .*$srcfile:" \
	 "18:\[ \t\]+${int_type} mod1::var_const;" \
	 "17:\[ \t\]+${int_type} mod1::var_i;" \
	 "23:\[ \t\]+${int_type} mod2::var_i;" \
	 "28:\[ \t\]+${int_type} mod3::mod1;" \
	 "27:\[ \t\]+${int_type} mod3::mod2;" \
	 "29:\[ \t\]+${int_type} mod3::var_i;" \
	 "33:\[ \t\]+${int_type} modmany::var_a;" \
	 "33:\[ \t\]+${int_type} modmany::var_b;" \
	 "33:\[ \t\]+${int_type} modmany::var_c;" \
	 "33:\[ \t\]+${int_type} modmany::var_i;" \
	 "37:\[ \t\]+${int_type} moduse::var_x;" \
	 "37:\[ \t\]+${int_type} moduse::var_y;(" \
	 "" \
	 "File .*:(" \
	 "$decimal:.*)+)*"]


# Do not use simple single-letter names as GDB would pick up for expectedly
# nonexisting symbols some static variables from system libraries debuginfos.

gdb_breakpoint [gdb_get_line_number "i-is-1"]
gdb_continue_to_breakpoint "i-is-1" ".*i-is-1.*"
gdb_test "print var_i" " = 1" "print var_i value 1"

gdb_breakpoint [gdb_get_line_number "i-is-2"]
gdb_continue_to_breakpoint "i-is-2" ".*i-is-2.*"
gdb_test "print var_i" " = 2" "print var_i value 2"

gdb_breakpoint [gdb_get_line_number "i-is-3"]
gdb_continue_to_breakpoint "i-is-3" ".*i-is-3.*"
# Ensure that the scope is correctly resolved.
gdb_test "p mod3" "Attempt to use a type name as an expression" "print mod3"
gdb_test "p mod2" " = 3" "print mod2"
gdb_test "p mod1" " = 3" "print mod1"

gdb_breakpoint [gdb_get_line_number "a-b-c-d"]
gdb_continue_to_breakpoint "a-b-c-d" ".*a-b-c-d.*"
gdb_test "print var_a" "No symbol \"var_a\" in current context\\."
gdb_test "print var_b" " = 11"
gdb_test "print var_c" "No symbol \"var_c\" in current context\\."
gdb_test "print var_d" " = 12"
gdb_test "print var_i" " = 14" "print var_i value 14"
gdb_test "print var_x" " = 30" "print var_x value 30"
gdb_test "print var_y" "No symbol \"var_y\" in current context\\."
gdb_test "print var_z" " = 31" "print var_x value 31"

gdb_test "ptype modmany" "type = module modmany"

proc complete {expr list} {
    set cmd "complete p $expr"
    set expect [join [concat [list $cmd] $list] "\r\np "]
    gdb_test $cmd $expect "complete $expr"
}
set modmany_list {modmany::var_a modmany::var_b modmany::var_c modmany::var_i}
complete "modm" "modmany $modmany_list"
complete "modmany" "modmany $modmany_list"
complete "modmany::" $modmany_list
complete "modmany::var" $modmany_list

# Breakpoint would work in language "c".
gdb_test "show language" {The current source language is "(auto; currently )?fortran".}

# gcc-4.4.2: The main program is always MAIN__ in .symtab so "runto" above
# works.  But DWARF DW_TAG_subprogram contains the name specified by
# the "program" Fortran statement.
if [gdb_breakpoint "module"] {
    pass "setting breakpoint at module"
}