home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / testsuite / config / unix-gdb.exp < prev    next >
Encoding:
Text File  |  1993-05-12  |  6.5 KB  |  290 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. # variables that need to set up
  21. #
  22. if ![info exists prompt] then {
  23.     set prompt "\(gdb\)"
  24. }
  25. # some convenience abbreviations
  26. #
  27. if ![info exists hex] then {
  28.     set hex "0x\[0-9A-Fa-f\]+"
  29. }
  30. if ![info exists decimal] then {
  31.     set decimal "\[0-9\]+"
  32. }
  33.  
  34. #
  35. # gdb_version -- extract and print the version number of gcc
  36. #
  37. proc gdb_version {} {
  38.     global GDB
  39.     global GDBFLAGS
  40.     if {[which $GDB] != 0} then {
  41.     set tmp [exec echo "q" | $GDB]
  42.     set version "[lindex $tmp [lsearch $tmp "\[0-9\]*"]]"
  43.     set version "[string range $version 0 [expr [string length $version]-2]]"
  44.     clone_output "[which $GDB] version $version $GDBFLAGS\n"
  45.     } else {
  46.     warning "$GDB does not exist"
  47. }
  48. }
  49.  
  50. #
  51. # gdb_unload -- unload a file if one is loaded
  52. #
  53.  
  54. proc gdb_unload {} {
  55.     global verbose
  56.     global GDB
  57.     global prompt
  58.     send "file\n"
  59.     expect {
  60.     -re "No exec file now\.\r" { continue -expect }
  61.     -re "No symbol file now\.\r" { continue -expect }
  62.     -re "A program is being debugged already..*Kill it\? \(y or n\) $"\
  63.         { send "y\n"
  64.         if $verbose>1 then {
  65.             send_user "\t\tKilling previous program being debugged\n"
  66.         }
  67.         continue -expect
  68.     }
  69.     -re "Discard symbol table from .*\? \(y or n\) $" {
  70.         send "y\n"
  71.         continue -expect
  72.     }
  73.     -re "$prompt $" {}
  74.     timeout {
  75.         error "Couldn't unload file in $GDB (timed out)."
  76.         return -1
  77.     }
  78.     }
  79. }
  80.  
  81. #
  82. # gdb_load -- load a file into the debugger.
  83. #             return a -1 if anything goes wrong.
  84. #
  85. proc gdb_load { arg } {
  86.     global verbose
  87.     global loadpath
  88.     global loadfile
  89.     global GDB
  90.     global prompt
  91.  
  92.     set loadfile [file tail $arg]
  93.     set loadpath [file dirname $arg]
  94.     send "file $arg\n"
  95.     expect {
  96.     -re "Reading symbols from.*done.*$prompt $" {
  97.         if $verbose>1 then {
  98.         send_user "\t\tLoaded $arg into the $GDB\n"
  99.         }
  100.         return 0
  101.     }
  102.     -re "has no symbol-table.*$prompt $" {
  103.         error "$arg wasn't compiled with \"-g\""
  104.         return -1
  105.     }
  106.     -re "A program is being debugged already..*Kill it\? \(y or n\) $" {
  107.         send "y\n"
  108.         if $verbose>1 then {
  109.             send_user "\t\tKilling previous program being debugged\n"
  110.         }
  111.         continue -expect
  112.     }
  113.     -re "Load new symbol table from.*\? \(y or n\) $" {
  114.         send "y\n"
  115.         expect {
  116.         -re "Reading symbols from.*done.*$prompt $" {
  117.             if $verbose>1 then {
  118.             send_user "\t\tLoaded $arg with new symbol table into $GDB\n"
  119.         }
  120.             return 0
  121.         }
  122.         timeout    {
  123.             error "(timeout) Couldn't load $arg, other program already loaded."
  124.             return -1
  125.         }
  126.         }
  127.         }
  128.     -re ".*No such file or directory.*$prompt $" {
  129.         error "($arg) No such file or directory\n"
  130.         return -1
  131.     }
  132.     -re "$prompt $" {
  133.         error "couldn't load $arg into $GDB."
  134.         return -1
  135.         }
  136.     timeout    {
  137.         error "couldn't load $arg into $GDB (timed out)."
  138.         return -1
  139.     }
  140.     }
  141. }
  142.  
  143. #
  144. # gdb_exit -- kills the gdb process currently running
  145. #
  146. proc gdb_exit {} {
  147.     global verbose
  148.     global GDB
  149.     global GDBFLAGS
  150.     set timeout 1
  151.  
  152.     if $verbose>1 then {
  153.     send_user "Quitting $GDB $GDBFLAGS\n"
  154.     }    
  155.     catch "send \"quit\n\"" result
  156.     if [string match "write\(spawn_id=\[0-9\]+\):" $result] then {
  157.     catch "close"
  158.     return -1
  159.     }
  160.     catch {
  161.     expect {
  162.     eof                 { 
  163.         if $verbose>1 then {
  164.         send_user "Got EOF from $GDB\n"
  165.         }
  166.     }
  167.     timeout             { 
  168.         if $verbose>1 then {
  169.         send_user "Got TIMEOUT from $GDB\n"
  170.         }
  171.         close
  172.     }
  173.         -re "The program is running.  Quit anyway? (y or n) $" {
  174.         send "y\n"
  175.         if $verbose>1 then {
  176.             send_user "\t\tKilling program being debugged\n"
  177.         }
  178.             close
  179.         }
  180.     }
  181.     }
  182.     catch "close"
  183.  
  184.     if $verbose>1 then {
  185.     send_user "Quitting $GDB $GDBFLAGS\n"
  186.     }    
  187. }
  188.  
  189. #
  190. # start gdb -- start gdb running
  191. #
  192.  
  193. proc gdb_start {} {
  194.     global verbose
  195.     global GDB
  196.     global GDBFLAGS
  197.     global prompt
  198.     global spawn_id
  199.     global timeout
  200.     if $verbose>1 then {
  201.     send_user "Spawning $GDB $GDBFLAGS\n"
  202.     }
  203.  
  204.     set oldtimeout $timeout
  205.     set timeout [expr "$timeout + 60"]
  206.     if [ llength $GDBFLAGS ] then {
  207.     if {[which $GDB] != 0} then {
  208.     spawn $GDB $GDBFLAGS
  209.     } else {
  210.         error "$GDB does not exist."
  211.         exit 1
  212.     }
  213.     } else {
  214.     IF {[WHICH $GDB] != 0} then {
  215.     spawn $GDB
  216.     } else {
  217.         error "$GDB does not exist."
  218.         exit 1
  219.     }
  220.     }
  221.     expect {
  222.     -re ".*$prompt $"    {
  223.         if $verbose>1 then {
  224.         send_user "GDB initialized for native mode\n"
  225.     }
  226.     }
  227.     -re "$prompt $"    {
  228.         error "GDB never initialized."
  229.         return -1
  230.     }
  231.     timeout        {
  232.         error "(timeout) GDB never initialized."
  233.         return -1
  234.     }
  235.     }
  236.     set timeout $oldtimeout
  237.     # force the height to "unlimited", so no pagers get used
  238.     send "set height 0\n"
  239.     expect {
  240.     -re ".*$prompt $" { 
  241.         if $verbose>2 then {
  242.         send_user "Seting height to 0.\n"
  243.         }
  244.     }
  245.     timeout {
  246.         warning "Couldn't set the height to 0."
  247.     }
  248.     }
  249.     # force the width to "unlimited", so no wraparound occurs
  250.     send "set width 0\n"
  251.     expect {
  252.     -re ".*$prompt $" {
  253.         if $verbose>2 then {
  254.         send_user "Seting width to 0.\n"
  255. }
  256.     }
  257.     timeout {
  258.         warning "Couldn't set the width to 0."
  259. }
  260.     }
  261. }
  262.  
  263. # These only need to be uncommented for debugging test cases. They exist
  264. # mainly to catch programming errors
  265. #expect_after {
  266. #    "<return>"           { send "\n"; error "Window too small." }
  267. #    -re "\(y or n\) "        { send "n\n"; error "Got interactive prompt." }
  268. #    buffer_full           { error "internal buffer is full." }
  269. #    eof               { error "eof -- there is no child process" ; alldone}
  270. #    timeout               { error "timeout." }
  271. #    "virtual memory exhausted" { error "virtual memory exhausted." }
  272. #    "Undefined command"       { error "send string probably wrong." }
  273. #}
  274.  
  275. load_lib gdb.exp
  276.  
  277. set binpath /s1/users/rob/vxworks/bin/somewhere-bogus-that-needs-configuring
  278. set bin $GDB
  279.  
  280. gdb_start
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.