Make sure $GDB contains a real program.
[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-dejagnu@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 }
103 -re "has no symbol-table.*$prompt $" {
104 error "$arg wasn't compiled with \"-g\""
105 return -1
106 }
107 -re "A program is being debugged already..*Kill it\? \(y or n\) $" {
108 send "y\n"
109 if $verbose>1 then {
110 send_user "\t\tKilling previous program being debugged\n"
111 }
112 continue -expect
113 }
114 -re "Load new symbol table from.*\? \(y or n\) $" {
115 send "y\n"
116 expect {
117 -re "Reading symbols from.*done.*$prompt $" {
118 if $verbose>1 then {
119 send_user "\t\tLoaded $arg with new symbol table into $GDB\n"
120 }
121 return 0
122 }
123 timeout {
124 error "(timeout) Couldn't load $arg, other program already loaded."
125 return -1
126 }
127 }
128 }
129 -re ".*No such file or directory.*$prompt $" {
130 error "($arg) No such file or directory\n"
131 return -1
132 }
133 -re "$prompt $" {
134 error "couldn't load $arg into $GDB."
135 return -1
136 }
137 timeout {
138 error "couldn't load $arg into $GDB (timed out)."
139 return -1
140 }
141 }
142 }
143
144 #
145 # gdb_exit -- kills the gdb process currently running
146 #
147 proc gdb_exit {} {
148 global verbose
149 global GDB
150 global GDBFLAGS
151 set timeout 1
152
153 if $verbose>1 then {
154 send_user "Quitting $GDB $GDBFLAGS\n"
155 }
156 catch "send \"quit\n\"" result
157 if [string match "write\(spawn_id=\[0-9\]+\):" $result] then {
158 catch "close"
159 return -1
160 }
161 catch {
162 expect {
163 eof {
164 if $verbose>1 then {
165 send_user "Got EOF from $GDB\n"
166 }
167 }
168 timeout {
169 if $verbose>1 then {
170 send_user "Got TIMEOUT from $GDB\n"
171 }
172 close
173 }
174 -re "The program is running. Quit anyway? (y or n) $" {
175 send "y\n"
176 if $verbose>1 then {
177 send_user "\t\tKilling program being debugged\n"
178 }
179 close
180 }
181 }
182 }
183 catch "close"
184
185 if $verbose>1 then {
186 send_user "Quitting $GDB $GDBFLAGS\n"
187 }
188 }
189
190 #
191 # start gdb -- start gdb running
192 #
193
194 proc gdb_start {} {
195 global verbose
196 global GDB
197 global GDBFLAGS
198 global prompt
199 global spawn_id
200 global timeout
201 if $verbose>1 then {
202 send_user "Spawning $GDB $GDBFLAGS\n"
203 }
204
205 set oldtimeout $timeout
206 set timeout [expr "$timeout + 60"]
207 if [ llength $GDBFLAGS ] then {
208 if {[which $GDB] != 0} then {
209 spawn $GDB $GDBFLAGS
210 } else {
211 error "$GDB does not exist."
212 exit 1
213 }
214 } else {
215 IF {[WHICH $GDB] != 0} then {
216 spawn $GDB
217 } else {
218 error "$GDB does not exist."
219 exit 1
220 }
221 }
222 expect {
223 -re ".*$prompt $" {
224 if $verbose>1 then {
225 send_user "GDB initialized for native mode\n"
226 }
227 }
228 -re "$prompt $" {
229 error "GDB never initialized."
230 return -1
231 }
232 timeout {
233 error "(timeout) GDB never initialized."
234 return -1
235 }
236 }
237 set timeout $oldtimeout
238 # force the height to "unlimited", so no pagers get used
239 send "set height 0\n"
240 expect {
241 -re ".*$prompt $" {
242 if $verbose>2 then {
243 send_user "Seting height to 0.\n"
244 }
245 }
246 timeout {
247 warning "Couldn't set the height to 0."
248 }
249 }
250 # force the width to "unlimited", so no wraparound occurs
251 send "set width 0\n"
252 expect {
253 -re ".*$prompt $" {
254 if $verbose>2 then {
255 send_user "Seting width to 0.\n"
256 }
257 }
258 timeout {
259 warning "Couldn't set the width to 0."
260 }
261 }
262 }
263
264 # These only need to be uncommented for debugging test cases. They exist
265 # mainly to catch programming errors
266 #expect_after {
267 # "<return>" { send "\n"; error "Window too small." }
268 # -re "\(y or n\) " { send "n\n"; error "Got interactive prompt." }
269 # buffer_full { error "internal buffer is full." }
270 # eof { error "eof -- there is no child process" ; alldone}
271 # timeout { error "timeout." }
272 # "virtual memory exhausted" { error "virtual memory exhausted." }
273 # "Undefined command" { error "send string probably wrong." }
274 #}
275
276 load_lib gdb.exp
277
278 set binpath /s1/users/rob/vxworks/bin/somewhere-bogus-that-needs-configuring
279 set bin $GDB
280
281 gdb_start
282
283
284
285
286
287
288
This page took 0.043909 seconds and 4 git commands to generate.