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