]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/condbreak.exp
test suite update - gdb.base/[cd]
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / condbreak.exp
1 # Copyright 1997-2013 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 was written by Rich Title.
17 # Purpose is to test conditional breakpoints.
18 # Modeled after "break.exp".
19
20 #
21 # test running programs
22 #
23
24 standard_testfile break.c break1.c
25
26 if {[prepare_for_testing ${testfile}.exp $testfile [list $srcfile $srcfile2] \
27 {debug nowarnings}]} {
28 return -1
29 }
30
31 if [get_compiler_info] {
32 return -1
33 }
34
35 clean_restart ${binfile}
36
37
38 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
39 set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
40 set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile2]
41 set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile2]
42 set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile2]
43 set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile2]
44 set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile2]
45 set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile2]
46 set bp_location17 [gdb_get_line_number "set breakpoint 17 here" $srcfile2]
47 set bp_location18 [gdb_get_line_number "set breakpoint 18 here" $srcfile2]
48
49 #
50 # test break at function
51 #
52 gdb_test "break main" \
53 "Breakpoint.*at.* file .*$srcfile, line.*" \
54 "breakpoint function"
55
56 #
57 # test conditional break at function
58 #
59 gdb_test "break marker1 if 1==1" \
60 "Breakpoint.*at.* file .*$srcfile2, line.*"
61
62 gdb_test_no_output "delete 2"
63
64 #
65 # test conditional break at line number
66 #
67 gdb_test "break $srcfile:$bp_location1 if 1==1" \
68 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
69
70 gdb_test_no_output "delete 3"
71
72 #
73 # test conditional break at function
74 #
75 gdb_test "break marker1 if (1==1)" \
76 "Breakpoint.*at.* file .*$srcfile2, line.*"
77
78 #
79 # test conditional break at line number
80 #
81 gdb_test "break $srcfile:$bp_location1 if (1==1)" \
82 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
83
84 gdb_test "break marker2 if (a==43)" \
85 "Breakpoint.*at.* file .*$srcfile2, line.*"
86
87 #
88 # Check break involving inferior function call.
89 # Ensure there is at least one additional breakpoint with higher VMA.
90 #
91 gdb_test "break marker3 if (multi_line_if_conditional(1,1,1)==0)" \
92 "Breakpoint.*at.* file .*$srcfile2, line.*"
93 gdb_test "break marker4" \
94 "Breakpoint.*at.* file .*$srcfile2, line.*"
95
96 #
97 # check to see what breakpoints are set
98 #
99
100 if {$hp_aCC_compiler} {
101 set marker1_proto "\\(void\\)"
102 set marker2_proto "\\(int\\)"
103 # Not checked.
104 set marker3_proto "\\(char \\*, char \\*\\)"
105 set marker4_proto "\\(long\\)"
106 } else {
107 set marker1_proto ""
108 set marker2_proto ""
109 set marker3_proto ""
110 set marker4_proto ""
111 }
112
113 gdb_test "info break" \
114 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
115 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location6.*
116 \[0-9\]+\[\t \]+breakpoint keep y.* in marker1$marker1_proto at .*$srcfile2:($bp_location15|$bp_location16).*
117 \[\t \]+stop only if \\(1==1\\).*
118 \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
119 \[\t \]+stop only if \\(1==1\\).*
120 \[0-9\]+\[\t \]+breakpoint keep y.* in marker2$marker2_proto at .*$srcfile2:($bp_location8|$bp_location9).*
121 \[\t \]+stop only if \\(a==43\\).*
122 \[0-9\]+\[\t \]+breakpoint keep y.* in marker3$marker3_proto at .*$srcfile2:($bp_location17|$bp_location18).*
123 \[\t \]+stop only if \\(multi_line_if_conditional\\(1,1,1\\)==0\\).*
124 \[0-9\]+\[\t \]+breakpoint keep y.* in marker4$marker4_proto at .*$srcfile2:($bp_location13|$bp_location14).*" \
125 "breakpoint info"
126
127
128 #
129 # run until the breakpoint at main is hit.
130 #
131
132
133 rerun_to_main
134
135 #
136 # run until the breakpoint at a line number
137 #
138 gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
139 "run until breakpoint set at a line number"
140
141 #
142 # run until the breakpoint at marker1
143 #
144 # If the inferior stops at the first instruction of a source line, GDB
145 # won't print the actual PC value; the source line is enough to
146 # exactly specify the PC. But if the inferior is instead stopped in
147 # the midst of a source line, GDB will include the PC in the
148 # breakpoint hit message. This way, GDB always provides the exact
149 # stop location, but avoids clutter when possible.
150 #
151 # Suppose you have a function written completely on one source line, like:
152 # int foo (int x) { return 0; }
153 # Setting a breakpoint at `foo' actually places the breakpoint after
154 # foo's prologue.
155 #
156 # GCC's STABS writer always emits a line entry attributing the
157 # prologue instructions to the line containing the function's open
158 # brace, even if the first user instruction is also on that line.
159 # This means that, in the case of a one-line function, you will get
160 # two line entries in the debug info for the same line: one at the
161 # function's entry point, and another at the first user instruction.
162 # GDB preserves these duplicated line entries, and prefers the later
163 # one; thus, when the program stops after the prologue, at the first
164 # user instruction, GDB's search finds the second line entry, decides
165 # that the PC is indeed at the beginning of a source line, and doesn't
166 # print an address in the breakpoint hit message.
167 #
168 # GCC's Dwarf2 writer, on the other hand, squeezes out duplicate line
169 # entries, so GDB considers the source line to begin at the start of
170 # the function's prologue. Thus, if the program stops at the
171 # breakpoint, GDB will decide that the PC is not at the beginning of a
172 # source line, and will print an address.
173 #
174 # I think the Dwarf2 writer's behavior is arguably correct, but not
175 # helpful. If the user sets a breakpoint at that source line, they
176 # want that breakpoint to fall after the prologue. Identifying the
177 # prologue's code with the opening brace is nice, but it shouldn't
178 # take precedence over real code.
179 #
180 # Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior.
181 gdb_test_multiple "continue" "run until breakpoint at marker1" {
182 -re "Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile2:($bp_location15|$bp_location16).*($bp_location15|$bp_location16)\[\t \]+.*$gdb_prompt $" {
183 pass "run until breakpoint at marker1"
184 }
185 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile2:($bp_location15|$bp_location16).*($bp_location15|$bp_location16)\[\t \]+.*$gdb_prompt $" {
186 xfail "run until breakpoint at marker1"
187 }
188 }
189
190 # run until the breakpoint at marker2
191 # Same issues here as above.
192 setup_xfail hppa2.0w-*-* 11512CLLbs
193 gdb_test_multiple "continue" "run until breakpoint at marker2" {
194 -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile2:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*$gdb_prompt $" {
195 pass "run until breakpoint at marker2"
196 }
197 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile2:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*$gdb_prompt $" {
198 xfail "run until breakpoint at marker2"
199 }
200 }
201
202 # Test combinations of conditional and thread-specific breakpoints.
203 gdb_test "break main if (1==1) thread 999" \
204 "Unknown thread 999\\."
205 gdb_test "break main thread 999 if (1==1)" \
206 "Unknown thread 999\\."
207
208 # Verify that both if and thread can be distinguished from a breakpoint
209 # address expression.
210 gdb_test "break *main if (1==1) thread 999" \
211 "Unknown thread 999\\."
212 gdb_test "break *main thread 999 if (1==1)" \
213 "Unknown thread 999\\."
214
215 # Similarly for task.
216 gdb_test "break *main if (1==1) task 999" \
217 "Unknown task 999\\."
218 gdb_test "break *main task 999 if (1==1)" \
219 "Unknown task 999\\."
220
221 # GDB accepts abbreviations for "thread" and "task".
222 gdb_test "break *main if (1==1) t 999" \
223 "Unknown thread 999\\."
224 gdb_test "break *main if (1==1) th 999" \
225 "Unknown thread 999\\."
226 gdb_test "break *main if (1==1) ta 999" \
227 "Unknown task 999\\."
228
229 set test "run until breakpoint at marker3"
230 gdb_test_multiple "continue" $test {
231 -re "Continuing\\..*Breakpoint \[0-9\]+, marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile2:($bp_location17|$bp_location18).*($bp_location17|$bp_location18)\[\t \]+.*$gdb_prompt $" {
232 pass $test
233 }
234 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile2:($bp_location17|$bp_location18).*($bp_location17|$bp_location18)\[\t \]+.*$gdb_prompt $" {
235 xfail $test
236 }
237 }
238
239 set test "run until breakpoint at marker4"
240 gdb_test_multiple "continue" $test {
241 -re "Continuing\\..*Breakpoint \[0-9\]+, marker4 \\(d=177601976\\) at .*$srcfile2:($bp_location13|$bp_location14).*($bp_location13|$bp_location14)\[\t \]+.*$gdb_prompt $" {
242 pass $test
243 }
244 -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker4 \\(d=177601976\\) at .*$srcfile2:($bp_location13|$bp_location14).*($bp_location13|$bp_location14)\[\t \]+.*$gdb_prompt $" {
245 xfail $test
246 }
247 }
248
249 gdb_test "complete cond 1" "cond 1"
250 gdb_test "set variable \$var = 1"
251 gdb_test "complete cond \$v" "cond \\\$var"
252 gdb_test "complete cond 1 values\[0\].a" "cond 1 values.0..a_field"