* gdb/testsuite: Initial creation of gdb/testsuite.
[deliverable/binutils-gdb.git] / gdb / testsuite / config / unix-gdb.exp
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 #
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 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # DejaGnu@cygnus.com
19
20 # This file was written by Rob Savoye. (rob@cygnus.com)
21
22 # variables that need to set up
23 #
24 if ![info exists prompt] then {
25 set prompt "\(gdb\)"
26 }
27 # some convenience abbreviations
28 #
29 if ![info exists hex] then {
30 set hex "0x\[0-9A-Fa-f\]+"
31 }
32 if ![info exists decimal] then {
33 set decimal "\[0-9\]+"
34 }
35
36 #
37 # gdb_version -- extract and print the version number of gcc
38 #
39 proc gdb_version {} {
40 global GDB
41 global GDBFLAGS
42 set tmp [exec echo "q" | $GDB]
43 set version [lindex $tmp [lsearch $tmp "\[0-9\]*"]]
44 set version [string range $version 0 [expr [string length $version]-2]]
45 clone_output "[which $GDB] version $version $GDBFLAGS\n"
46 }
47
48 #
49 # gdb_unload -- unload a file if one is loaded
50 #
51
52 proc gdb_unload {} {
53 global verbose
54 global GDB
55 global prompt
56 send "file\n"
57 expect {
58 -re "No exec file now\.\r" { continue -expect }
59 -re "No symbol file now\.\r" { continue -expect }
60 -re "A program is being debugged already..*Kill it\? \(y or n\) $"\
61 { send "y\n"
62 if $verbose>1 then {
63 send_user "\t\tKilling previous program being debugged\n"
64 }
65 continue -expect
66 }
67 -re "Discard symbol table from .*\? \(y or n\) $" {
68 send "y\n"
69 continue -expect
70 }
71 -re "$prompt $" {}
72 timeout {
73 error "Couldn't unload file in $GDB (timed out)."
74 alldone
75 }
76 }
77 }
78
79 #
80 # gdb_load -- load a file into the debugger.
81 #
82 proc gdb_load { arg } {
83 global verbose
84 global loadpath
85 global loadfile
86 global GDB
87 global prompt
88
89 set loadfile [file tail $arg]
90 set loadpath [file dirname $arg]
91 send "directory\n"
92 expect {
93 -re "Reinitialize source path to empty\? \(y or n\) $"\
94 { send "y\n"
95 expect {
96 -re "$prompt $" {}
97 timeout { fail "(timeout) reset directory path" ; return }
98 }
99 }
100 timeout { fail "(timeout) reset directory path" ; return }
101 }
102 send "directory $loadpath\n"
103 expect -re "$prompt $" {}
104 send "file $arg\n"
105 expect {
106 -re "Reading symbols from.*done.*$prompt $"\
107 { if $verbose>1 then {
108 send_user "\t\tLoaded $arg into the $GDB\n"
109 }
110 }
111 -re "has no symbol-table.*$prompt $" {
112 error "$arg wasn't compiled with \"-g\"\n"
113 return -1
114 }
115 -re "A program is being debugged already..*Kill it\? \(y or n\) $"\
116 { send "y\n"
117 if $verbose>1 then {
118 send_user "\t\tKilling previous program being debugged\n"
119 }
120 continue -expect
121 }
122 -re "Load new symbol table from.*\? \(y or n\) $"\
123 { send "y\n"
124 expect {
125 -re "Reading symbols from.*done.*$prompt $"
126 { if $verbose>1 then {
127 send_user "\t\tLoaded $arg with new symbol table into $GDB\n"
128 }
129 }
130 timeout { error "(timeout) Couldn't load $arg, other program already loaded."; alldone }
131 }
132 }
133 -re ".*No such file or directory.*$prompt $"\
134 { error "($arg) No such file or directory\n"; alldone }
135 -re "$prompt $" { error "couldn't load $arg into $GDB."; alldone }
136 timeout { error "couldn't load $arg into $GDB (timed out)."; alldone }
137 }
138 }
139
140 #
141 # gdb_exit -- kills the gdb process currently running
142 #
143 proc gdb_exit {} {
144 global verbose
145 global GDB
146 global GDBFLAGS
147 set timeout 1
148
149 catch "send \"quit\n\"" result
150 if [string match "write\(spawn_id=\[0-9\]+\): Bad file number" $result] then {
151 close
152 return 0
153 }
154 expect {
155 eof {
156 if $verbose>1 then {
157 send_user "Got EOF from $GDB\n"
158 }
159 }
160 timeout {
161 if $verbose>1 then {
162 send_user "Got TIMEOUT from $GDB\n"
163 }
164 }
165 -re "The program is running. Quit anyway? (y or n) $"\
166 { send "y\n"
167 if $verbose>1 then {
168 send_user "\t\tKilling program being debugged\n"
169 }
170 }
171 }
172
173 close
174
175 if $verbose>1 then {
176 send_user "Quitting $GDB $GDBFLAGS\n"
177 }
178 }
179
180 #
181 # start gdb -- start gdb running
182 #
183
184 proc gdb_start {} {
185 global verbose
186 global GDB
187 global GDBFLAGS
188 global prompt
189 global spawn_id
190 global timeout
191 if $verbose>1 then {
192 send_user "Spawning $GDB $GDBFLAGS\n"
193 }
194
195 set oldtimeout $timeout
196 set timeout [expr "$timeout + 60"]
197 if [ llength $GDBFLAGS ] then {
198 spawn $GDB $GDBFLAGS
199 } else {
200 spawn $GDB
201 }
202 expect {
203 -re ".*$prompt $" { if $verbose>1 then {
204 send_user "GDB initialized for native mode\n" }
205 }
206 -re "$prompt $" { error "GDB never initialized."; alldone }
207 timeout { error "(timeout) GDB never initialized."; alldone }
208 }
209 set timeout $oldtimeout
210 # force the height to "unlimited", so no pagers get used
211 send "set height 0\n"
212 expect -re ".*$prompt $" {}
213 # force the width to "unlimited", so no wraparound occurs
214 send "set width 0\n"
215 expect -re ".*$prompt $" {}
216 }
217
218 expect_after {
219 "<return>" { send "\n"; error "Window too small." }
220 -re "\(y or n\) " { send "n\n"; error "Got interactive prompt." }
221 buffer_full { error "internal buffer is full." }
222 eof { error "eof -- pty is hosed." }
223 timeout { error "timeout." }
224 "virtual memory exhausted" { error "virtual memory exhausted." }
225 "Undefined command" { error "send string probably wrong." }
226 }
227
228 load_lib gdb.exp
229
230 set binpath /s1/users/rob/vxworks/bin/somewhere-bogus-that-needs-configuring
231 set bin $GDB
232
233 gdb_start
234
This page took 0.058562 seconds and 4 git commands to generate.