1 # Copyright
1997-2019 Free Software Foundation
, Inc.
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.
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.
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
/>.
16 # This test was written by Rich Title.
17 # Purpose is to test conditional breakpoints.
18 # Modeled after
"break.exp".
21 # test running programs
24 standard_testfile
break.c break1.c
26 if {[prepare_for_testing
"failed to prepare" $testfile [list $srcfile $srcfile2] \
27 {debug nowarnings
}]} {
31 if [get_compiler_info
] {
35 clean_restart $
{binfile
}
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_location14
[gdb_get_line_number
"set breakpoint 14 here" $srcfile2]
42 set bp_location15
[gdb_get_line_number
"set breakpoint 15 here" $srcfile2]
43 set bp_location17
[gdb_get_line_number
"set breakpoint 17 here" $srcfile2]
46 # test
break at function
48 gdb_test
"break main" \
49 "Breakpoint.*at.* file .*$srcfile, line.*" \
53 # test conditional
break at function
55 gdb_test
"break marker1 if 1==1" \
56 "Breakpoint.*at.* file .*$srcfile2, line.*"
58 gdb_test_no_output
"delete 2"
61 # test conditional
break at line number
63 gdb_test
"break $srcfile:$bp_location1 if 1==1" \
64 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
66 gdb_test_no_output
"delete 3"
69 # test conditional
break at function
71 gdb_test
"break marker1 if (1==1)" \
72 "Breakpoint.*at.* file .*$srcfile2, line.*"
75 # test conditional
break at line number
77 gdb_test
"break $srcfile:$bp_location1 if (1==1)" \
78 "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\."
80 gdb_test
"break marker2 if (a==43)" \
81 "Breakpoint.*at.* file .*$srcfile2, line.*"
84 # Check
break involving inferior function
call.
85 # Ensure there is at least one additional breakpoint with higher VMA.
87 gdb_test
"break marker3 if (multi_line_if_conditional(1,1,1)==0)" \
88 "Breakpoint.*at.* file .*$srcfile2, line.*"
89 gdb_test
"break marker4" \
90 "Breakpoint.*at.* file .*$srcfile2, line.*"
93 # check to see what breakpoints are
set
95 gdb_test
"info break" \
96 "Num Type\[ \]+Disp Enb Address\[ \]+What.*
97 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in main at .
*$srcfile
:$bp_location6.
*
98 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in marker1 at .
*$srcfile2
:$bp_location15.
*
99 \
[\t \
]+stop only
if \\(1==1\\).
*
100 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in main at .
*$srcfile
:$bp_location1.
*
101 \
[\t \
]+stop only
if \\(1==1\\).
*
102 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in marker2 at .
*$srcfile2
:$bp_location8.
*
103 \
[\t \
]+stop only
if \\(a
==43\\).
*
104 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in marker3 at .
*$srcfile2
:$bp_location17.
*
105 \
[\t \
]+stop only
if \\(multi_line_if_conditional
\\(1,1,1\\)==0\\).
*
106 \
[0-9\
]+\
[\t \
]+breakpoint keep y.
* in marker4 at .
*$srcfile2
:$bp_location14.
*" \
111 # run until the breakpoint at main is hit.
118 # run until the breakpoint at a line number
120 gdb_test
"continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
121 "run until breakpoint set at a line number"
124 # run until the breakpoint at marker1
126 #
If the inferior stops at the first instruction of a source line
, GDB
127 # won
't print the actual PC value; the source line is enough to
128 # exactly specify the PC. But if the inferior is instead stopped in
129 # the midst of a source line, GDB will include the PC in the
130 # breakpoint hit message. This way, GDB always provides the exact
131 # stop location, but avoids clutter when possible.
133 # Suppose you have a function written completely on one source line, like:
134 # int foo (int x) { return 0; }
135 # Setting a breakpoint at `foo' actually places the breakpoint after
138 # GCC's STABS writer always emits a line entry attributing the
139 # prologue instructions to the line containing the function
's open
140 # brace, even if the first user instruction is also on that line.
141 # This means that, in the case of a one-line function, you will get
142 # two line entries in the debug info for the same line: one at the
143 # function's entry point
, and another at the first user instruction.
144 # GDB preserves these duplicated line entries
, and prefers the later
145 # one
; thus
, when the
program stops after the prologue
, at the first
146 # user instruction
, GDB
's search finds the second line entry, decides
147 # that the PC is indeed at the beginning of a source line, and doesn't
148 # print an address in the breakpoint hit message.
150 # GCC
's Dwarf2 writer, on the other hand, squeezes out duplicate line
151 # entries, so GDB considers the source line to begin at the start of
152 # the function's prologue. Thus
, if the
program stops at the
153 # breakpoint
, GDB will decide that the PC is not at the beginning of a
154 # source line
, and will print an address.
156 # I think the Dwarf2 writer
's behavior is arguably correct, but not
157 # helpful. If the user sets a breakpoint at that source line, they
158 # want that breakpoint to fall after the prologue. Identifying the
159 # prologue's code with the opening brace is nice
, but it shouldn
't
160 # take precedence over real code.
162 # Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior.
163 gdb_test_multiple
"continue" "run until breakpoint at marker1" {
164 -re
"Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile2:$bp_location15.*$bp_location15\[\t \]+.*$gdb_prompt $" {
165 pass
"run until breakpoint at marker1"
167 -re
"Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile2:$bp_location15.*$bp_location15\[\t \]+.*$gdb_prompt $" {
168 xfail
"run until breakpoint at marker1"
172 # run until the breakpoint at marker2
173 # Same issues here as above.
174 setup_xfail hppa2.0w
-*-* 11512CLLbs
175 gdb_test_multiple
"continue" "run until breakpoint at marker2" {
176 -re
"Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile2:$bp_location8.*$bp_location8\[\t \]+.*$gdb_prompt $" {
177 pass
"run until breakpoint at marker2"
179 -re
"Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile2:$bp_location8.*$bp_location8\[\t \]+.*$gdb_prompt $" {
180 xfail
"run until breakpoint at marker2"
184 # Test combinations of conditional and thread
-specific breakpoints.
185 gdb_test
"break main if (1==1) thread 999" \
186 "Unknown thread 999\\."
187 gdb_test
"break main thread 999 if (1==1)" \
188 "Unknown thread 999\\."
190 # Verify that both
if and thread can be distinguished from a breakpoint
191 # address expression.
192 gdb_test
"break *main if (1==1) thread 999" \
193 "Unknown thread 999\\."
194 gdb_test
"break *main thread 999 if (1==1)" \
195 "Unknown thread 999\\."
197 # Similarly
for task.
198 gdb_test
"break *main if (1==1) task 999" \
199 "Unknown task 999\\."
200 gdb_test
"break *main task 999 if (1==1)" \
201 "Unknown task 999\\."
203 # GDB accepts abbreviations
for "thread" and "task".
204 gdb_test
"break *main if (1==1) t 999" \
205 "Unknown thread 999\\."
206 gdb_test
"break *main if (1==1) th 999" \
207 "Unknown thread 999\\."
208 gdb_test
"break *main if (1==1) ta 999" \
209 "Unknown task 999\\."
211 set test
"run until breakpoint at marker3"
212 gdb_test_multiple
"continue" $test {
213 -re
"Continuing\\..*Breakpoint \[0-9\]+, marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile2:$bp_location17.*$bp_location17\[\t \]+.*$gdb_prompt $" {
216 -re
"Continuing\\..*Breakpoint \[0-9\]+, $hex in marker3 \\(a=$hex \"stack\", b=$hex \"trace\"\\) at .*$srcfile2:$bp_location17.*$bp_location17\[\t \]+.*$gdb_prompt $" {
221 set test
"run until breakpoint at marker4"
222 gdb_test_multiple
"continue" $test {
223 -re
"Continuing\\..*Breakpoint \[0-9\]+, marker4 \\(d=177601976\\) at .*$srcfile2:$bp_location14.*$bp_location14\[\t \]+.*$gdb_prompt $" {
226 -re
"Continuing\\..*Breakpoint \[0-9\]+, $hex in marker4 \\(d=177601976\\) at .*$srcfile2:$bp_location14.*$bp_location14\[\t \]+.*$gdb_prompt $" {
231 gdb_test
"complete cond 1" "cond 1"
232 gdb_test
"set variable \$var = 1"
233 gdb_test
"complete cond \$v" "cond \\\$var"
234 gdb_test
"complete cond 1 values\[0\].a" "cond 1 values.0..a_field"