68c1a729cf39936d53d77f25c92c583dfbd2e26f
[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 # bug-gdb@prep.ai.mit.edu
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 if {[which $GDB] != 0} then {
43 set tmp [exec echo "q" | $GDB]
44 set version "[lindex $tmp [lsearch $tmp "\[0-9\]*"]]"
45 set version "[string range $version 0 [expr [string length $version]-2]]"
46 clone_output "[which $GDB] version $version $GDBFLAGS\n"
47 } else {
48 warning "$GDB does not exist"
49 }
50 }
51
52 #
53 # gdb_unload -- unload a file if one is loaded
54 #
55
56 proc gdb_unload {} {
57 global verbose
58 global GDB
59 global prompt
60 send "file\n"
61 expect {
62 -re "No exec file now\.\r" { continue -expect }
63 -re "No symbol file now\.\r" { continue -expect }
64 -re "A program is being debugged already..*Kill it\? \(y or n\) $"\
65 { send "y\n"
66 if $verbose>1 then {
67 send_user "\t\tKilling previous program being debugged\n"
68 }
69 continue -expect
70 }
71 -re "Discard symbol table from .*\? \(y or n\) $" {
72 send "y\n"
73 continue -expect
74 }
75 -re "$prompt $" {}
76 timeout {
77 error "Couldn't unload file in $GDB (timed out)."
78 return -1
79 }
80 }
81 }
82
83 #
84 # gdb_load -- load a file into the debugger.
85 # return a -1 if anything goes wrong.
86 #
87 proc gdb_load { arg } {
88 global verbose
89 global loadpath
90 global loadfile
91 global GDB
92 global prompt
93
94 set loadfile [file tail $arg]
95 set loadpath [file dirname $arg]
96 send "file $arg\n"
97 expect {
98 -re "Reading symbols from.*done.*$prompt $" {
99 if $verbose>1 then {
100 send_user "\t\tLoaded $arg into the $GDB\n"
101 }
102 return 0
103 }
104 -re "has no symbol-table.*$prompt $" {
105 error "$arg wasn't compiled with \"-g\""
106 return -1
107 }
108 -re "A program is being debugged already..*Kill it\? \(y or n\) $" {
109 send "y\n"
110 if $verbose>1 then {
111 send_user "\t\tKilling previous program being debugged\n"
112 }
113 continue -expect
114 }
115 -re "Load new symbol table from.*\? \(y or n\) $" {
116 send "y\n"
117 expect {
118 -re "Reading symbols from.*done.*$prompt $" {
119 if $verbose>1 then {
120 send_user "\t\tLoaded $arg with new symbol table into $GDB\n"
121 }
122 return 0
123 }
124 timeout {
125 error "(timeout) Couldn't load $arg, other program already loaded."
126 return -1
127 }
128 }
129 }
130 -re ".*No such file or directory.*$prompt $" {
131 error "($arg) No such file or directory\n"
132 return -1
133 }
134 -re "$prompt $" {
135 error "couldn't load $arg into $GDB."
136 return -1
137 }
138 timeout {
139 error "couldn't load $arg into $GDB (timed out)."
140 return -1
141 }
142 eof {
143 # This is an attempt to detect a core dump, but seems not to
144 # work. Perhaps we need to match .* followed by eof, in which
145 # expect does not seem to have a way to do that.
146 error "couldn't load $arg into $GDB (end of file)."
147 return -1
148 }
149 }
150 }
151
152 #
153 # gdb_exit -- kills the gdb process currently running
154 #
155 # This overrides the generic version of gdb_exit in lib/gdb.exp, since
156 # it's doing a lot of wierd stuff that lib/gdb.exp isn't.
157 # FIXME, fold it in, or abandon this version.
158
159 proc gdb_exit {} {
160 global verbose
161 global GDB
162 global GDBFLAGS
163 set timeout 1
164
165 if $verbose>1 then {
166 send_user "Quitting $GDB $GDBFLAGS\n"
167 }
168 catch "send \"quit\n\"" result
169 if [string match "write\(spawn_id=\[0-9\]+\):" $result] then {
170 catch "close"
171 return -1
172 }
173 catch {
174 expect {
175 eof {
176 if $verbose>1 then {
177 send_user "Got EOF from $GDB\n"
178 }
179 }
180 timeout {
181 if $verbose>1 then {
182 send_user "Got TIMEOUT from $GDB\n"
183 }
184 close
185 }
186 -re "The program is running. Quit anyway.*? (y or n) $" {
187 send "y\n"
188 if $verbose>1 then {
189 send_user "\t\tKilling program being debugged\n"
190 }
191 close
192 }
193 }
194 }
195 catch "close"
196 # Before this was here sometimes "uit" would get sent to the next GDB
197 # (assuming this is immediately followed by gdb_start), which would
198 # cause a loss of syncronization (i.e. all the stuff that swallows a
199 # prompt would swallow the wrong one).
200 wait
201
202 if $verbose>1 then {
203 send_user "Quitting $GDB $GDBFLAGS\n"
204 }
205 }
206
207 #
208 # start gdb -- start gdb running
209 #
210
211 proc gdb_start {} {
212 global verbose
213 global GDB
214 global GDBFLAGS
215 global prompt
216 global spawn_id
217 global timeout
218 if $verbose>1 then {
219 send_user "Spawning $GDB $GDBFLAGS\n"
220 }
221
222 set oldtimeout $timeout
223 set timeout [expr "$timeout + 60"]
224 if [ llength $GDBFLAGS ] then {
225 if {[which $GDB] != 0} then {
226 spawn $GDB $GDBFLAGS
227 } else {
228 error "$GDB does not exist."
229 exit 1
230 }
231 } else {
232 IF {[WHICH $GDB] != 0} then {
233 spawn $GDB
234 } else {
235 error "$GDB does not exist."
236 exit 1
237 }
238 }
239 expect {
240 -re ".*$prompt $" {
241 if $verbose>1 then {
242 send_user "GDB initialized for native mode\n"
243 }
244 }
245 -re "$prompt $" {
246 error "GDB never initialized."
247 return -1
248 }
249 timeout {
250 error "(timeout) GDB never initialized."
251 return -1
252 }
253 }
254 set timeout $oldtimeout
255 # force the height to "unlimited", so no pagers get used
256 send "set height 0\n"
257 expect {
258 -re ".*$prompt $" {
259 if $verbose>2 then {
260 send_user "Seting height to 0.\n"
261 }
262 }
263 timeout {
264 warning "Couldn't set the height to 0."
265 }
266 }
267 # force the width to "unlimited", so no wraparound occurs
268 send "set width 0\n"
269 expect {
270 -re ".*$prompt $" {
271 if $verbose>2 then {
272 send_user "Seting width to 0.\n"
273 }
274 }
275 timeout {
276 warning "Couldn't set the width to 0."
277 }
278 }
279 }
280
281 # These only need to be uncommented for debugging test cases. They exist
282 # mainly to catch programming errors
283 #expect_after {
284 # "<return>" { send "\n"; error "Window too small." }
285 # -re "\(y or n\) " { send "n\n"; error "Got interactive prompt." }
286 # buffer_full { error "internal buffer is full." }
287 # eof { error "eof -- there is no child process" ; cleanup ; exit $exit_status}
288 # timeout { error "timeout." }
289 # "virtual memory exhausted" { error "virtual memory exhausted." }
290 # "Undefined command" { error "send string probably wrong." }
291 #}
292
293 load_lib gdb.exp
294
295 set binpath /s1/users/rob/vxworks/bin/somewhere-bogus-that-needs-configuring
296 set bin $GDB
297
298 gdb_start
299
300
301
302
303
304
305
This page took 0.036057 seconds and 3 git commands to generate.