home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / testsuite / lib / gdb.exp next >
Encoding:
Text File  |  1993-05-12  |  6.6 KB  |  257 lines

  1. # Copyright (C) 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 Fred Fish. (fnf@cygnus.com)
  19.  
  20. # Generic gdb subroutines that should work for any target.  If these
  21. # need to be modified for any target, it can be done with a variable
  22. # or by passing arguments.
  23.  
  24. #
  25. # gdb_unload -- unload a file if one is loaded
  26. #
  27.  
  28. proc gdb_unload {} {
  29.     global verbose
  30.     global GDB
  31.     global prompt
  32.     send "file\n"
  33.     expect {
  34.     -re "No exec file now\.\r" { continue -expect }
  35.     -re "No symbol file now\.\r" { continue -expect }
  36.     -re "A program is being debugged already..*Kill it\? \(y or n\) $"\
  37.         { send "y\n"
  38.         if $verbose>1 then {
  39.             send_user "\t\tKilling previous program being debugged\n"
  40.         }
  41.         continue -expect
  42.     }
  43.     -re "Discard symbol table from .*\? \(y or n\) $" {
  44.         send "y\n"
  45.         continue -expect
  46.     }
  47.     -re "$prompt $" {}
  48.     timeout {
  49.         error "couldn't unload file in $GDB (timed out)."
  50.         return -1
  51.     }
  52.     }
  53. }
  54.  
  55. # Many of the tests depend on setting breakpoints at various places and
  56. # running until that breakpoint is reached.  At times, we want to start
  57. # with a clean-slate with respect to breakpoints, so this utility proc 
  58. # lets us do this without duplicating this code everywhere.
  59. #
  60.  
  61. proc delete_breakpoints {} {
  62.     global prompt
  63.  
  64.     send "delete breakpoints\n"
  65.     expect {
  66.     -re "Delete all breakpoints\? \(y or n\) $" {
  67.         send "y\n"
  68.         continue -expect
  69.     }
  70.     -re "y\r\n$prompt $" {}
  71.     -re ".*$prompt $" { fail "Delete all breakpoints" ; return }
  72.     timeout { fail "Delete all breakpoints (timeout)" ; return }
  73.     }
  74.     send "info breakpoints\n"
  75.     expect {
  76.     -re "No breakpoints or watchpoints..*$prompt $" {}
  77.     -re ".*$prompt $" { fail "breakpoints not deleted" ; return }
  78.     timeout { fail "info breakpoints (timeout)" ; return }
  79.     }
  80. }
  81.  
  82.  
  83. #
  84. # Set breakpoint at function and run gdb until it breaks there.
  85. # Since this is the only breakpoint that will be set, if it stops
  86. # at a breakpoint, we will assume it is the one we want.  We can't
  87. # just compare to "function" because it might be a fully qualified,
  88. # single quoted C++ function specifier.
  89. #
  90.  
  91. proc runto { function } {
  92.     global prompt
  93.     global decimal
  94.  
  95.     send "delete\n"
  96.     expect {
  97.     -re "Delete all breakpoints\? \(y or n\) $" {
  98.         send "y\n"
  99.         expect {
  100.         -re "$prompt $" {}
  101.         timeout { fail "deleting breakpoints (timeout)" ; return 0 }
  102.         }
  103.     }
  104.     -re ".*$prompt $" {}
  105.     timeout { fail "deleting breakpoints (timeout)" ; return 0 }
  106.     }
  107.  
  108.     send "break $function\n"
  109.     expect {
  110.     -re "Break.* at .*: file .*, line $decimal.\r\n$prompt $" {}
  111.     -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 }
  112.     timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
  113.     }
  114.  
  115.     send "run\n"
  116.     expect {
  117.     -re "The program .* has been started already.* \(y or n\) $" {
  118.         send "y\n"
  119.         continue -expect
  120.     }
  121.     -re "Starting.*Break.* at .*:$decimal.*$prompt $" { return 1 }
  122.     -re "$prompt $" { fail "running to $function" ; return 0 }
  123.     timeout { fail "running to $function (timeout)" ; return 0 }
  124.     }
  125. }
  126.  
  127. #
  128. # gdb_test -- send a command to gdb and test the result.
  129. #             Takes three parameters.
  130. #             Parameters:
  131. #                First one is the command to execute,
  132. #                Second one is the pattern to match for a PASS,
  133. #                Third one is an optional message to be printed. If this
  134. #                  a null string "", then the pass/fail messages are not printed.
  135. #             Returns:
  136. #                1 if the test failed,
  137. #                0 if the test passes,
  138. #               -1 if there was an internal error.
  139. #
  140. proc gdb_test { args } {
  141.     global verbose
  142.     global prompt
  143.     global GDB
  144.     global spawn_id
  145.  
  146.     if [llength $args]==3 then {
  147.     set message [lindex $args 2]
  148.     } else {
  149.     set message [lindex $args 0]
  150.     }
  151.     set command [lindex $args 0]
  152.     set pattern [lindex $args 1]
  153.  
  154.     if $verbose>2 then {
  155.     send_user "Sending \"$command\" to gdb\n"
  156.     send_user "Looking to match \"$pattern\"\n"
  157.     send_user "Message is \"$message\"\n"
  158.     }
  159.  
  160.     set result -1
  161.     set errmess ""
  162.     # trap the send so any problems don't crash things
  163.     catch "send \"$command\n\"" errmess
  164.     if [string match "write\(spawn_id=\[0-9\]+\):" $errmess] then {
  165.     error "sent \"$command\" got expect error \"$errmess\""
  166.     catch "close"
  167.     gdb_start
  168.     return -1
  169.     }
  170.  
  171.     expect {
  172.     -re ".*Ending remote debugging.*$prompt$" {
  173.         if ![isnative] then {
  174.         warning "Can`t communicate to remote target."
  175.         }
  176.         gdb_exit
  177.         gdb_start
  178.         set result -1
  179.     }
  180.     -re "$pattern.*$prompt $" {
  181.         if ![string match "" $message] then {
  182.         pass "$message"
  183.         }
  184.         set result 0
  185.     }
  186.     -re "Undefined command:.*$prompt" {
  187.         error "Undefined command \"$command\"."
  188.         set result 1
  189.     }
  190.     -re "Ambiguous command.*$prompt $" {
  191.         error "\"$command\" is not a unique command name."
  192.         set result 1
  193.     }
  194.     -re ".*$prompt $" {
  195.         if ![string match "" $message] then {
  196.         fail "$message"
  197.         }
  198.         set result 1
  199.     }
  200.     "<return>" {
  201.         send "\n"
  202.         error "Window too small."
  203.     }
  204.     -re "\(y or n\) " {
  205.         send "n\n"
  206.         error "Got interactive prompt."
  207.     }
  208.     eof {
  209.         error "Process no longer exists"
  210.         return -1
  211.     }
  212.     buffer_full {
  213.         error "internal buffer is full."
  214.     }
  215.     timeout    {
  216.         fail "(timeout) $message"
  217.         set result 1
  218.     }
  219.     }
  220.     return $result
  221. }
  222.  
  223. proc gdb_reinitialize_dir { subdir } {
  224.     global prompt
  225.     global verbose
  226.  
  227.     send "dir\n"
  228.     expect {
  229.     -re "Reinitialize source path to empty.*" {
  230.         send "y\n"
  231.         expect {
  232.         -re "Source directories searched.*$prompt $" {
  233.             send "dir $subdir\n"
  234.             expect {
  235.             -re "Source directories searched.*$prompt $" {
  236.                 if $verbose>1 then {
  237.                 send_user "Dir set to $subdir\n"
  238.                 }
  239.             }
  240.             -re ".*$prompt $" {
  241.                 error "Dir \"$subdir\" failed."
  242.             }
  243.             }
  244.         }
  245.         -re ".*$prompt $" {
  246.             error "Dir \"$subdir\" failed."
  247.         }
  248.         }
  249.     }
  250.     -re ".*$prompt $" {
  251.         error "Dir \"$subdir\" failed."
  252.     }
  253.     }
  254. }
  255.