home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / testsuite / gdb.t00 / teststrategy.exp < prev    next >
Encoding:
Text File  |  1993-05-12  |  11.8 KB  |  372 lines

  1. #   Copyright (C) 1988, 1990, 1991, 1992 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. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  14.  
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # bug-gdb@prep.ai.mit.edu
  17.  
  18. # This file was written by Rob Savoye. (rob@cygnus.com)
  19.  
  20. if $tracelevel then {
  21.     strace $tracelevel
  22.     }
  23.  
  24. set prms_id 0
  25. set bug_id 0
  26.  
  27. # are we on a target board
  28. if [string first $target_alias $host_alias]==-1 then {
  29.     warning "These test cases can't run on a target system."
  30.     continue
  31. }
  32.  
  33. proc test_with_self {} {
  34.     global prompt
  35.     global tool
  36.     global det_file
  37.     global timeout
  38.     global decimal
  39.  
  40.     # load yourself into the debugger
  41.     # This can take a relatively long time, particularly for testing where
  42.     # the executable is being accessed over a network, or where gdb does not
  43.     # support partial symbols for a particular target and has to load the
  44.     # entire symbol table.  Set the timeout to 10 minutes, which should be
  45.     # adequate for most environments (it *has* timed out with 5 min on a
  46.     # SPARCstation SLC under moderate load, so this isn't unreasonable).
  47.     # After gdb is loaded, set the timeout to 30 seconds for the duration
  48.     # of this test, and then back to the original value.
  49.  
  50.     set oldtimeout $timeout
  51.     set timeout 600
  52.     if {[gdb_load "./x$tool"] <0} then {
  53.     return -1
  54.     }
  55.  
  56.     set timeout 30
  57.  
  58.     # disassemble yourself
  59.     send "x/10i main\n"
  60.     expect {
  61.     -re "x/10i.*main.*main\+$decimal.*main\+$decimal.*$prompt $"\
  62.         { pass "Disassemble main" }
  63.     -re ".*$prompt $"    { fail "Disassemble main" }
  64.     timeout        { fail "(timeout) Disassemble main" }
  65.     }
  66.  
  67.  
  68.     # do we have a version number ?
  69.     send "print version\n"
  70.     expect {
  71.     -re ".\[0-9\]+ = 0x.*\[0-9.\]+.*$prompt $"\
  72.         { pass "printed version" }
  73.     -re ".*$prompt $"    { fail "printed version" }
  74.     timeout        { fail "(timeout) printed version" }
  75.     }
  76.  
  77.  
  78.     # set a breakpoint at main()
  79.     send "break main\n"
  80.     expect {
  81.     -re "Breakpoint.*at.* file.*, line.*$prompt $" { pass "Set breakpoint at main" }
  82.     -re ".*$prompt $"   { fail "Set breakpoint at main" }
  83.     timeout        { fail "(timeout) Set breakpoint at main" }
  84.     }
  85.  
  86.  
  87.     # run yourself
  88.     send "run\n"
  89.     expect {
  90.     -re "Starting program.*Breakpoint \[0-9\]+,.*main \(argc.*argv.*\) at .*main.c:.*$prompt $"\
  91.         { pass "run until breakpoint at main" }
  92.     -re ".*$prompt $"       { fail "run until breakpoint at main" }
  93.     timeout                { fail "(timeout) run until breakpoint at main" }
  94.     }
  95.  
  96.  
  97.     # lets do a few single steps
  98.     send "step\n"
  99.     expect {
  100.     -re "char \*execarg = NULL;.*$prompt $" { pass "first single step" }
  101.     -re ".*No such file or directory.\r\n$prompt $" {
  102.         pass "first single step (no source available)"
  103.     }
  104.     -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
  105.         pass "first single step (no source available)"
  106.     }
  107.     -re ".*$prompt $"       { fail "first single step" }
  108.     timeout                { fail "(timeout) first single step" }
  109.     }
  110.  
  111.  
  112.     send "step\n"
  113.     expect {
  114.     -re "char \*corearg = NULL;.*$prompt $" { pass "second single step" }
  115.     -re ".*No such file or directory.\r\n$prompt $" {
  116.         pass "second single step (no source available)"
  117.     }
  118.     -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
  119.         pass "second single step (no source available)"
  120.     }
  121.     -re ".*$prompt $"       { fail "second single step" }
  122.     timeout                { fail "(timeout) second single step" }
  123.     }
  124.  
  125.  
  126.     send "step\n"
  127.     expect {
  128.     -re "char \*cdarg = NULL;.*$prompt $" { pass "third single step" }
  129.     -re ".*No such file or directory.\r\n$prompt $" {
  130.         pass "third step (no source available)"
  131.     }
  132.     -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
  133.         pass "third step (no source available)"
  134.     }
  135.     -re ".*$prompt $"       { fail "third single step" }
  136.     timeout                { fail "(timeout) third single step" }
  137.     }
  138.     
  139.     
  140.     send "step\n"
  141.     expect {
  142.     -re "char \*ttyarg = NULL;.*$prompt $" { pass "forth single step" }
  143.     -re ".*No such file or directory.\r\n$prompt $" {
  144.         pass "fourth single step (no source available)"
  145.     }
  146.     -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
  147.         pass "fourth single step (no source available)"
  148.     }
  149.     -re ".*$prompt $"       { fail "forth single step" }
  150.     timeout                { fail "(timeout) forth single step" }
  151.     }
  152.     
  153.     
  154.     send "step\n"
  155.     expect {
  156.     -re "init_malloc.* NULL.*$prompt $" { pass "fifth single step" }
  157.     -re ".*No such file or directory.\r\n$prompt $" {
  158.         pass "fifth single step (no source available)"
  159.     }
  160.     -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
  161.         pass "fifth single step (no source available)"
  162.     }
  163.     -re ".*$prompt $"       { fail "fifth single step" }
  164.     timeout                { fail "(timeout) fifth single step" }
  165.     }
  166.     
  167.     
  168.     # now jump over a few functions
  169.     send "next\n"
  170.     expect {
  171.     -re "if.*level.*$prompt $" { pass "first next" }
  172.     -re "i = .*count.*$prompt $" { pass "first next" }
  173.     -re ".*No such file or directory.\r\n$prompt $" {
  174.         pass "first next (no source available)"
  175.     }
  176.     -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
  177.         pass "first next (no source available)"
  178.     }
  179.     -re ".*$prompt $"       { fail "first next" }
  180.     timeout                { fail "(timeout) first next" }
  181.     }
  182.     #    -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
  183.     
  184.     
  185.     # This one fails on Solaris (for some versions of gdb) because you
  186.     # can't next over library functions
  187.     setup_xfail "sparc-sun-solaris2" 1817
  188.     # The mips assembler rearranges jumps so that gdb lands in the
  189.     # middle of the next source line and then steps to the next line.
  190.     # We would have to pass -O0 from gcc to mips-as to fix that xfail.
  191.     setup_xfail "mips-*-*"
  192.     set next_ok 1
  193.     send "next\n"
  194.     expect {
  195.     -re "cmdsize = 1;.*$prompt $" { pass "second next" }
  196.     -re "if \(i.*$prompt $" { pass "second next" }
  197.     -re ".*No such file or directory.\r\n$prompt $" {
  198.         pass "second next (no source available)"
  199.     }
  200.     -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
  201.         pass "second next (no source available)"
  202.     }
  203.     -re ".*$prompt $"       { fail "second next"; set next_ok 0 }
  204.     timeout                 { fail "(timeout) second next"; set next_ok 0 }
  205.     }
  206.     
  207.     
  208.     # print something
  209.     # On the RS/6000 malloc is pulled in from a shared library, and gdb
  210.     # doesn't know how to find it.
  211.     setup_xfail "rs6000-*-*"
  212.     # On the Sun4 the value happens to be allocated near the sbrk, and
  213.     # gdb doesn't know how to handle that.
  214.     setup_xfail "sparc-sun-sunos4*" 1823
  215.     send "print \"foo\"\n"
  216.     expect {
  217.     -re ".\[0-9\]+ = 0x\[0-9a-f\]+ \"foo\".*$prompt $"\
  218.                 { pass "print \"foo\"" }
  219.     -re ".*$prompt $"       { fail "print \"foo\"" }
  220.     timeout                { fail "(timeout) print \"foo\"" }
  221.     }
  222.     
  223.     
  224.     # and another step for good luck
  225.     # This one fails on Solaris (for some versions of gdb) because you
  226.     # can't step into library functions
  227.     if $next_ok {
  228.         send "step\n"
  229.         expect {
  230.         -re "cmdarg = .*xmalloc.*$prompt $" { pass "Another single step" }
  231.         -re "if \(setjmp.*$prompt $" { pass "Another single step" }
  232.         -re ".*No such file or directory.\r\n$prompt $" {
  233.             pass "Another single step (no source available)"
  234.         }
  235.         -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
  236.         pass "Another single step (no source available)"
  237.         }
  238.         -re ".*$prompt $"       { fail "Another single step" }
  239.         timeout                { fail "(timeout) Another single step" }
  240.     }
  241.     }
  242.     
  243.     # start the "xgdb" process
  244.     send "continue\n"
  245.     expect {
  246.     -re "GDB is free software and you are welcome to distribute copies of it.*
  247.  under certain conditions; type \"show copying\" to see the conditions..*
  248. There is absolutely no warranty for GDB; type \"show warranty\" for details..*
  249. GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
  250.         { pass "xgdb is at prompt" }
  251.     -re ".*$prompt $"       { fail "xgdb is at prompt" }
  252.     timeout                { fail "(timeout) xgdb is at prompt" }
  253.     }
  254.     
  255.     # set xgdb prompt so we can tell which is which
  256.     send "set prompt (xgdb) \n"
  257.     expect {
  258.     -re "\(xgdb\) $"        { pass "Set xgdb prompt" }
  259.     -re ".*$prompt $"       { fail "Set xgdb prompt" }
  260.     timeout                { fail "(timeout) Set xgdb prompt" }
  261.     }
  262.     
  263.     # kill the xgdb process
  264.     send "\Cc"
  265.     expect {
  266.     -re "Program received signal 2, Interrupt.*$prompt $"   { pass "Sent ^C to xgdb" }
  267.     -re ".*$prompt $"       { fail "Sent ^C to xgdb" }
  268.     timeout                { fail "(timeout) Sent ^C to xgdb" }
  269.     }
  270.     
  271.     send "signal 2\n"
  272.     expect {
  273.     -re "Continuing with signal 2.*$prompt $" { pass "Continuing with  signal 2" }
  274.     -re ".*$prompt $"       { fail "Continuing with  signal 2" }
  275.     timeout                { fail "(timeout) Continuing with  signal 2" }
  276.     }
  277.     
  278.     # get a stack trace
  279.     setup_xfail "rs6000-*-*"
  280.     send "backtrace\n"
  281.     expect {
  282.     -re "#0.*read.*#\[1-9\].*main.c.*$prompt $"\
  283.                 { pass "Got a stack trace" }
  284.     -re ".*$prompt $"       { fail "Got a stack trace" }
  285.     timeout                { fail "(timeout) Got a stack trace" }
  286.     }
  287.     
  288.     # force GDB to dump core.  On Solaris expect seems to not see the
  289.     # final message, even if gdb did dump core, so we check for the
  290.     # core dump explicitly if we time out.
  291.     system rm -f core
  292.     send "maint dump-me\n"
  293.     expect {
  294.     -re "Should GDB dump core\? \(y or n\) $" {
  295.         send "y\n"
  296.         expect {
  297.         -re "Quit.*core dumped.*"    { pass "GDB dumped core" }
  298.         -re "Program received signal 3, Quit.* in kill.*$prompt $" {
  299.             pass "GDB dumped core"
  300.         }
  301.         -re "$prompt $" { fail "GDB dumped core" }
  302.         default { 
  303.             if [file exists core] then {
  304.             pass "GDB dumped core"
  305.             } else {
  306.             fail "GDB dumped core"
  307.             }
  308.         }
  309.         }
  310.     }
  311.     -re ".*$prompt $"       { fail "GDB dumped core" }
  312.     timeout                { fail "(timeout) GDB dumped core" }
  313.     }
  314.     system rm -f core
  315.  
  316.     # Set the timeout back to the value it had when we were called.
  317.     set timeout $oldtimeout
  318.  
  319.     # Restart gdb in case next text expects it to be started already.
  320.     gdb_start
  321.     return 0
  322. }
  323.  
  324. # Find a pathname to a file that we would execute if the shell was asked
  325. # to run $arg using the current PATH.
  326.  
  327. proc find_gdb { arg } {
  328.  
  329.     # If the arg directly specifies an existing executable file, then
  330.     # simply use it.
  331.  
  332.     if [file executable $arg] then {
  333.     return $arg
  334.     }
  335.  
  336.     set result [which $arg]
  337.     if [string match "/" [ string range $result 0 0 ]] then {
  338.     return $result
  339.     }
  340.  
  341.     # If everything fails, just return the unqualified pathname as default
  342.     # and hope for best.
  343.  
  344.     return $arg
  345. }
  346.  
  347. # Run the test with self.
  348. # Copy the file executable file in case this OS doesn't like to edit it's own
  349. # text space.
  350.  
  351. set GDB_FULLPATH [find_gdb $GDB]
  352.  
  353. if ![file executable $GDB_FULLPATH] then {
  354.     fail "couldn't convert $GDB to absolute pathname to make local copy"
  355. } else {
  356.     if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
  357.     fail "couldn't copy $GDB_FULLPATH to current directory"
  358.     } else {
  359.     if $verbose>1 then {
  360.         send_user "\t\tCopied $GDB_FULLPATH to ./x$tool\n"
  361.     }
  362.     if {[test_with_self] <0} then {
  363.         warning "Couldn't test self"
  364.         catch "exec rm -f ./x$tool"
  365.         return -1
  366.     }
  367.     catch "exec rm -f ./x$tool"
  368.     }
  369. }
  370.