Commit | Line | Data |
---|---|---|
6aba47ca DJ |
1 | # Copyright 1997, 1998, 1999, 2000, 2001, 2003, 2007 |
2 | # Free Software Foundation, Inc. | |
c906108c SS |
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 | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
c906108c SS |
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. | |
e22f8b7c | 13 | # |
c906108c | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c SS |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This test was written by Rich Title. | |
21 | # Purpose is to test conditional breakpoints. | |
22 | # Modeled after "break.exp". | |
23 | ||
c906108c SS |
24 | if $tracelevel then { |
25 | strace $tracelevel | |
26 | } | |
27 | ||
28 | global usestubs | |
29 | ||
30 | # | |
31 | # test running programs | |
32 | # | |
33 | set prms_id 0 | |
34 | set bug_id 0 | |
35 | ||
c2c6d25f | 36 | set testfile "break" |
c906108c | 37 | set srcfile ${testfile}.c |
a1dea79a | 38 | set srcfile1 ${testfile}1.c |
c906108c SS |
39 | set binfile ${objdir}/${subdir}/${testfile} |
40 | ||
fc91c6c2 | 41 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } { |
b60f0898 JB |
42 | untested condbreak.exp |
43 | return -1 | |
a1dea79a FF |
44 | } |
45 | ||
fc91c6c2 | 46 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } { |
b60f0898 JB |
47 | untested condbreak.exp |
48 | return -1 | |
a1dea79a FF |
49 | } |
50 | ||
fc91c6c2 | 51 | if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } { |
b60f0898 JB |
52 | untested condbreak.exp |
53 | return -1 | |
c906108c SS |
54 | } |
55 | ||
085dd6e6 JM |
56 | if [get_compiler_info ${binfile}] { |
57 | return -1; | |
58 | } | |
59 | ||
c906108c SS |
60 | gdb_exit |
61 | gdb_start | |
62 | gdb_reinitialize_dir $srcdir/$subdir | |
63 | gdb_load ${binfile} | |
64 | ||
65 | ||
66 | if [target_info exists gdb_stub] { | |
67 | gdb_step_for_stub; | |
68 | } | |
69 | ||
a1dea79a FF |
70 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] |
71 | set bp_location6 [gdb_get_line_number "set breakpoint 6 here"] | |
72 | set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1] | |
73 | set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1] | |
74 | set bp_location15 [gdb_get_line_number "set breakpoint 15 here" $srcfile1] | |
75 | set bp_location16 [gdb_get_line_number "set breakpoint 16 here" $srcfile1] | |
76 | ||
c906108c SS |
77 | # |
78 | # test break at function | |
79 | # | |
80 | gdb_test "break main" \ | |
81 | "Breakpoint.*at.* file .*$srcfile, line.*" \ | |
82 | "breakpoint function" | |
83 | ||
84 | # | |
85 | # test conditional break at function | |
86 | # | |
87 | gdb_test "break marker1 if 1==1" \ | |
a1dea79a | 88 | "Breakpoint.*at.* file .*$srcfile1, line.*" |
c906108c | 89 | |
7dbd117d | 90 | gdb_test "delete 2" "" |
c906108c SS |
91 | |
92 | # | |
93 | # test conditional break at line number | |
94 | # | |
a1dea79a FF |
95 | gdb_test "break $srcfile:$bp_location1 if 1==1" \ |
96 | "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." | |
c906108c | 97 | |
7dbd117d | 98 | gdb_test "delete 3" "" |
c906108c SS |
99 | |
100 | # | |
101 | # test conditional break at function | |
102 | # | |
103 | gdb_test "break marker1 if (1==1)" \ | |
a1dea79a | 104 | "Breakpoint.*at.* file .*$srcfile1, line.*" |
c906108c SS |
105 | |
106 | # | |
107 | # test conditional break at line number | |
108 | # | |
a1dea79a FF |
109 | gdb_test "break $srcfile:$bp_location1 if (1==1)" \ |
110 | "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." | |
c906108c SS |
111 | |
112 | gdb_test "break marker2 if (a==43)" \ | |
a1dea79a | 113 | "Breakpoint.*at.* file .*$srcfile1, line.*" |
c906108c SS |
114 | |
115 | # | |
116 | # check to see what breakpoints are set | |
117 | # | |
118 | ||
085dd6e6 JM |
119 | if {$hp_aCC_compiler} { |
120 | set marker1_proto "\\(void\\)" | |
121 | set marker2_proto "\\(int\\)" | |
122 | } else { | |
123 | set marker1_proto "" | |
124 | set marker2_proto "" | |
125 | } | |
126 | ||
c906108c SS |
127 | gdb_test "info break" \ |
128 | "Num Type\[ \]+Disp Enb Address\[ \]+What.* | |
a1dea79a FF |
129 | \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location6.* |
130 | \[0-9\]+\[\t \]+breakpoint keep y.* in marker1$marker1_proto at .*$srcfile1:($bp_location15|$bp_location16).* | |
c906108c | 131 | \[\t \]+stop only if 1 == 1.* |
a1dea79a | 132 | \[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.* |
c906108c | 133 | \[\t \]+stop only if 1 == 1.* |
a1dea79a | 134 | \[0-9\]+\[\t \]+breakpoint keep y.* in marker2$marker2_proto at .*$srcfile1:($bp_location8|$bp_location9).* |
c906108c SS |
135 | \[\t \]+stop only if a == 43.*" \ |
136 | "breakpoint info" | |
137 | ||
138 | ||
139 | # | |
7a292a7a | 140 | # run until the breakpoint at main is hit. |
c906108c | 141 | # |
7a292a7a SS |
142 | |
143 | ||
cce74817 | 144 | rerun_to_main |
c906108c SS |
145 | |
146 | # | |
147 | # run until the breakpoint at a line number | |
148 | # | |
a1dea79a | 149 | gdb_test "continue" "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \ |
c906108c SS |
150 | "run until breakpoint set at a line number" |
151 | ||
152 | # | |
153 | # run until the breakpoint at marker1 | |
154 | # | |
11cf8741 JM |
155 | # If the inferior stops at the first instruction of a source line, GDB |
156 | # won't print the actual PC value; the source line is enough to | |
157 | # exactly specify the PC. But if the inferior is instead stopped in | |
158 | # the midst of a source line, GDB will include the PC in the | |
159 | # breakpoint hit message. This way, GDB always provides the exact | |
160 | # stop location, but avoids clutter when possible. | |
161 | # | |
162 | # Suppose you have a function written completely on one source line, like: | |
163 | # int foo (int x) { return 0; } | |
164 | # Setting a breakpoint at `foo' actually places the breakpoint after | |
165 | # foo's prologue. | |
166 | # | |
167 | # GCC's STABS writer always emits a line entry attributing the | |
168 | # prologue instructions to the line containing the function's open | |
169 | # brace, even if the first user instruction is also on that line. | |
170 | # This means that, in the case of a one-line function, you will get | |
171 | # two line entries in the debug info for the same line: one at the | |
172 | # function's entry point, and another at the first user instruction. | |
173 | # GDB preserves these duplicated line entries, and prefers the later | |
174 | # one; thus, when the program stops after the prologue, at the first | |
175 | # user instruction, GDB's search finds the second line entry, decides | |
176 | # that the PC is indeed at the beginning of a source line, and doesn't | |
177 | # print an address in the breakpoint hit message. | |
178 | # | |
179 | # GCC's Dwarf2 writer, on the other hand, squeezes out duplicate line | |
180 | # entries, so GDB considers the source line to begin at the start of | |
181 | # the function's prologue. Thus, if the program stops at the | |
182 | # breakpoint, GDB will decide that the PC is not at the beginning of a | |
183 | # source line, and will print an address. | |
184 | # | |
185 | # I think the Dwarf2 writer's behavior is arguably correct, but not | |
186 | # helpful. If the user sets a breakpoint at that source line, they | |
187 | # want that breakpoint to fall after the prologue. Identifying the | |
188 | # prologue's code with the opening brace is nice, but it shouldn't | |
189 | # take precedence over real code. | |
190 | # | |
191 | # Until the Dwarf2 writer gets fixed, I'm going to XFAIL its behavior. | |
192 | send_gdb "continue\n" | |
193 | gdb_expect { | |
a1dea79a | 194 | -re "Continuing\\..*Breakpoint \[0-9\]+, marker1 \\(\\) at .*$srcfile1:($bp_location15|$bp_location16).*($bp_location15|$bp_location16)\[\t \]+.*$gdb_prompt $" { |
11cf8741 JM |
195 | pass "run until breakpoint at marker1" |
196 | } | |
a1dea79a | 197 | -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker1 \\(\\) at .*$srcfile1:($bp_location15|$bp_location16).*($bp_location15|$bp_location16)\[\t \]+.*$gdb_prompt $" { |
11cf8741 JM |
198 | xfail "run until breakpoint at marker1" |
199 | } | |
200 | -re "$gdb_prompt $" { | |
201 | fail "run until breakpoint at marker1" | |
202 | } | |
203 | timeout { | |
204 | fail "(timeout) run until breakpoint at marker1" | |
205 | } | |
206 | } | |
c906108c | 207 | |
c906108c | 208 | # run until the breakpoint at marker2 |
dfcd3bfb | 209 | # Same issues here as above. |
a0b3c4fd | 210 | setup_xfail hppa2.0w-*-* 11512CLLbs |
dfcd3bfb JM |
211 | send_gdb "continue\n" |
212 | gdb_expect { | |
a1dea79a | 213 | -re "Continuing\\..*Breakpoint \[0-9\]+, marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*" { |
dfcd3bfb JM |
214 | pass "run until breakpoint at marker2" |
215 | } | |
a1dea79a | 216 | -re "Continuing\\..*Breakpoint \[0-9\]+, $hex in marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*($bp_location8|$bp_location9)\[\t \]+.*" { |
dfcd3bfb JM |
217 | xfail "run until breakpoint at marker2" |
218 | } | |
219 | -re "$gdb_prompt $" { | |
220 | fail "run until breakpoint at marker2" | |
221 | } | |
222 | timeout { | |
223 | fail "(timeout) run until breakpoint at marker2" | |
224 | } | |
225 | } |