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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.gdb/] [selftest.exp] - Blame information for rev 308

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
# Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002, 2003, 2004,
2
# 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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 3 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, see .
16
 
17
# This file was written by Rob Savoye. (rob@cygnus.com)
18
 
19
if $tracelevel then {
20
    strace $tracelevel
21
}
22
 
23
set prms_id 0
24
set bug_id 0
25
 
26
# are we on a target board
27
if { [is_remote target] || ![isnative] } then {
28
    return
29
}
30
 
31
# Not all of the lines of code near the start of main are executed for
32
# every machine.  Also, optimization may reorder some of the lines.
33
# So all we do is try to step or next over everything until we get
34
# to a line that we know is always executed.
35
 
36
proc do_steps_and_nexts {} {
37
    global gdb_prompt
38
    global srcdir
39
 
40
    gdb_reinitialize_dir $srcdir/..
41
 
42
    set unlikely_line 0
43
    for {set count 0} {$count < 32} {incr count} {
44
        send_gdb "list\n"
45
        # NOTE: carlton/2002-12-11: The "initial brace" and
46
        # "current_directory initialization" possibilities happen to
47
        # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
48
        # optimization.
49
        gdb_expect {
50
            -re ".*context = data.*$gdb_prompt $" {
51
                set description "step over context initialization"
52
                set command "step"
53
            }
54
            -re ".*argc = context->argc.*$gdb_prompt $" {
55
                set description "step over argc initialization"
56
                set command "step"
57
            }
58
            -re ".*argv = context->argv.*$gdb_prompt $" {
59
                set description "step over argv initialization"
60
                set command "step"
61
            }
62
            -re ".*quiet = 0.*$gdb_prompt $" {
63
                set description "step over quiet initialization"
64
                set command "step"
65
            }
66
            -re ".*batch = 0.*$gdb_prompt $" {
67
                set description "step over batch initialization"
68
                set command "step"
69
            }
70
            -re ".*symarg = NULL.*$gdb_prompt $" {
71
                set description "step over symarg initialization"
72
                set command "step"
73
            }
74
            -re ".*execarg = NULL.*$gdb_prompt $" {
75
                set description "step over execarg initialization"
76
                set command "step"
77
            }
78
            -re ".*pidarg = NULL.*$gdb_prompt $" {
79
                set description "step over pidarg initialization"
80
                set command "step"
81
            }
82
            -re ".*corearg = NULL.*$gdb_prompt $" {
83
                set description "step over corearg initialization"
84
                set command "step"
85
            }
86
            -re ".*pid_or_core_arg = NULL.*$gdb_prompt $" {
87
                set description "step over pid_or_core_arg 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
            }
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
                # Note: ezannoni/2004/02/17: This check should be
104
                # removed, since as of today that source line is not
105
                # in gdb anymore.
106
                set description "next over START_PROGRESS and everything it calls"
107
                set command "next"
108
            }
109
            -re ".*mac_init.*$gdb_prompt $" {
110
                set description "next over mac_init and everything it calls"
111
                set command "next"
112
            }
113
            -re ".*init_malloc.*$gdb_prompt $" {
114
                # gdb 6.2.X is the last gdb which called init_malloc
115
                set description "next over init_malloc and everything it calls"
116
                set command "next"
117
            }
118
            -re ".*lim_at_start.*$gdb_prompt $" {
119
                set description "next over lim_at_start initialization"
120
                set command "next"
121
            }
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
            }
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
            }
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
            }
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
            }
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
            }
183
            -re ".*ndir = 0.*$gdb_prompt $" {
184
                set description "step over ndir initialization"
185
                set command "step"
186
            }
187
            -re ".*instream = stdin.*$gdb_prompt $" {
188
                set description "step over instream initialization"
189
                set command "step"
190
            }
191
            -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf..;.*$gdb_prompt $" {
192
                set description "next over getcwd"
193
                set command "next"
194
            }
195
            -re ".*quit_flag = 0.*$gdb_prompt $" {
196
                set description "step over quit_flag initialization"
197
                set command "step"
198
            }
