Commit | Line | Data |
---|---|---|
19fa4a0a MW |
1 | # Copyright (C) 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 Fred Fish. (fnf@cygnus.com) | |
21 | ||
22 | # Generic gdb subroutines that should work for any target. If these | |
23 | # need to be modified for any target, it can be done with a variable | |
24 | # or by passing arguments. | |
25 | ||
26 | # | |
27 | # gdb_unload -- unload a file if one is loaded | |
28 | # | |
29 | ||
30 | proc gdb_unload {} { | |
31 | global verbose | |
32 | global GDB | |
33 | global prompt | |
34 | send "file\n" | |
35 | expect { | |
36 | -re "No exec file now\.\r" { continue -expect } | |
37 | -re "No symbol file now\.\r" { continue -expect } | |
38 | -re "A program is being debugged already..*Kill it\? \(y or n\) $"\ | |
39 | { send "y\n" | |
40 | if $verbose>1 then { | |
41 | send_user "\t\tKilling previous program being debugged\n" | |
42 | } | |
43 | continue -expect | |
44 | } | |
45 | -re "Discard symbol table from .*\? \(y or n\) $" { | |
46 | send "y\n" | |
47 | continue -expect | |
48 | } | |
49 | -re "$prompt $" {} | |
50 | timeout { | |
51 | error "couldn't unload file in $GDB (timed out)." | |
52 | alldone | |
53 | } | |
54 | } | |
55 | } | |
56 | ||
57 | # Many of the tests depend on setting breakpoints at various places and | |
58 | # running until that breakpoint is reached. At times, we want to start | |
59 | # with a clean-slate with respect to breakpoints, so this utility proc | |
60 | # lets us do this without duplicating this code everywhere. | |
61 | # | |
62 | ||
63 | proc delete_breakpoints {} { | |
64 | global prompt | |
65 | ||
66 | send "delete breakpoints\n" | |
67 | expect { | |
68 | -re "Delete all breakpoints\? \(y or n\) $" { | |
69 | send "y\n" | |
70 | continue -expect | |
71 | } | |
72 | -re "y\r\n$prompt $" {} | |
73 | -re ".*$prompt $" { fail "Delete all breakpoints" ; return } | |
74 | timeout { fail "Delete all breakpoints (timeout)" ; return } | |
75 | } | |
76 | send "info breakpoints\n" | |
77 | expect { | |
78 | -re "No breakpoints or watchpoints..*$prompt $" {} | |
79 | -re ".*$prompt $" { fail "breakpoints not deleted" ; return } | |
80 | timeout { fail "info breakpoints (timeout)" ; return } | |
81 | } | |
82 | } | |
83 | ||
84 | ||
85 | # | |
86 | # Set breakpoint at function and run gdb until it breaks there. | |
87 | # Since this is the only breakpoint that will be set, if it stops | |
88 | # at a breakpoint, we will assume it is the one we want. We can't | |
89 | # just compare to "function" because it might be a fully qualified, | |
90 | # single quoted C++ function specifier. | |
91 | # | |
92 | ||
93 | proc runto { function } { | |
94 | global prompt | |
95 | global decimal | |
96 | ||
97 | send "delete\n" | |
98 | expect { | |
99 | -re "Delete all breakpoints\? \(y or n\) $" { | |
100 | send "y\n" | |
101 | expect { | |
102 | -re "$prompt $" {} | |
103 | timeout { fail "deleting breakpoints (timeout)" ; return 0 } | |
104 | } | |
105 | } | |
106 | -re ".*$prompt $" {} | |
107 | timeout { fail "deleting breakpoints (timeout)" ; return 0 } | |
108 | } | |
109 | ||
110 | send "break $function\n" | |
111 | expect { | |
112 | -re "Break.* at .*: file .*, line $decimal.\r\n$prompt $" {} | |
113 | -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 } | |
114 | timeout { fail "setting breakpoint at $function (timeout)" ; return 0 } | |
115 | } | |
116 | ||
117 | send "run\n" | |
118 | expect { | |
119 | -re "The program .* has been started already.* \(y or n\) $" { | |
120 | send "y\n" | |
121 | continue -expect | |
122 | } | |
123 | -re "Starting.*Break.*\(\) at .*:$decimal.*$prompt $" { return 1 } | |
124 | -re "$prompt $" { fail "running to $function" ; return 0 } | |
125 | timeout { fail "running to $function (timeout)" ; return 0 } | |
126 | } | |
127 | } | |
128 | ||
129 | # | |
130 | # gdb_test -- send a command to gdb and test the result. | |
131 | # Takes three parameters. | |
132 | # Parameters: | |
133 | # First one is the command to execute, | |
134 | # Second one is the pattern to match for a PASS, | |
135 | # Third one is an optional message to be printed. If this | |
136 | # a null string "", then the pass/fail messages are not printed. | |
137 | # Returns: | |
138 | # 1 if the test failed, | |
139 | # 0 if the test passes, | |
140 | # -1 if there was an internal error. | |
141 | # | |
142 | proc gdb_test { args } { | |
143 | global verbose | |
144 | global prompt | |
145 | global GDB | |
146 | global spawn_id | |
147 | ||
148 | if [llength $args]==3 then { | |
149 | set message [lindex $args 2] | |
150 | } else { | |
151 | set message [lindex $args 0] | |
152 | } | |
153 | set command [lindex $args 0] | |
154 | set pattern [lindex $args 1] | |
155 | ||
156 | if $verbose>2 then { | |
157 | send_user "Sending \"$command\" to gdb\n" | |
158 | send_user "Looking to match \"$pattern\"\n" | |
159 | send_user "Message is \"$message\"\n" | |
160 | } | |
161 | ||
162 | set result -1 | |
163 | set errmess "" | |
164 | # trap the send so any problems don't crash things | |
165 | catch "send \"$command\n\"" errmess | |
166 | if ![string match "" $errmess] then { | |
167 | error "send \"$command\" got expect error \"$errmess\"" | |
168 | return -1 | |
169 | } | |
170 | ||
171 | expect { | |
172 | -re ".*Ending remote debugging.*$prompt$" { | |
173 | if ![isnative] then { | |
174 | warning "Can`t communicate to remote target." | |
175 | } | |
176 | gdb_exit | |
177 | gdb_start | |
178 | set result -1 | |
179 | } | |
180 | -re "$pattern.*$prompt $" { | |
181 | if ![string match "" $message] then { | |
182 | pass "$message" | |
183 | } | |
184 | set result 0 | |
185 | } | |
186 | -re "Undefined command:.*$prompt" { | |
187 | error "Undefined command \"$command\"." | |
188 | } | |
189 | -re "Ambiguous command.*$prompt $" { | |
190 | error "\"$command\" is not a unique command name." | |
191 | } | |
192 | -re ".*$prompt $" { | |
193 | if ![string match "" $message] then { | |
194 | fail "$message" | |
195 | } | |
196 | set result 1 | |
197 | } | |
198 | "<return>" { | |
199 | send "\n" | |
200 | error "Window too small." | |
201 | } | |
202 | -re "\(y or n\) " { | |
203 | send "n\n" | |
204 | error "Got interactive prompt." | |
205 | } | |
206 | buffer_full { | |
207 | error "internal buffer is full." | |
208 | } | |
209 | eof { | |
210 | error "eof -- pty is hosed." | |
211 | } | |
212 | timeout { | |
213 | fail "(timeout) $message" | |
214 | set result 1 | |
215 | } | |
216 | } | |
217 | return $result | |
218 | } | |
219 | ||
220 | # "virtual memory exhausted" { | |
221 | # error "virtual memory exhausted." | |
222 | # } | |
223 | ||
224 | proc gdb_reinitialize_dir { subdir } { | |
225 | global prompt | |
226 | global verbose | |
227 | ||
228 | send "dir\n" | |
229 | expect { | |
230 | -re "Reinitialize source path to empty.*" { | |
231 | send "y\n" | |
232 | expect { | |
233 | -re "Source directories searched.*$prompt $" { | |
234 | send "dir $subdir\n" | |
235 | expect { | |
236 | -re "Source directories searched.*$prompt $" { | |
237 | if $verbose>1 then { | |
238 | send_user "Dir set to $subdir\n" | |
239 | } | |
240 | } | |
241 | -re ".*$prompt $" { | |
242 | error "Dir \"$subdir\" failed." | |
243 | } | |
244 | } | |
245 | } | |
246 | -re ".*$prompt $" { | |
247 | error "Dir \"$subdir\" failed." | |
248 | } | |
249 | } | |
250 | } | |
251 | -re ".*$prompt $" { | |
252 | error "Dir \"$subdir\" failed." | |
253 | } | |
254 | } | |
255 | } |