Commit | Line | Data |
---|---|---|
48fe539f | 1 | # Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002, 2003 |
b6ba6518 | 2 | # Free Software Foundation, Inc. |
adf40b2e JM |
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 | |
6 | # the Free Software Foundation; either version 2 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
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. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | ||
18 | # Please email any bugs, comments, and/or additions to this file to: | |
19 | # bug-gdb@prep.ai.mit.edu | |
20 | ||
21 | # This file was written by Rob Savoye. (rob@cygnus.com) | |
22 | ||
23 | if $tracelevel then { | |
24 | strace $tracelevel | |
25 | } | |
26 | ||
27 | set prms_id 0 | |
28 | set bug_id 0 | |
29 | ||
30 | # are we on a target board | |
31 | if [is_remote target] { | |
32 | return | |
33 | } | |
34 | ||
adf40b2e JM |
35 | # Not all of the lines of code near the start of main are executed for |
36 | # every machine. Also, optimization may reorder some of the lines. | |
37 | # So all we do is try to step or next over everything until we get | |
38 | # to a line that we know is always executed. | |
39 | ||
40 | proc do_steps_and_nexts {} { | |
41 | global gdb_prompt | |
42 | global srcdir | |
43 | ||
44 | gdb_reinitialize_dir $srcdir/.. | |
45 | ||
48fe539f | 46 | for {set count 0} {$count < 32} {incr count} { |
adf40b2e | 47 | send_gdb "list\n" |
ee73db83 DC |
48 | # NOTE: carlton/2002-12-11: The "initial brace" and |
49 | # "current_directory initialization" possibilities happen to | |
50 | # me with GCC 3.1 on i686-pc-linux-gnu when I compile with | |
51 | # optimization. | |
adf40b2e | 52 | gdb_expect { |
0d06e24b JM |
53 | -re ".*context = data.*$gdb_prompt $" { |
54 | set description "step over context initialization" | |
55 | set command "step" | |
56 | } | |
57 | -re ".*argc = context->argc.*$gdb_prompt $" { | |
58 | set description "step over argc initialization" | |
59 | set command "step" | |
60 | } | |
61 | -re ".*argv = context->argv.*$gdb_prompt $" { | |
62 | set description "step over argv initialization" | |
63 | set command "step" | |
64 | } | |
65 | -re ".*quiet = 0.*$gdb_prompt $" { | |
66 | set description "step over quiet initialization" | |
67 | set command "step" | |
68 | } | |
69 | -re ".*batch = 0.*$gdb_prompt $" { | |
70 | set description "step over batch initialization" | |
71 | set command "step" | |
72 | } | |
adf40b2e JM |
73 | -re ".*symarg = NULL.*$gdb_prompt $" { |
74 | set description "step over symarg initialization" | |
75 | set command "step" | |
76 | } | |
77 | -re ".*execarg = NULL.*$gdb_prompt $" { | |
78 | set description "step over execarg initialization" | |
79 | set command "step" | |
80 | } | |
81 | -re ".*corearg = NULL.*$gdb_prompt $" { | |
82 | set description "step over corearg initialization" | |
83 | set command "step" | |
84 | } | |
85 | -re ".*cdarg = NULL.*$gdb_prompt $" { | |
86 | set description "step over cdarg initialization" | |
87 | set command "step" | |
88 | } | |
89 | -re ".*ttyarg = NULL.*$gdb_prompt $" { | |
90 | set description "step over ttyarg initialization" | |
91 | set command "step" | |
92 | } | |
adf40b2e JM |
93 | -re ".*time_at_startup = get_run_time.*$gdb_prompt $" { |
94 | set description "next over get_run_time and everything it calls" | |
95 | set command "next" | |
96 | } | |
97 | -re ".*START_PROGRESS.*$gdb_prompt $" { | |
98 | set description "next over START_PROGRESS and everything it calls" | |
99 | set command "next" | |
100 | } | |
101 | -re ".*mac_init.*$gdb_prompt $" { | |
102 | set description "next over mac_init and everything it calls" | |
103 | set command "next" | |
104 | } | |
105 | -re ".*init_malloc.*$gdb_prompt $" { | |
106 | set description "next over init_malloc and everything it calls" | |
107 | set command "next" | |
108 | } | |
6dd77b81 RH |
109 | -re ".*lim_at_start.*$gdb_prompt $" { |
110 | set description "next over lim_at_start initialization" | |
111 | set command "next" | |
112 | } | |
adf40b2e JM |
113 | -re ".*count . 0x3.*$gdb_prompt $" { |
114 | set description "next over conditional stack alignment code 1" | |
115 | set command "next" | |
116 | } | |
117 | -re ".*if .i != 0.*$gdb_prompt $" { | |
118 | set description "next over conditional stack alignment code 2" | |
119 | set command "next" | |
120 | } | |
121 | -re ".*alloca .i - 4.*$gdb_prompt $" { | |
122 | set description "next over conditional stack alignment alloca" | |
123 | set command "next" | |
124 | } | |
adf40b2e JM |
125 | -re ".*cmdsize = 1.*$gdb_prompt $" { |
126 | set description "step over cmdsize initialization" | |
127 | set command "next" | |
128 | } | |
129 | -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" { | |
130 | set description "next over cmdarg initialization via xmalloc" | |
131 | set command "next" | |
132 | } | |
133 | -re ".*ncmd = 0.*$gdb_prompt $" { | |
134 | set description "next over ncmd initialization" | |
135 | set command "next" | |
136 | } | |
137 | -re ".*dirsize = 1.*$gdb_prompt $" { | |
138 | set description "next over dirsize initialization" | |
139 | set command "next" | |
140 | } | |
141 | -re ".*dirarg = .* xmalloc.*$gdb_prompt $" { | |
142 | return | |
143 | } | |
8cf8c2b8 AC |
144 | -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" { |
145 | set description "next over setlocale LC_MESSAGES" | |
146 | set command "next" | |
147 | } | |
148 | -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" { | |
149 | set description "next over setlocale LC_CTYPE" | |
150 | set command "next" | |
151 | } | |
152 | -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" { | |
153 | set description "next over bindtextdomain" | |
154 | set command "next" | |
155 | } | |
156 | -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" { | |
157 | set description "next over textdomain PACKAGE" | |
158 | set command "next" | |
159 | } | |
ee73db83 DC |
160 | -re "\[0-9\]*\t\{\r\n$gdb_prompt $" { |
161 | set description "step over initial brace" | |
162 | set command "step" | |
163 | } | |
164 | -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" { | |
165 | set description "step over current_directory initialization" | |
166 | set command "step" | |
167 | } | |
a1769aca DC |
168 | -re ".*gdb_sysroot = .*$gdb_prompt $" { |
169 | # NOTE: carlton/2003-01-15: More optimization reordering, | |
170 | # observed on GCC 3.1. | |
171 | set description "step over gdb_sysroot initialization" | |
172 | set command "step" | |
173 | } | |
180dea7c AS |
174 | -re ".*ndir = 0.*$gdb_prompt $" { |
175 | set description "step over ndir initialization" | |
176 | set command "step" | |
177 | } | |
178 | -re ".*instream = stdin.*$gdb_prompt $" { | |
179 | set description "step over instream initialization" | |
180 | set command "step" | |
181 | } | |
182 | -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf..;.*$gdb_prompt $" { | |
183 | set description "next over getcwd" | |
184 | set command "next" | |
185 | } | |
adf40b2e JM |
186 | -re "\[ \t\]+\{\r\n$gdb_prompt $" { |
187 | setup_xfail "mips-*-irix5*" | |
188 | fail "$description ended up at odd location" | |
189 | } | |
190 | -re ".*main.c.*No such file or directory.*$gdb_prompt $" { | |
191 | setup_xfail "rs6000-*-aix3*" | |
192 | fail "must be able to list source lines" | |
193 | return | |
194 | } | |
195 | -re ".*$gdb_prompt $" { | |
196 | fail "unknown source line after $description" | |
197 | return | |
198 | } | |
199 | default { | |
200 | fail "unknown source line near main" | |
201 | return | |
202 | } | |
203 | } | |
204 | send_gdb "$command\n" | |
205 | gdb_expect { | |
206 | -re ".*No such file or directory.\r\n$gdb_prompt $" { | |
207 | fail "$description (no source available)" | |
208 | } | |
209 | -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" { | |
210 | fail "$description (no source available)" | |
211 | } | |
212 | -re ".*$gdb_prompt $" { | |
213 | pass "$description" | |
214 | } | |
215 | timeout { | |
216 | fail "$description (timeout)" | |
217 | } | |
218 | } | |
219 | } | |
220 | } | |
221 | ||
222 | proc test_with_self { executable } { | |
223 | global gdb_prompt | |
224 | global tool | |
225 | global det_file | |
226 | global decimal | |
227 | global timeout | |
228 | ||
229 | # load yourself into the debugger | |
230 | # This can take a relatively long time, particularly for testing where | |
231 | # the executable is being accessed over a network, or where gdb does not | |
232 | # support partial symbols for a particular target and has to load the | |
233 | # entire symbol table. Set the timeout to 10 minutes, which should be | |
234 | # adequate for most environments (it *has* timed out with 5 min on a | |
235 | # SPARCstation SLC under moderate load, so this isn't unreasonable). | |
236 | # After gdb is started, set the timeout to 30 seconds for the duration | |
237 | # of this test, and then back to the original value. | |
238 | ||
239 | set oldtimeout $timeout | |
240 | set timeout 600 | |
241 | verbose "Timeout is now $timeout seconds" 2 | |
242 | if {[gdb_load $executable] <0} then { | |
243 | set timeout $oldtimeout | |
244 | verbose "Timeout is now $timeout seconds" 2 | |
245 | return -1 | |
246 | } | |
247 | set timeout $oldtimeout | |
248 | verbose "Timeout is now $timeout seconds" 2 | |
249 | ||
250 | # disassemble yourself | |
251 | gdb_test "x/10i main" \ | |
252 | "x/10i.*main.*main.$decimal.*main.$decimal.*" \ | |
253 | "Disassemble main" | |
254 | ||
255 | # Set a breakpoint at main | |
0d06e24b | 256 | gdb_test "break captured_main" \ |
adf40b2e | 257 | "Breakpoint.*at.* file.*, line.*" \ |
0d06e24b | 258 | "breakpoint in captured_main" |
adf40b2e JM |
259 | |
260 | # We'll need this when we send a ^C to GDB. Need to do it before we | |
261 | # run the program and gdb starts saving and restoring tty states. | |
262 | # On Ultrix, we don't need it and it is really slow (because shell_escape | |
263 | # doesn't use vfork). | |
264 | if ![istarget "*-*-ultrix*"] then { | |
265 | gdb_test "shell stty intr '^C'" "" \ | |
266 | "set interrupt character in test_with_self" | |
267 | } | |
268 | ||
269 | # FIXME: If we put this after the run to main, the first list | |
270 | # command doesn't print the same line as the current line where | |
271 | # gdb is stopped. | |
272 | gdb_test "set listsize 1" "" "set listsize to 1" | |
273 | ||
274 | # run yourself | |
275 | # It may take a very long time for the inferior gdb to start (lynx), | |
276 | # so we bump it back up for the duration of this command. | |
277 | set timeout 600 | |
278 | ||
0d06e24b | 279 | set description "run until breakpoint at captured_main" |
adf40b2e JM |
280 | send_gdb "run -nw\n" |
281 | gdb_expect { | |
0d06e24b | 282 | -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" { |
adf40b2e JM |
283 | pass "$description" |
284 | } | |
0d06e24b | 285 | -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" { |
adf40b2e JM |
286 | xfail "$description (line numbers scrambled?)" |
287 | } | |
288 | -re "vfork: No more processes.*$gdb_prompt $" { | |
289 | fail "$description (out of virtual memory)" | |
290 | set timeout $oldtimeout | |
291 | verbose "Timeout is now $timeout seconds" 2 | |
292 | return -1 | |
293 | } | |
294 | -re ".*$gdb_prompt $" { | |
295 | fail "$description" | |
296 | set timeout $oldtimeout | |
297 | verbose "Timeout is now $timeout seconds" 2 | |
298 | return -1 | |
299 | } | |
300 | timeout { | |
301 | fail "$description (timeout)" | |
302 | } | |
303 | } | |
304 | ||
305 | set timeout $oldtimeout | |
306 | verbose "Timeout is now $timeout seconds" 2 | |
307 | ||
308 | # do we have a version number ? | |
309 | send_gdb "print version\n" | |
310 | gdb_expect { | |
d4f3574e SS |
311 | -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" { |
312 | pass "printed version as string" | |
313 | } | |
adf40b2e | 314 | -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" { |
d4f3574e | 315 | pass "printed version as pointer" |
adf40b2e JM |
316 | } |
317 | -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" { | |
318 | pass "printed version with cast" | |
319 | } | |
320 | -re ".*$gdb_prompt $" { fail "printed version" } | |
321 | timeout { fail "(timeout) printed version" } | |
322 | } | |
323 | ||
324 | do_steps_and_nexts | |
325 | ||
326 | gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string" | |
327 | ||
328 | # do_steps_and_nexts left us ready to execute an xmalloc call, | |
329 | # so give that a try. | |
330 | # If we don't actually enter the xmalloc call when we give a | |
331 | # step command that seems like a genuine bug. It seems to happen | |
332 | # on most RISC processors. | |
48fe539f DJ |
333 | # NOTE drow/2003-06-22: However, if we step back to the preceding two |
334 | # lines, just keep stepping until we enter. | |
335 | set stepped_back 0 | |
adf40b2e JM |
336 | setup_xfail "alpha-*-*" "mips-*-*" |
337 | set description "step into xmalloc call" | |
338 | send_gdb "step\n" | |
339 | gdb_expect { | |
48fe539f DJ |
340 | -re "ncmd = 0;.*$gdb_prompt $" { |
341 | set stepped_back 1 | |
342 | send_gdb "step\n" | |
343 | exp_continue | |
344 | } | |
274bcba0 EZ |
345 | -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" { |
346 | set stepped_back 1 | |
347 | send_gdb "step\n" | |
348 | exp_continue | |
349 | } | |
48fe539f DJ |
350 | -re "dirsize = 1;.*$gdb_prompt $" { |
351 | set stepped_back 1 | |
352 | send_gdb "step\n" | |
353 | exp_continue | |
354 | } | |
355 | -re ".*dirarg = .* xmalloc.*$gdb_prompt $" { | |
356 | if { $stepped_back == 1 } { | |
357 | send_gdb "step\n" | |
358 | exp_continue | |
359 | } else { | |
360 | fail "$description" | |
361 | } | |
362 | } | |
adf40b2e JM |
363 | -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" { |
364 | pass "$description" | |
365 | } | |
366 | -re ".*No such file or directory.\r\n$gdb_prompt $" { | |
367 | pass "$description (no source available)" | |
368 | } | |
369 | -re "A file or directory .* does not exist..\r\n$gdb_prompt $" { | |
370 | pass "$description (no source available)" | |
371 | } | |
372 | -re ".*$gdb_prompt $" { | |
373 | fail "$description" | |
374 | } | |
375 | timeout { | |
376 | fail "$description (timeout)" | |
377 | } | |
378 | } | |
379 | ||
380 | # start the "xgdb" process | |
381 | send_gdb "continue\n" | |
382 | gdb_expect { | |
383 | -re "GNU gdb \[0-9\.\]*.* | |
384 | Copyright \[0-9\]* Free Software Foundation, Inc.* | |
385 | GDB is free software, covered by the GNU General Public License, and you are.* | |
386 | welcome to change it and/or distribute copies of it under certain conditions.* | |
387 | Type \"show copying\" to see the conditions.* | |
388 | There is absolutely no warranty for GDB. Type \"show warranty\" for details.* | |
389 | This GDB was configured as .*$gdb_prompt $"\ | |
390 | { pass "xgdb is at prompt" } | |
391 | -re "GDB is free software and you are welcome to distribute copies of it.* | |
392 | under certain conditions; type \"show copying\" to see the conditions..* | |
393 | There is absolutely no warranty for GDB; type \"show warranty\" for details..* | |
394 | GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\ | |
395 | { pass "xgdb is at prompt (obsolescent gdb)" } | |
396 | -re ".*$gdb_prompt $" { fail "xgdb is at prompt" } | |
397 | timeout { fail "(timeout) xgdb is at prompt" } | |
398 | } | |
399 | ||
400 | # set xgdb prompt so we can tell which is which | |
401 | send_gdb "set prompt (xgdb) \n" | |
402 | gdb_expect { | |
403 | -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" } | |
404 | -re ".*$gdb_prompt $" { fail "Set xgdb prompt" } | |
405 | default { fail "(timeout) Set xgdb prompt" } | |
406 | } | |
407 | ||
408 | # kill the xgdb process | |
409 | set description "send ^C to child process" | |
410 | send_gdb "\003" | |
411 | gdb_expect { | |
412 | -re "Program received signal SIGINT.*$gdb_prompt $" { | |
413 | pass "$description" | |
414 | } | |
415 | -re ".*$gdb_prompt $" { | |
416 | fail "$description" | |
417 | } | |
418 | timeout { | |
419 | fail "$description (timeout)" | |
420 | } | |
421 | } | |
422 | ||
423 | set description "send SIGINT signal to child process" | |
424 | send_gdb "signal SIGINT\n" | |
425 | gdb_expect { | |
426 | -re "Continuing with signal SIGINT.*$gdb_prompt $" { | |
427 | pass "$description" | |
428 | } | |
429 | -re ".*$gdb_prompt $" { | |
430 | fail "$description" | |
431 | } | |
432 | timeout { | |
433 | fail "$description (timeout)" | |
434 | } | |
435 | } | |
436 | ||
437 | # get a stack trace | |
438 | # | |
439 | # This fails on some linux systems for unknown reasons. On the | |
440 | # systems where it fails, sometimes it works fine when run manually. | |
441 | # The testsuite failures may not be limited to just aout systems. | |
634d57ec | 442 | setup_xfail "i*86-pc-linuxaout-gnu" |
adf40b2e JM |
443 | set description "backtrace through signal handler" |
444 | send_gdb "backtrace\n" | |
445 | gdb_expect { | |
92806416 | 446 | -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" { |
adf40b2e JM |
447 | pass "$description" |
448 | } | |
449 | -re ".*$gdb_prompt $" { | |
450 | # On the alpha, we hit the infamous problem about gdb | |
451 | # being unable to get the frame pointer (mentioned in | |
452 | # gdb/README). As it is intermittent, there is no way to | |
453 | # XFAIL it which will give us an XPASS if the problem goes | |
454 | # away. | |
455 | setup_xfail "alpha*-*-osf*" | |
456 | fail "$description" | |
457 | } | |
458 | timeout { | |
459 | fail "$description (timeout)" | |
460 | } | |
461 | } | |
462 | ||
463 | ||
464 | # Set the timeout back to the value it had when we were called. | |
465 | set timeout $oldtimeout | |
466 | verbose "Timeout is now $timeout seconds" 2 | |
467 | ||
468 | # Restart gdb in case next test expects it to be started already. | |
469 | return 0 | |
470 | } | |
471 | ||
472 | # Find a pathname to a file that we would execute if the shell was asked | |
473 | # to run $arg using the current PATH. | |
474 | ||
475 | proc find_gdb { arg } { | |
476 | ||
477 | # If the arg directly specifies an existing executable file, then | |
478 | # simply use it. | |
479 | ||
480 | if [file executable $arg] then { | |
481 | return $arg | |
482 | } | |
483 | ||
484 | set result [which $arg] | |
485 | if [string match "/" [ string range $result 0 0 ]] then { | |
486 | return $result | |
487 | } | |
488 | ||
489 | # If everything fails, just return the unqualified pathname as default | |
490 | # and hope for best. | |
491 | ||
492 | return $arg | |
493 | } | |
494 | ||
495 | # Run the test with self. | |
496 | # Copy the file executable file in case this OS doesn't like to edit its own | |
497 | # text space. | |
498 | ||
499 | set GDB_FULLPATH [find_gdb $GDB] | |
500 | ||
501 | # Remove any old copy lying around. | |
502 | remote_file host delete x$tool | |
503 | ||
504 | gdb_start | |
505 | set file [remote_download host $GDB_FULLPATH x$tool] | |
506 | set result [test_with_self $file]; | |
507 | gdb_exit; | |
508 | catch "remote_file host delete $file"; | |
509 | ||
510 | if {$result <0} then { | |
511 | warning "Couldn't test self" | |
512 | return -1 | |
513 | } |