199
            -re ".*gdb_stdout = stdio_fileopen .stdout.;.*$gdb_prompt $" {
200
                set description "step over gdb_stdout initialization"
201
                set command "step"
202
            }
203
            -re ".*gdb_stderr = stdio_fileopen .stderr.;.*$gdb_prompt $" {
204
                set description "step over gdb_stderr initialization"
205
                set command "step"
206
            }
207
            -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
208
                setup_xfail "rs6000-*-aix3*"
209
                fail "must be able to list source lines"
210
                return
211
            }
212
            -re ".*interpreter_p = xstrdup.*$gdb_prompt $" {
213
                if { $unlikely_line == 0 } {
214
                    # This is a GCC optimization bug; a constant has been
215
                    # associated with the wrong line number.
216
                    setup_xfail "*-*-*" gcc/26475
217
                    fail "$description (unlikely line from gcc)"
218
                    set unlikely_line 1
219
                }
220
                set description "next over xstrdup"
221
                set command "next"
222
            }
223
            -re ".*$gdb_prompt $" {
224
                fail "unknown source line after $description"
225
                return
226
            }
227
            default {
228
                fail "unknown source line near main"
229
                return
230
            }
231
        }
232
        send_gdb "$command\n"
233
        gdb_expect {
234
            -re ".*No such file or directory.\r\n$gdb_prompt $" {
235
                fail "$description (no source available)"
236
            }
237
            -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
238
                fail "$description (no source available)"
239
            }
240
            -re ".*$gdb_prompt $" {
241
                pass "$description"
242
            }
243
            timeout {
244
                fail "$description (timeout)"
245
            }
246
        }
247
    }
248
}
249
 
250
proc test_with_self { executable } {
251
    global gdb_prompt
252
    global tool
253
    global det_file
254
    global decimal
255
    global timeout
256
 
257
    # load yourself into the debugger
258
    # This can take a relatively long time, particularly for testing where
259
    # the executable is being accessed over a network, or where gdb does not
260
    # support partial symbols for a particular target and has to load the
261
    # entire symbol table.  Set the timeout to 10 minutes, which should be
262
    # adequate for most environments (it *has* timed out with 5 min on a
263
    # SPARCstation SLC under moderate load, so this isn't unreasonable).
264
    # After gdb is started, set the timeout to 30 seconds for the duration
265
    # of this test, and then back to the original value.
266
 
267
    set oldtimeout $timeout
268
    set timeout 600
269
    verbose "Timeout is now $timeout seconds" 2
270
 
271
    global gdb_file_cmd_debug_info
272
    set gdb_file_cmd_debug_info "unset"
273
 
274
    set result [gdb_load $executable]
275
    set timeout $oldtimeout
276
    verbose "Timeout is now $timeout seconds" 2
277
 
278
    if { $result != 0 } then {
279
        return -1
280
    }
281
 
282
    if { $gdb_file_cmd_debug_info != "debug" } then {
283
        untested "No debug information, skipping testcase."
284
        return -1
285
    }
286
 
287
    # disassemble yourself
288
    gdb_test "x/10i main" \
289
            "x/10i.*main.*main.$decimal.*main.$decimal.*" \
290
            "Disassemble main"
291
 
292
    # Set a breakpoint at main
293
    gdb_test "break captured_main" \
294
            "Breakpoint.*at.* file.*, line.*" \
295
            "breakpoint in captured_main"
296
 
297
    # We'll need this when we send a ^C to GDB.  Need to do it before we
298
    # run the program and gdb starts saving and restoring tty states.
299
    # On Ultrix, we don't need it and it is really slow (because shell_escape
300
    # doesn't use vfork).
301
    if ![istarget "*-*-ultrix*"] then {
302
        gdb_test "shell stty intr '^C'" "" \
303
            "set interrupt character in test_with_self"
304
    }
305
 
306
    # FIXME: If we put this after the run to main, the first list
307
    # command doesn't print the same line as the current line where
308
    # gdb is stopped.
309
    gdb_test "set listsize 1" "" "set listsize to 1"
310
 
311
    # run yourself
312
    # It may take a very long time for the inferior gdb to start (lynx),
313
    # so we bump it back up for the duration of this command.
314
    set timeout 600
315
 
316
    set description "run until breakpoint at captured_main"
317
    send_gdb "run -nw\n"
318
    gdb_expect {
319
        -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
320
            pass "$description"
321
        }
322
        -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
323
            xfail "$description (line numbers scrambled?)"
324
        }
