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