OSDN Git Service

2012-01-16 Pedro Alves <palves@redhat.com>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.cp / mb-templates.exp
1 # Copyright 2007-2012 Free Software Foundation, Inc.
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
16 # This test verifies that setting breakpoint on line in template
17 # function will fire in all instantiations of that template.
18
19 if { [skip_stl_tests] } { continue }
20
21 # On SPU this test fails because the executable exceeds local storage size.
22 if { [istarget "spu*-*-*"] } {
23         return 0
24 }
25
26
27 set testfile "mb-templates"
28 set srcfile ${testfile}.cc
29 set binfile ${objdir}/${subdir}/${testfile}
30
31 if [get_compiler_info ${binfile} "c++"] {
32     return -1
33 }
34
35 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
36      untested mb-templates.exp
37      return -1
38 }
39
40 gdb_exit
41 gdb_start
42 gdb_reinitialize_dir $srcdir/$subdir
43 gdb_load ${binfile}
44
45 set bp_location [gdb_get_line_number "set breakpoint here"]
46
47 # Set a breakpoint with multiple locations
48 # and a condition.
49
50 gdb_test "break $srcfile:$bp_location if i==1" \
51     "Breakpoint.*at.*: $srcfile:$bp_location. \\(2 locations\\).*" \
52     "initial condition: set breakpoint"
53
54 gdb_run_cmd
55 gdb_expect {
56     -re "Breakpoint \[0-9\]+,.*foo<int> \\(i=1\\).*$gdb_prompt $" {
57         pass "initial condition: run to breakpoint"
58     }
59     -re "$gdb_prompt $" {
60         fail "initial condition: run to breakpoint"
61     }
62     timeout {
63         fail "initial condition: run to breakpoint (timeout)"
64     }
65 }
66
67 gdb_test "continue" \
68     ".*Breakpoint.*foo<double> \\(i=1\\).*" \
69     "initial condition: run to breakpoint 2"
70
71 # Set breakpoint with multiple locations.
72 # Separately set the condition.
73 gdb_exit
74 gdb_start
75 gdb_reinitialize_dir $srcdir/$subdir
76 gdb_load ${binfile}
77
78 gdb_test "break $srcfile:$bp_location" \
79     "Breakpoint.*at.*: $srcfile:$bp_location. \\(2 locations\\).*" \
80     "separate condition: set breakpoint"
81
82 gdb_test_no_output "condition 1 i==1" \
83     "separate condition: set condition"
84     
85 gdb_run_cmd
86 gdb_expect {
87     -re "Breakpoint \[0-9\]+,.*foo<int> \\(i=1\\).*$gdb_prompt $" {
88         pass "separate condition: run to breakpoint"
89     }
90     -re "$gdb_prompt $" {
91         fail "separate condition: run to breakpoint"
92     }
93     timeout {
94         fail "separate condition: run to breakpoint (timeout)"
95     }
96 }
97
98 gdb_test "continue" \
99     ".*Breakpoint.*foo<double> \\(i=1\\).*" \
100     "separate condition: run to breakpoint 2"
101
102 # Try disabling a single location. We also test
103 # that at least in simple cases, the enable/disable
104 # state of locations surive "run".
105 gdb_test_no_output "disable 1.1" "disabling location: disable"
106
107 gdb_run_cmd
108 gdb_expect {
109     -re "Breakpoint \[0-9\]+,.*foo<double> \\(i=1\\).*$gdb_prompt $" {
110         pass "disabling location: run to breakpoint"
111     }
112     -re "$gdb_prompt $" {
113         fail "disabling location: run to breakpoint"
114     }
115     timeout {
116         fail "disabling location: run to breakpoint (timeout)"
117     }
118 }
119
120 # Try disabling entire breakpoint
121 gdb_test_no_output "enable 1.1" "disabling location: enable"
122
123
124 gdb_test_no_output "disable 1" "disable breakpoint: disable"
125
126 gdb_run_cmd
127 gdb_expect {
128     -re "$inferior_exited_re normally.*$gdb_prompt $" {
129         pass "disable breakpoint: run to breakpoint"
130     }
131     -re "$gdb_prompt $" {
132         fail "disable breakpoint: run to breakpoint"
133     }
134     timeout {
135         fail "disable breakpoint: run to breakpoint (timeout)"
136     }
137 }
138
139 # Make sure breakpoint can be set on a specific instantion.
140 delete_breakpoints
141 gdb_test "break 'void foo<int>(int)'" ".*" \
142     "instantiation: set breakpoint"
143
144
145 gdb_run_cmd
146 gdb_expect {
147     -re ".*Breakpoint \[0-9\]+,.*foo<int> \\(i=0\\).*$gdb_prompt $" {
148         pass "instantiation: run to breakpoint"
149     }
150     -re "$gdb_prompt $" {
151         fail "instantiation: run to breakpoint"
152     }
153     timeout {
154         fail "instantiation: run to breakpoint (timeout)"
155     }
156 }
157
158 gdb_test "continue" \
159     ".*Breakpoint.*foo<int> \\(i=1\\).*" \
160     "instantiation: run to breakpoint 2"
161
162
163 # Make sure we can set a breakpoint on a source statement that spans
164 # multiple lines.
165
166 delete_breakpoints
167
168 set bp_location [gdb_get_line_number "set multi-line breakpoint here"]
169
170 if { ![runto_main] } {
171     fail "Can't run to main for multi_line_foo tests."
172     return 0
173 }
174
175 gdb_test "break $srcfile:$bp_location" \
176     "Breakpoint.*at.*: $srcfile:$bp_location. \\(2 locations\\).*" \
177     "set multi_line_foo breakpoint"
178 gdb_test "continue" \
179     ".*Breakpoint.*multi_line_foo<int> \\(i=0\\).*" \
180     "run to multi_line_foo breakpoint 2 <int>"
181 gdb_test "continue" \
182     ".*Breakpoint.*multi_line_foo<double> \\(i=0\\).*" \
183     "run to multi_line_foo breakpoint 2 <double>"