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