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