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 / udi-gdb.exp < prev    next >
Encoding:
Text File  |  1993-05-12  |  5.2 KB  |  219 lines

  1. # Test Framework Driver
  2. #   Copyright (C) 1988, 1990, 1991, 1992 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 2 of the License, or
  7. # (at your option) any later version.
  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. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  15.  
  16. # Please email any bugs, comments, and/or additions to this file to:
  17. # DejaGnu@cygnus.com
  18.  
  19. # This file was written by Rob Savoye. (rob@cygnus.com)
  20.  
  21. #
  22. # NOTE: these test assume that there is a udi_soc file in th
  23. #
  24.  
  25. # these need to be initialized only if site.exp doesn't set them
  26. set prompt "\(gdb\)"
  27.  
  28. if ![info exists prompt] then {
  29.     set prompt "\(gdb\)"
  30. }
  31.  
  32. #
  33. # gdb_version -- extract and print the version number of gdb
  34. #
  35. proc gdb_version {} {
  36.     global GDB
  37.     global GDBFLAGS
  38.     global prompt
  39.     set tmp [exec echo "q" | $GDB]
  40.     set version [lindex $tmp [lsearch $tmp "\[0-9\]*"]]
  41.     set version [string range $version 0 [expr [string length $version]-2]]
  42.     clone_output "[which $GDB] version $version $GDBFLAGS\n"
  43. }
  44.  
  45. #
  46. # gdb_load -- load a file into the GDB. 
  47. #             Returns a 0 if there was an error,
  48. #                       1 if it load successfully.
  49. #
  50. proc gdb_load { arg } {
  51.     global verbose
  52.     global loadpath
  53.     global loadfile
  54.     global prompt
  55.     global spawn_id
  56.     global GDB
  57.     global expect_out
  58.  
  59.     send "load $arg\n"
  60.     if $verbose>1 then {
  61.     send_user "Loading $arg into $GDB\n"
  62.     }
  63.     expect {
  64.     -re "Loading.*\.text.*\.data.*\.bss.*Reading symbols from $arg.+done.*$prompt $" {
  65.         if $verbose>1 then {
  66.         send_user "Loaded $arg into $GDB\n"
  67.         }
  68.         return 1
  69.     }
  70.     -re "$prompt $"     {
  71.         if $verbose>1 then {
  72.         error "GDB couldn't load."
  73.         }
  74.     }
  75.     timeout {
  76.         if $verbose>1 then {
  77.         error "Timed out trying to load $arg."
  78.         }
  79.     }
  80. }
  81.     if [info exists expect_out(buffer)] then {
  82.     send_log $expect_out(buffer)
  83.     }
  84.     return 0
  85. }
  86.  
  87. #
  88. # gdb_exit -- exit the GDB
  89. #
  90. proc gdb_exit {} {
  91.     global GDB
  92.     global GDBFLAGS
  93.     global verbose
  94.  
  95.     set timeout 5
  96.     send "quit\n"
  97.     expect {
  98.     eof                 { 
  99.         if $verbose>1 then {
  100.         send_user "Got EOF from $GDB\n"
  101.         }
  102.     }
  103.     timeout             { 
  104.         if $verbose>1 then {
  105.         send_user "Got TIMEOUT from $GDB\n"
  106.         }
  107.     }
  108.     -re "The program is running.  Quit anyway? (y or n) $"\
  109.         { send "y\n"
  110.         if $verbose>1 then {
  111.             send_user "\t\tKilling program being debugged\n"
  112.         }
  113.         }
  114.     }
  115.     if $verbose>1 then {
  116.     send_user "Quitting $GDB $GDBFLAGS\n"
  117.     }
  118. }
  119.  
  120. #
  121. # gdb_target_udi
  122. # Set gdb to the desired UDI target
  123. #
  124. proc gdb_target_udi { } {
  125.     global targetname
  126.     global prompt
  127.     global verbose
  128.  
  129.     # set targets hostname
  130.     send "target udi $targetname\n"
  131.     set timeout 60
  132.     expect {
  133.     -re "TIP UDI 1.2 Conformant.*$prompt $"    {
  134.         if $verbose>1 then {
  135.         send_user "Set target to $targetname\n"
  136.         }
  137.     }
  138.     -re "A program is being debugged already.  Kill it\? \(y or n\)" {
  139.         send "y\n"
  140.         continue -expect
  141.     }
  142.     timeout { 
  143.         error "Couldn't set target for UDI."
  144.         alldone
  145.     }
  146.     }
  147.     set timeout 10
  148. }
  149.  
  150. #
  151. # gdb_start -- start GDB running. This assumes that there the
  152. #              UDICONF enviroment variable is set.
  153. #
  154. proc gdb_start { } {
  155.     global GDB
  156.     global GDBFLAGS
  157.     global spawn_id
  158.     global prompt
  159.     global verbose
  160.  
  161.     set GDB [which $GDB]
  162.     # start GDB
  163.     if [ llength $GDBFLAGS ] then {
  164.     spawn $GDB $GDBFLAGS
  165.     } else {
  166.     spawn $GDB
  167.     }
  168.     expect  {
  169.     -re "GDB.*$prompt $"   {
  170.         if $verbose>1 then {
  171.         send_user "$GDB initialized for cross mode\n\n"
  172.         }
  173.     }
  174.     -re "$prompt $"     { error "GDB never initialized."; return -1 }
  175.     timeout             { error "(timeout) GDB never initialized.";
  176.         return -1 }
  177.     }
  178.  
  179.     # force the height to "unlimited", so no pagers get used
  180.     send "set height 0\n"
  181.     expect -re ".*$prompt $" {}
  182.     # force the width to "unlimited", so no wraparound occurs
  183.     send "set width 0\n"
  184.     expect -re ".*$prompt $" {}
  185.     # set the default arguments to "main", so that "run" with no
  186.     # arguments will work correctly.
  187.     send "set args main\n"
  188.     expect -re ".*$prompt $" {}
  189.  
  190.     if $verbose>1 then {
  191.     send_user "Setting up target, Please wait...\n"
  192.     }
  193.  
  194.     gdb_target_udi
  195. }
  196.  
  197. expect_after {
  198.     "<return>"           { send "\n"; clone_output "ERROR: Window too small." }
  199.     -re "\(y or n\) "        { send "n\n"; error "Got interactive prompt." }
  200.     buffer_full           { error "internal buffer is full." }
  201.     eof               { error "eof -- pty is hosed." }
  202.     timeout               { error "timeout." }
  203.     "virtual memory exhausted" { error "virtual memory exhausted." }
  204.     "Undefined command"       { error "send string probably wrong." }
  205. }
  206.  
  207. load_lib gdb.exp
  208.  
  209. gdb_start
  210.  
  211. # make sure gdb has actually started, otherwise if the first test
  212. # timesout, DejaGnu crashes
  213. send "\n"
  214. expect {
  215.     -re "$prompt"
  216.     }
  217.