325
        -re "vfork: No more processes.*$gdb_prompt $" {
326
            fail "$description (out of virtual memory)"
327
            set timeout $oldtimeout
328
            verbose "Timeout is now $timeout seconds" 2
329
            return -1
330
        }
331
        -re ".*$gdb_prompt $" {
332
            fail "$description"
333
            set timeout $oldtimeout
334
            verbose "Timeout is now $timeout seconds" 2
335
            return -1
336
        }
337
        timeout {
338
            fail "$description (timeout)"
339
        }
340
    }
341
 
342
    set timeout $oldtimeout
343
    verbose "Timeout is now $timeout seconds" 2
344
 
345
    # do we have a version number ?
346
    send_gdb "print version\n"
347
    gdb_expect {
348
        -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
349
            pass "printed version as string"
350
        }
351
        -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
352
            pass "printed version as pointer"
353
        }
354
        -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
355
            pass "printed version with cast"
356
        }
357
        -re ".*$gdb_prompt $"   { fail "printed version" }
358
        timeout         { fail "(timeout) printed version" }
359
    }
360
 
361
    do_steps_and_nexts
362
 
363
    gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
364
 
365
    # do_steps_and_nexts left us ready to execute an xmalloc call,
366
    # so give that a try.
367
    # If we don't actually enter the xmalloc call when we give a
368
    # step command that seems like a genuine bug.  It seems to happen
369
    # on most RISC processors.
370
    # NOTE drow/2003-06-22: However, if we step back to the preceding two
371
    # lines, just keep stepping until we enter.
372
    set stepped_back 0
373
    setup_xfail "alpha-*-*" "mips-*-*"
374
    set description "step into xmalloc call"
375
    send_gdb "step\n"
376
    gdb_expect {
377
        -re "ncmd = 0;.*$gdb_prompt $" {
378
            set stepped_back 1
379
            send_gdb "step\n"
380
            exp_continue
381
        }
382
        -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
383
            set stepped_back 1
384
            send_gdb "step\n"
385
            exp_continue
386
        }
387
        -re "dirsize = 1;.*$gdb_prompt $" {
388
            set stepped_back 1
389
            send_gdb "step\n"
390
            exp_continue
391
        }
392
        -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
393
            if { $stepped_back == 1 } {
394
                send_gdb "step\n"
395
                exp_continue
396
            } else {
397
                fail "$description"
398
            }
399
        }
400
        -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
401
            pass "$description"
402
        }
403
        -re ".*No such file or directory.\r\n$gdb_prompt $" {
404
            pass "$description (no source available)"
405
        }
406
        -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
407
            pass "$description (no source available)"
408
        }
409
        -re ".*$gdb_prompt $" {
410
            fail "$description"
411
        }
412
        timeout {
413
            fail "$description (timeout)"
414
        }
415
    }
416
 
417
    # start the "xgdb" process
418
    send_gdb "continue\n"
419
    gdb_expect {
420
        -re "GNU gdb \[0-9\.\]*.*
421
Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc.*
422
License GPLv3\\+: GNU GPL version 3 or later .*
423
This is free software: you are free to change and redistribute it.*
424
There is NO WARRANTY, to the extent permitted by law.  Type \"show copying\".*
425
and \"show warranty\" for details.*
426
This GDB was configured as .*$gdb_prompt $"\
427
            { pass "xgdb is at prompt" }
428
        -re "GNU gdb \[0-9\.\]*.*
429
Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc.*
430
GDB is free software, covered by the GNU General Public License, and you are.*
431
welcome to change it and/or distribute copies of it under certain conditions.*
432
Type \"show copying\" to see the conditions.*
433
There is absolutely no warranty for GDB.  Type \"show warranty\" for details.*
434
This GDB was configured as .*$gdb_prompt $"\
435
            { pass "xgdb is at prompt (obsolescent gdb 2)" }
436
        -re "GDB is free software and you are welcome to distribute copies of it.*
437
 under certain conditions; type \"show copying\" to see the conditions..*
438
There is absolutely no warranty for GDB; type \"show warranty\" for details..*
439
GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\
440
            { pass "xgdb is at prompt (obsolescent gdb 1)" }
441
        -re ".*$gdb_prompt $"       { fail "xgdb is at prompt" }
442
        timeout             { fail "(timeout) xgdb is at prompt" }
443
    }
