OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [gdb.base/] [selftest.exp] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.