2003-08-02 Andrew Cagney <cagney@redhat.com>
[external/binutils.git] / gdb / testsuite / gdb.base / annota3.exp
1 # Copyright 2003 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
21
22 if $tracelevel then {
23     strace $tracelevel
24 }
25
26
27 # are we on a target board? If so, don't run these tests.
28 # note: this is necessary because we cannot use runto_main (which would
29 # work for remote targets too) because of the different prompt we get
30 # when using annotation level 2.
31 #
32 if [is_remote target] then {
33     return 0
34 }
35
36
37 #
38 # test running programs
39 #
40 set prms_id 0
41 set bug_id 0
42
43 set testfile "annota3"
44 set srcfile ${testfile}.c
45 set binfile ${objdir}/${subdir}/${testfile}
46
47 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
48     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
49 }
50
51
52 gdb_exit
53 gdb_start
54 gdb_reinitialize_dir $srcdir/$subdir
55 gdb_load ${binfile}
56
57 if [target_info exists gdb_stub] {
58     gdb_step_for_stub;
59 }
60
61 #
62 # the line at which break main will put the breakpoint
63 #
64 set main_line 32
65
66 # The commands we test here produce many lines of output; disable "press 
67 # <return> to continue" prompts.
68 send_gdb "set height 0\n"
69 gdb_expect -re "$gdb_prompt $"
70
71 #
72 # break at main
73 #
74 gdb_test "break main" \
75     "Breakpoint.*at.* file .*$srcfile, line.*" \
76     "breakpoint main"
77
78
79 # NOTE: this prompt is OK only when the annotation level is > 1
80
81 # NOTE: When this prompt is in use the gdb_test procedure cannot be
82 # used because it assumes that the last char after the gdb_prompt is a
83 # white space. This is not true with this annotated prompt. So we must
84 # use send_gdb and gdb_expect or gdb_expect_list.
85
86 set old_gdb_prompt $gdb_prompt
87 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
88
89
90
91 #
92 # set the annotation level to 3
93 #
94 # of course, this will test:
95 # annotate-pre-prompt
96 # annotate-prompt
97 # annotate-post-prompt (in the next block)
98 #
99 send_gdb "set annotate 3\n" 
100 gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
101     "set annotate 3"
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 \r\n"
124     "\(\r\n\032\032\(frames-invalid|breakpoints-invalid\)\r\n\)+"
125     "\r\n\032\032starting\r\n"
126     "\(\r\n\032\032\(frames-invalid|breakpoints-invalid\)\r\n\)+"
127     "\r\n\032\032breakpoint 1\r\n"
128     "\r\n"
129     "Breakpoint 1, 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\032frames-invalid\r\n\)+"
146     "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
147     "\r\n\032\032stopped\r\n"
148 }
149
150
151 #
152 # printing the array:
153 #
154 send_gdb "print my_array\n"
155 gdb_expect_list "print array" "$gdb_prompt$" {
156     "\r\n\032\032post-prompt\r\n"
157     ".*= .1, 2, 3.\r\n"
158 }
159
160
161 #
162 # this should generate an error message, so to test:
163 # annotate-error-begin
164 # FIXME: annotate-error not tested
165 #
166
167 #exp_internal 1
168 send_gdb "print non_existent_value\n"
169 gdb_expect_list "print non_existent_value" "$gdb_prompt$" {
170     "\r\n\032\032post-prompt\r\n"
171     "\r\n\032\032error-begin\r\n"
172     "No symbol \"non_existent_value\" in current context.\r\n"
173     "\r\n\032\032error\r\n"
174 }
175
176
177 #
178 # break at signal handler
179 #
180 send_gdb "break handle_USR1\n"
181 gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" {
182     "\r\n\032\032post-prompt\r\n"
183     "\r\n\032\032breakpoints-invalid\r\n"
184     "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n"
185 }
186
187 #
188 # break at printf. When we are stopped at printf, we can test 
189 #
190 send_gdb "break printf\n"
191 gdb_expect_list "breakpoint printf" "$gdb_prompt$" {
192     "\r\n\032\032post-prompt\r\n"
193     "\r\n\032\032breakpoints-invalid\r\n"
194     "Breakpoint.*at 0x\[0-9a-z\]+.*"
195 }
196
197 #
198 # get to printf
199 #
200 send_gdb "continue\n"
201 gdb_expect_list "continue to printf" "$gdb_prompt$" {
202     "\r\n\032\032post-prompt\r\n"
203     "Continuing.\r\n"
204     "\r\n\032\032starting\r\n"
205     "\r\n\032\032frames-invalid\r\n"
206     "\r\n\032\032breakpoint 3\r\n"
207     "\r\n"
208     "Breakpoint 3, \[^\r\n\]*\r\n"
209     "\r\n\032\032stopped\r\n"
210 }
211
212 send_gdb "backtrace\n"
213 gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" {
214     "\r\n\032\032post-prompt\r\n"
215     "#0 .* printf \[^\r\n\]*\r\n"
216     "#1 .* main \[^\r\n\]*\r\n"
217 }
218
219
220 #
221 # test printing a frame with some arguments: 
222 #
223 send_gdb "signal SIGUSR1\n"
224 gdb_expect_list "send SIGUSR1" "$gdb_prompt$" {
225     "\r\n\032\032post-prompt\r\n"
226     "Continuing with signal SIGUSR1.\r\n"
227     "\r\n\032\032starting\r\n"
228     "\r\n\032\032frames-invalid\r\n"
229     "\r\n\032\032breakpoint 2\r\n"
230     "Breakpoint 2, handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n"
231     "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
232     "\r\n\032\032stopped\r\n"
233 }
234
235
236 #
237 # test:
238 #
239 verbose "match_max local is: [match_max]"
240 verbose "match_max default is: [match_max -d]"
241 # This is necessary because a 2000 buffer is not enought to get everything
242 # up to the prompt ad the test gets a timeout.
243 match_max 3000
244 verbose "match_max now is: [match_max]"
245 send_gdb "backtrace\n"
246 gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" {
247     "#0 +handle_USR1 \[^\r\n\]+\r\n"
248     "#1 +.signal handler called.\r\n"
249     "#2 .* printf \[^\r\n\]+\r\n"
250     "#3 .* main \[^\r\n\]+\r\n"
251 }
252
253 #
254 # delete all the breakpoints
255 #
256 send_gdb "delete 1\n"
257 gdb_expect_list "delete bp 1" "$gdb_prompt$" {
258     "\r\n\032\032post-prompt\r\n"
259 }
260
261 send_gdb "delete 2\n"
262 gdb_expect_list "delete bp 2" "$gdb_prompt$" {
263     "\r\n\032\032post-prompt\r\n"
264 }
265
266 send_gdb "delete 3\n"
267 gdb_expect_list "delete bp 3" "$gdb_prompt$" {
268     "\r\n\032\032post-prompt\r\n"
269 }
270
271 #
272 # break at main, after value is initialized. This is in preparation
273 # to test the annotate output for the display command.
274 #
275 send_gdb "break main\n"
276 gdb_expect_list "break at 28" "$gdb_prompt$" {
277     "\r\n\032\032post-prompt\r\n"
278     "\r\n\032\032breakpoints-invalid\r\n"
279     "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line 32.\r\n"
280 }
281
282 #
283 # display the value
284 #
285 send_gdb "display value\n"
286 gdb_expect_list "set up display" "$gdb_prompt$" {
287     "\r\n\032\032post-prompt\r\n"
288     "1: value = 7\r\n"
289 }
290
291
292 # should ask query. Test annotate-query.
293 # we don't care about anything else here, only the query.
294
295 send_gdb "run\n"
296 gdb_expect {
297   -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
298          send_gdb "y\n"
299          gdb_expect {
300              -re ".*post-query.*$gdb_prompt$" \
301                      { pass "re-run" }
302              -re ".*$gdb_prompt$"  { fail "re-run" }
303              timeout { fail "re-run (timeout)" }
304          }
305      }
306   -re ".*$gdb_prompt$"  { fail "re-run" }
307   timeout { fail "re-run (timeout)" }
308 }
309
310 #
311 # Test that breakpoints-invalid is issued once and only once for
312 # breakpoint ignore count changes, after annotation stopped.
313 #
314 send_gdb "break 46\n"
315 gdb_expect_list  "break at 46" "$gdb_prompt$" {
316     "\r\n\032\032post-prompt\r\n"
317     "\r\n\032\032breakpoints-invalid\r\n"
318     "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line 46.\r\n"
319 }
320
321 send_gdb "ignore 5 4\n"
322 gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
323     "\r\n\032\032post-prompt\r\n"
324     "Will ignore next 4 crossings of breakpoint 5"
325     "\r\n\032\032breakpoints-invalid\r\n"
326     "\r\n"
327 }
328
329 send_gdb "continue\n"
330 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" {
331     "\r\n\032\032post-prompt\r\n"
332     "\(\r\n\032\032frames-invalid\r\n\)+"
333     "\r\n\032\032breakpoint 5\r\n"
334     "Breakpoint 5, main \\(\\) at .*annota3.c:46"
335     "\r\n\032\032source .*annota3.c:46:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
336     "1: value = 11\r\n"
337     "\r\n\032\032stopped\r\n"
338     "\r\n\032\032breakpoints-invalid\r\n"
339 }
340
341 # check that ignore command is working, or the above can provide
342 # misleading assurance ...
343
344 send_gdb "next\n"
345 gdb_expect_list "next to exit loop" "$gdb_prompt$"  {
346     "\r\n\032\032post-prompt\r\n"
347     "\r\n\032\032starting\r\n"
348     "\(\r\n\032\032frames-invalid\r\n\)+"
349     "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
350     "1: value = 12\r\n"
351     "\r\n\032\032stopped\r\n"
352 }
353
354 send_gdb "next\n"
355 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" {
356     "\r\n\032\032post-prompt\r\n"
357     "\r\n\032\032starting\r\n"
358     "\(\r\n\032\032frames-invalid\r\n\)+"
359     "\r\n\032\032source.*annota3.c:49:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
360     "1: value = 12\r\n"
361     "\r\n\032\032stopped\r\n"
362 }
363
364 #
365 # Send a signal that is not handled
366 #
367 # SIGTRAP signals are dropped before they get to the inferior process
368 # on hpux11.  In theory, this behaivor can be controlled by setting
369 # TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause
370 # the signal to be properly delivered.
371 #
372 # It has been verified that other signals will be delivered.  However,
373 # rather than twiddle the test, I choose to leave it as-is as it
374 # exposes an interesting failure on hpux11.
375 setup_xfail hppa*-*-hpux11*
376 send_gdb "signal SIGTRAP\n"
377 gdb_expect_list "signal sent" "$gdb_prompt$" {
378     "\r\n\032\032post-prompt\r\n"
379     "Continuing with signal SIGTRAP.\r\n"
380     "\r\n\032\032starting\r\n"
381     "\r\n\032\032frames-invalid\r\n"
382     "\r\n\032\032frames-invalid\r\n"
383     "\r\n\032\032signalled\r\n"
384     "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
385     "The program no longer exists.\r\n"
386     "\r\n\032\032stopped\r\n"
387 }
388
389
390 # Check for production of a core file
391 # and remove it!
392
393 set exec_output [remote_exec build "ls core"]
394
395 if [ regexp "core not found" $exec_output]  {
396     pass "No core dumped"
397 } else {
398   if [ regexp "No such file or directory" $exec_output] {
399       pass "No core dumped"
400   } else {
401       remote_exec build "rm -f core"
402       pass "Core dumped and removed"
403   }
404 }
405
406 # restore the original prompt for the rest of the testsuite
407
408 set gdb_prompt $old_gdb_prompt