444
 
445
    # set xgdb prompt so we can tell which is which
446
    send_gdb "set prompt (xgdb) \n"
447
    gdb_expect {
448
        -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $"  { pass "Set xgdb prompt" }
449
        -re ".*$gdb_prompt $"           { fail "Set xgdb prompt" }
450
        default                         { fail "(timeout) Set xgdb prompt" }
451
    }
452
 
453
    # kill the xgdb process
454
    set description "send ^C to child process"
455
    send_gdb "\003"
456
    gdb_expect {
457
        -re "Program received signal SIGINT.*$gdb_prompt $" {
458
            pass "$description"
459
        }
460
        -re ".*$gdb_prompt $" {
461
            fail "$description"
462
        }
463
        timeout {
464
            fail "$description (timeout)"
465
        }
466
    }
467
 
468
    set description "send SIGINT signal to child process"
469
    send_gdb "signal SIGINT\n"
470
    gdb_expect {
471
        -re "Continuing with signal SIGINT.*$gdb_prompt $" {
472
            pass "$description"
473
        }
474
        -re ".*$gdb_prompt $" {
475
            fail "$description"
476
        }
477
        timeout {
478
            fail "$description (timeout)"
479
        }
480
    }
481
 
482
    # get a stack trace
483
    #
484
    # This fails on some linux systems for unknown reasons.  On the
485
    # systems where it fails, sometimes it works fine when run manually.
486
    # The testsuite failures may not be limited to just aout systems.
487
    setup_xfail "i*86-pc-linuxaout-gnu"
488
    set description "backtrace through signal handler"
489
    send_gdb "backtrace\n"
490
    gdb_expect {
491
        -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
492
            pass "$description"
493
        }
494
        -re ".*$gdb_prompt $" {
495
            # On the alpha, we hit the infamous problem about gdb
496
            # being unable to get the frame pointer (mentioned in
497
            # gdb/README).  As it is intermittent, there is no way to
498
            # XFAIL it which will give us an XPASS if the problem goes
499
            # away.
500
            setup_xfail "alpha*-*-osf*"
501
            fail "$description"
502
        }
503
        timeout {
504
            fail "$description (timeout)"
505
        }
506
    }
507
 
508
 
509
    # Set the timeout back to the value it had when we were called.
510
    set timeout $oldtimeout
511
    verbose "Timeout is now $timeout seconds" 2
512
 
513
    # Restart gdb in case next test expects it to be started already.
514
    return 0
515
}
516
 
517
# Find a pathname to a file that we would execute if the shell was asked
518
# to run $arg using the current PATH.
519
 
520
proc find_gdb { arg } {
521
 
522
    # If the arg directly specifies an existing executable file, then
523
    # simply use it.
524
 
525
    if [file executable $arg] then {
526
        return $arg
527
    }
528
 
529
    set result [which $arg]
530
    if [string match "/" [ string range $result 0 0 ]] then {
531
        return $result
532
    }
533
 
534
    # If everything fails, just return the unqualified pathname as default
535
    # and hope for best.
536
 
537
    return $arg
538
}
539
 
540
# Run the test with self.
541
# Copy the file executable file in case this OS doesn't like to edit its own
542
# text space.
543
 
544
set GDB_FULLPATH [find_gdb $GDB]
545
 
546
# Remove any old copy lying around.
547
remote_file host delete x$tool
548
 
549
gdb_start
550
set file [remote_download host $GDB_FULLPATH x$tool]
551
set result [test_with_self $file];
552
gdb_exit;
553
catch "remote_file host delete $file";
554
 
555
if {$result <0} then {
556
    warning "Couldn't test self"
557
    return -1
558
}

powered by: WebSVN 2.1.0

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