* gdb.cp/mb-ctor.exp: Check skip_cplus_tests.
[binutils-gdb.git] / gdb / testsuite / gdb.cp / mb-templates.exp
1 # Copyright 2007
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This test verifies that setting breakpoint on line in template
18 # function will fire in all instantiations of that template.
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 if { [skip_cplus_tests] } { continue }
25
26 set prms_id 0
27 set bug_id 0
28
29 set testfile "mb-templates"
30 set srcfile ${testfile}.cc
31 set binfile ${objdir}/${subdir}/${testfile}
32
33 if [get_compiler_info ${binfile} "c++"] {
34 return -1
35 }
36
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
38 untested mb-templates.exp
39 return -1
40 }
41
42 gdb_exit
43 gdb_start
44 gdb_reinitialize_dir $srcdir/$subdir
45 gdb_load ${binfile}
46
47 set bp_location [gdb_get_line_number "set breakpoint here"]
48
49 # Set a breakpoint with multiple locations
50 # and a condition.
51
52 gdb_test "break $srcfile:$bp_location if i==1" \
53 "Breakpoint.*at.* file .*$srcfile, line.*\\(2 locations\\).*" \
54 "initial condition: set breakpoint"
55
56 gdb_run_cmd
57 gdb_expect {
58 -re "Breakpoint \[0-9\]+,.*foo<int> \\(i=1\\).*$gdb_prompt $" {
59 pass "initial condition: run to breakpoint"
60 }
61 -re "$gdb_prompt $" {
62 fail "initial condition: run to breakpoint"
63 }
64 timeout {
65 fail "initial condition: run to breakpoint (timeout)"
66 }
67 }
68
69 gdb_test "continue" \
70 ".*Breakpoint.*foo<double> \\(i=1\\).*" \
71 "initial condition: run to breakpoint 2"
72
73 # Set breakpoint with multiple locations.
74 # Separately set the condition.
75 gdb_exit
76 gdb_start
77 gdb_reinitialize_dir $srcdir/$subdir
78 gdb_load ${binfile}
79
80 gdb_test "break $srcfile:$bp_location" \
81 "Breakpoint.*at.* file .*$srcfile, line.*\\(2 locations\\).*" \
82 "separate condition: set breakpoint"
83
84 gdb_test "condition 1 i==1" "" \
85 "separate condition: set condition"
86
87 gdb_run_cmd
88 gdb_expect {
89 -re "Breakpoint \[0-9\]+,.*foo<int> \\(i=1\\).*$gdb_prompt $" {
90 pass "separate condition: run to breakpoint"
91 }
92 -re "$gdb_prompt $" {
93 fail "separate condition: run to breakpoint"
94 }
95 timeout {
96 fail "separate condition: run to breakpoint (timeout)"
97 }
98 }
99
100 gdb_test "continue" \
101 ".*Breakpoint.*foo<double> \\(i=1\\).*" \
102 "separate condition: run to breakpoint 2"
103
104 # Try disabling a single location. We also test
105 # that at least in simple cases, the enable/disable
106 # state of locations surive "run".
107 gdb_test "disable 1.1" "" "disabling location: disable"
108
109 gdb_run_cmd
110 gdb_expect {
111 -re "Breakpoint \[0-9\]+,.*foo<double> \\(i=1\\).*$gdb_prompt $" {
112 pass "disabling location: run to breakpoint"
113 }
114 -re "$gdb_prompt $" {
115 fail "disabling location: run to breakpoint"
116 }
117 timeout {
118 fail "disabling location: run to breakpoint (timeout)"
119 }
120 }
121
122 # Try disabling entire breakpoint
123 gdb_test "enable 1.1" "" "disabling location: enable"
124
125
126 gdb_test "disable 1" "" "disable breakpoint: disable"
127
128 gdb_run_cmd
129 gdb_expect {
130 -re "Program exited normally.*$gdb_prompt $" {
131 pass "disable breakpoint: run to breakpoint"
132 }
133 -re "$gdb_prompt $" {
134 fail "disable breakpoint: run to breakpoint"
135 }
136 timeout {
137 fail "disable breakpoint: run to breakpoint (timeout)"
138 }
139 }
140
141 # Make sure breakpoint can be set on a specific instantion.
142 delete_breakpoints
143 gdb_test "break 'void foo<int>(int)'" ".*" \
144 "instantiation: set breakpoint"
145
146
147 gdb_run_cmd
148 gdb_expect {
149 -re ".*Breakpoint \[0-9\]+,.*foo<int> \\(i=0\\).*$gdb_prompt $" {
150 pass "instantiation: run to breakpoint"
151 }
152 -re "$gdb_prompt $" {
153 fail "instantiation: run to breakpoint"
154 }
155 timeout {
156 fail "instantiation: run to breakpoint (timeout)"
157 }
158 }
159
160 gdb_test "continue" \
161 ".*Breakpoint.*foo<int> \\(i=1\\).*" \
162 "instantiation: run to breakpoint 2"
163