OSDN Git Service

82abc0a1ddeff4ada490db95b81f401aa3b2eae7
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.base / annota3.exp
1 # Copyright 2003-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 file was written by Elena Zannoni (ezannoni@cygnus.com)
17
18
19 # are we on a target board? If so, don't run these tests.
20 # note: this is necessary because we cannot use runto_main (which would
21 # work for remote targets too) because of the different prompt we get
22 # when using annotation level 2.
23 #
24 if [is_remote target] then {
25     return 0
26 }
27
28
29 #
30 # test running programs
31 #
32
33 set testfile "annota3"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
36
37 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
38     untested annota3.exp
39     return -1
40 }
41
42
43 gdb_exit
44 gdb_start
45 gdb_reinitialize_dir $srcdir/$subdir
46 gdb_load ${binfile}
47
48 #
49 # the line at which break main will put the breakpoint
50 #
51 set main_line 32
52
53 # The commands we test here produce many lines of output; disable "press 
54 # <return> to continue" prompts.
55 gdb_test_no_output "set height 0"
56
57 #
58 # break at main
59 #
60 gdb_test "break main" \
61     "Breakpoint.*at.* file .*$srcfile, line.*" \
62     "breakpoint main"
63
64
65 # NOTE: this prompt is OK only when the annotation level is > 1
66
67 # NOTE: When this prompt is in use the gdb_test procedure cannot be
68 # used because it assumes that the last char after the gdb_prompt is a
69 # white space. This is not true with this annotated prompt. So we must
70 # use send_gdb and gdb_expect or gdb_expect_list.
71
72 set old_gdb_prompt $gdb_prompt
73 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
74
75
76
77 #
78 # set the annotation level to 3
79 #
80 # of course, this will test:
81 # annotate-pre-prompt
82 # annotate-prompt
83 # annotate-post-prompt (in the next block)
84 #
85 send_gdb "set annotate 3\n" 
86 gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
87     "set annotate 3"
88 }
89
90 #
91 # if construct:
92 #
93 gdb_test_multiple "if 1" "start if construct" {
94     -re "^if 1\r\n\r\n\032\032post-prompt\r\n\r\n\032\032pre-commands\r\n >\r\n\032\032commands\r\n$" {
95         pass "start if construct"
96     }
97 }
98
99 gdb_test_multiple "end" "end if construct" {
100     -re "^end\r\n\r\n\032\032post-commands\r\n$gdb_prompt$" {
101         pass "end if construct"
102     }
103 }
104
105 #
106 # info break:
107 #
108 send_gdb "info break\n" 
109 gdb_expect_list "breakpoint info" "$gdb_prompt$" {
110     "\r\n\032\032post-prompt\r\n"
111     "Num     Type           Disp Enb Address    +What\r\n"
112     "1       breakpoint     keep y   0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:32\r\n"
113 }
114
115
116 #
117 # run to a break point will test:
118 #
119 #exp_internal 1
120 send_gdb "run\n"
121 gdb_expect_list "run until main breakpoint" "$gdb_prompt$" {
122     "\r\n\032\032post-prompt\r\n"
123     "Starting program: .*annota3(|\.exe) \r\n"
124     "\r\n\032\032starting\r\n"
125     "\r\n\032\032breakpoint 1\r\n"
126     "\r\n"
127     "Breakpoint 1, "
128     "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
129     "main \\(\\) at .*annota3.c:32\r\n"
130     "\r\n\032\032source.*annota3.c:32:.*:beg:0x\[0-9a-z\]+\r\n"
131     "\r\n\032\032stopped\r\n"
132 }
133 #exp_internal 0
134 #exit 0
135
136 #
137 # Let's do a next, to get to a point where the array is initialized
138 # We don't care about the annotated output for this operation, it is the same as
139 # the one produced by run above
140 #
141 send_gdb "next\n" 
142 gdb_expect_list "go after array init line" "$gdb_prompt$" {
143     "\r\n\032\032post-prompt\r\n"
144     "\r\n\032\032starting\r\n"
145     "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
146     "\r\n\032\032stopped\r\n"
147 }
148
149
150 #
151 # printing the array:
152 #
153 send_gdb "print my_array\n"
154 gdb_expect_list "print array" "$gdb_prompt$" {
155     "\r\n\032\032post-prompt\r\n"
156     ".*= .1, 2, 3.\r\n"
157 }
158
159
160 #
161 # this should generate an error message, so to test:
162 # annotate-error-begin
163 # FIXME: annotate-error not tested
164 #
165
166 #exp_internal 1
167 send_gdb "print non_existent_value\n"
168 gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
169     "\r\n\032\032post-prompt\r\n"
170     "\r\n\032\032error-begin\r\n"
171     "No symbol \"non_existent_value\" in current context.\r\n"
172     "\r\n\032\032error\r\n"
173 }
174
175
176 #
177 # break at signal handler
178 #
179 send_gdb "break handle_USR1\n"
180 gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
181     "\r\n\032\032post-prompt\r\n"
182     "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
183 }
184
185 #
186 # break at printf. When we are stopped at printf, we can test 
187 #
188 send_gdb "break printf\n"
189 gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
190     "\r\n\032\032post-prompt\r\n"
191     "Breakpoint.*at 0x\[0-9a-z\]+.*"
192 }
193
194 #
195 # get to printf
196 #
197 send_gdb "continue\n"
198 gdb_expect_list "continue to printf" "$gdb_prompt$" {
199     "\r\n\032\032post-prompt\r\n"
200     "Continuing.\r\n"
201     "\r\n\032\032starting\r\n"
202     "\r\n\032\032breakpoint 3\r\n"
203     "\r\n"
204     "Breakpoint 3, \[^\r\n\]*\r\n"
205     "\r\n\032\032stopped\r\n"
206 }
207
208 send_gdb "backtrace\n"
209 gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
210     "\r\n\032\032post-prompt\r\n"
211     "#0 .* .*printf(@\[^ ]*)? \[^\r\n\]*\r\n"
212     "#1 .* main \[^\r\n\]*\r\n"
213 }
214
215
216 #
217 # test printing a frame with some arguments: 
218 #
219
220 if [target_info exists gdb,nosignals] {
221     unsupported "send SIGUSR1"
222     unsupported "backtrace @ signal handler"
223 } else {
224     send_gdb "signal SIGUSR1\n"
225     gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
226         "\r\n\032\032post-prompt\r\n"
227         "Continuing with signal SIGUSR1.\r\n"
228         "\r\n\032\032starting\r\n"
229         "\r\n\032\032breakpoint 2\r\n"
230         "\r\n"
231         "Breakpoint 2, "
232         "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
233         "handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
234         "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
235         "\r\n\032\032stopped\r\n"
236     }
237
238     #
239     # test:
240     #
241     send_gdb "backtrace\n"
242     gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
243         "#0 +handle_USR1 \[^\r\n\]+\r\n"
244         "#1 +.signal handler called.\r\n"
245         "#2 .* .*printf(@\[^ \]*)? \[^\r\n\]+\r\n"
246         "#3 .* main \[^\r\n\]+\r\n"
247     }
248 }
249
250 #
251 # delete all the breakpoints
252 #
253 send_gdb "delete 1\n"
254 gdb_expect_list "delete bp 1" "$gdb_prompt$" {
255     "\r\n\032\032post-prompt\r\n"
256 }
257
258 send_gdb "delete 2\n"
259 gdb_expect_list "delete bp 2" "$gdb_prompt$" {
260     "\r\n\032\032post-prompt\r\n"
261 }
262
263 send_gdb "delete 3\n"
264 gdb_expect_list "delete bp 3" "$gdb_prompt$" {
265     "\r\n\032\032post-prompt\r\n"
266 }
267
268 #
269 # break at main, after value is initialized. This is in preparation
270 # to test the annotate output for the display command.
271 #
272 send_gdb "break main\n"
273 gdb_expect_list "break at 28" "$gdb_prompt$" {
274     "\r\n\032\032post-prompt\r\n"
275     "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line 32.\r\n"
276 }
277
278 #
279 # display the value
280 #
281 send_gdb "display value\n"
282 gdb_expect_list "set up display" "$gdb_prompt$" {
283     "\r\n\032\032post-prompt\r\n"
284     "1: value = 7\r\n"
285 }
286
287
288 # should ask query. Test annotate-query.
289 # we don't care about anything else here, only the query.
290
291 send_gdb "run\n"
292 gdb_expect {
293   -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
294          send_gdb "y\n"
295          gdb_expect {
296              -re ".*post-query.*$gdb_prompt$" \
297                      { pass "re-run" }
298              -re ".*$gdb_prompt$"  { fail "re-run" }
299              timeout { fail "re-run (timeout)" }
300          }
301      }
302   -re ".*$gdb_prompt$"  { fail "re-run" }
303   timeout { fail "re-run (timeout)" }
304 }
305
306 #
307 # Test that breakpoints-invalid is issued once and only once for
308 # breakpoint ignore count changes, after annotation stopped.
309 # NOTE: breakpoints-invalid annotations have been removed from
310 # level 3 but keep these tests for continuity and comparison
311 # with annota1.exp.
312 send_gdb "break 46\n"
313 gdb_expect_list  "break at 46" "$gdb_prompt$" {
314     "\r\n\032\032post-prompt\r\n"
315     "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line 46.\r\n"
316 }
317
318 send_gdb "ignore 5 4\n"
319 gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
320     "\r\n\032\032post-prompt\r\n"
321     "Will ignore next 4 crossings of breakpoint 5"
322     "\r\n"
323 }
324
325 send_gdb "continue\n"
326 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" {
327     "\r\n\032\032post-prompt\r\n"
328     "\r\n\032\032breakpoint 5\r\n"
329     "\r\n"
330     "Breakpoint 5, "
331     "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n"
332     "main \\(\\) at .*annota3.c:46\r\n"
333     "\r\n\032\032source .*annota3.c:46:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
334     "1: value = 11\r\n"
335     "\r\n\032\032stopped\r\n"
336 }
337
338 # check that ignore command is working, or the above can provide
339 # misleading assurance ...
340
341 send_gdb "next\n"
342 gdb_expect_list "next to exit loop" "$gdb_prompt$"  {
343     "\r\n\032\032post-prompt\r\n"
344     "\r\n\032\032starting\r\n"
345     "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
346     "1: value = 12\r\n"
347     "\r\n\032\032stopped\r\n"
348 }
349
350 send_gdb "next\n"
351 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" {
352     "\r\n\032\032post-prompt\r\n"
353     "\r\n\032\032starting\r\n"
354     "\r\n\032\032source.*annota3.c:49:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
355     "1: value = 12\r\n"
356     "\r\n\032\032stopped\r\n"
357 }
358
359 # Get the inferior's PID for later.
360
361 set test "get inferior pid"
362 set pid -1
363 gdb_test_multiple "info inferior 1" "$test" {
364     -re "process (\[0-9\]*).*$gdb_prompt$" {
365         set pid $expect_out(1,string)
366         pass "$test"
367     }
368 }
369
370 #
371 # Send a signal that is not handled
372 #
373 # SIGTRAP signals are dropped before they get to the inferior process
374 # on hpux11.  In theory, this behaivor can be controlled by setting
375 # TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
376 # the signal to be properly delivered.
377 #
378 # It has been verified that other signals will be delivered.  However,
379 # rather than twiddle the test, I choose to leave it as-is as it
380 # exposes an interesting failure on hpux11.
381
382 if [target_info exists gdb,nosignals] {
383     unsupported "signal sent"
384 } else {
385     setup_xfail hppa*-*-hpux11*
386     send_gdb "signal SIGTRAP\n"
387     gdb_expect_list "signal sent" "$gdb_prompt$" {
388         "\r\n\032\032post-prompt\r\n"
389         "Continuing with signal SIGTRAP.\r\n"
390         "\r\n\032\032starting\r\n"
391         "\r\n\032\032signalled\r\n"
392         "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
393         "The program no longer exists.\r\n"
394         "\r\n\032\032stopped\r\n"
395     }
396 }
397
398
399 # Check for production of a core file and remove it!
400
401 set test "cleanup core file"
402 if { [remote_file host exists core] } {
403     remote_file host delete core
404     pass "$test (removed)"
405 } elseif { $pid != -1 && [remote_file host exists core.$pid] } {
406     remote_file host delete core.$pid
407     pass "$test (removed)"
408 } else {
409     pass "$test (not dumped)"
410 }
411
412 # restore the original prompt for the rest of the testsuite
413
414 set gdb_prompt $old_gdb_prompt