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