Commit | Line | Data |
---|---|---|
40ee1402 KH |
1 | # Copyright (C) 1993 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 | |
6c9638b4 | 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
40ee1402 KH |
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 Ian Lance Taylor <ian@cygnus.com>. | |
21 | ||
22 | # GDB support routines for a board using the MIPS remote debugging | |
23 | # protocol. These are actually pretty generic. | |
24 | ||
25 | # DejaGnu currently assumes that debugging is being done over the main | |
26 | # console port. It would probably be more convenient for people using | |
27 | # IDT boards to permit the debugging port and the connected port to be | |
28 | # different, since an IDT board has two ports. This would require | |
29 | # extending some of the tests in a fashion similar to that done for | |
30 | # VxWorks, because the test output would appear on the other port, | |
31 | # rather than being displayed by gdb. | |
32 | ||
33 | load_lib remote.exp | |
34 | load_lib gdb.exp | |
35 | ||
36 | # | |
37 | # gdb_version -- extract and print the version number of gdb | |
38 | # | |
39 | proc gdb_version {} { | |
40 | global GDB | |
41 | global GDBFLAGS | |
42 | global prompt | |
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 | } | |
48 | ||
49 | # | |
50 | # gdb_load -- load a file into the GDB. | |
51 | # Returns a 0 if there was an error, | |
52 | # 1 if it load successfully. | |
53 | # | |
54 | proc gdb_load { arg } { | |
55 | global verbose | |
56 | global loadpath | |
57 | global loadfile | |
58 | global prompt | |
59 | global spawn_id | |
60 | global GDB | |
61 | global expect_out | |
62 | global targetname | |
63 | ||
64 | set loadfile [file tail $arg] | |
65 | set loadpath [file dirname $arg] | |
66 | ||
67 | send "file $arg\n" | |
68 | expect { | |
69 | -re "A program is being debugged already..*Kill it.*y or n. $" { | |
70 | send "y\n" | |
4729c3e2 KH |
71 | exp_continue |
72 | } | |
73 | -re "Load new symbol table.*y or n. $" { | |
74 | send "y\n" | |
40ee1402 KH |
75 | exp_continue |
76 | } | |
77 | -re "Reading symbols from.*done..*$prompt $" {} | |
78 | -re "$prompt $" { perror "GDB couldn't read file" } | |
79 | timeout { perror "(timeout) read symbol file" ; return -1 } | |
80 | } | |
81 | ||
82 | send "target sparclite $targetname\n" | |
83 | set timeout 60 | |
84 | expect { | |
85 | -re ".*SPARClite appears to be alive.*$prompt $" { | |
86 | if $verbose>1 then { | |
87 | send_user "Set target to $targetname\n" | |
88 | } | |
89 | } | |
90 | timeout { | |
91 | perror "Couldn't set SLITE target." | |
92 | set timeout 10 | |
93 | return -1 | |
94 | } | |
95 | } | |
96 | ||
97 | send "load $arg\n" | |
98 | if $verbose>1 then { | |
99 | send_user "Loading $arg into $GDB\n" | |
100 | } | |
101 | set timeout 2400 | |
102 | expect { | |
103 | -re "Loading.*$prompt $" { | |
104 | if $verbose>1 then { | |
105 | send_user "Loaded $arg into $GDB\n" | |
106 | } | |
107 | set timeout 30 | |
108 | } | |
109 | -re "$prompt $" { | |
110 | if $verbose>1 then { | |
111 | perror "GDB couldn't load." | |
112 | } | |
113 | } | |
114 | timeout { | |
115 | if $verbose>1 then { | |
116 | perror "Timed out trying to load $arg." | |
117 | } | |
118 | } | |
119 | } | |
120 | set timeout 10 | |
121 | ||
122 | send "target remote $targetname\n" | |
123 | set timeout 60 | |
124 | expect { | |
125 | -re ".*$prompt $" { | |
126 | if $verbose>1 then { | |
127 | send_user "Set remote target to $targetname\n" | |
128 | } | |
129 | } | |
130 | timeout { | |
131 | perror "Couldn't set remote target." | |
132 | set timeout 10 | |
133 | return -1 | |
134 | } | |
135 | } | |
136 | ||
137 | if [info exists expect_out(buffer)] then { | |
138 | send_log $expect_out(buffer) | |
139 | } | |
140 | return 0 | |
141 | } | |
142 | ||
143 | # | |
144 | # gdb_start -- start GDB running. | |
145 | # | |
146 | proc gdb_start { } { | |
147 | global GDB | |
148 | global GDBFLAGS | |
149 | global spawn_id | |
150 | global shell_id | |
151 | global prompt | |
152 | global verbose | |
153 | global targetname | |
154 | global connectmode | |
155 | global reboot | |
156 | global baud | |
157 | ||
158 | # reboot the board to get a clean start | |
159 | if $reboot then { | |
160 | if ![info exists connectmode] then { | |
161 | set connectmode "kermit" | |
162 | } | |
163 | if ![info exists baud] then { | |
164 | set baud 9600 | |
165 | } | |
166 | set shell_id [ eval $connectmode "$targetname" ] | |
167 | send -i $shell_id "\n" | |
168 | expect { | |
169 | -i $shell_id -re ">$" { } | |
170 | timeout { | |
171 | send -i $shell_id "\CC" | |
172 | expect { | |
173 | -i $shell_id -re ">$" { } | |
174 | timeout { | |
175 | perror "(timeout) board did not come up."; return -1 | |
176 | } | |
177 | } | |
178 | } | |
179 | } | |
180 | send -i $shell_id "go 0xbfc00000\n" | |
181 | expect { | |
182 | -i $shell_id -re ">$" { } | |
183 | timeout { perror "(timeout) board did not come up."; return -1 } | |
184 | } | |
185 | verbose "about to exit kermit" | |
186 | exit_remote_shell $shell_id | |
187 | } | |
188 | ||
189 | set GDB [which $GDB] | |
190 | # start GDB | |
191 | if [ llength $GDBFLAGS ] then { | |
192 | spawn $GDB $GDBFLAGS | |
193 | } else { | |
194 | spawn $GDB | |
195 | } | |
196 | expect { | |
197 | -re ".*\r\n$prompt $" { | |
198 | verbose "GDB initialized." | |
199 | } | |
200 | -re "$prompt $" { | |
201 | perror "GDB never initialized." | |
202 | return -1 | |
203 | } | |
204 | timeout { | |
205 | perror "(timeout) GDB never initialized." | |
206 | return -1 | |
207 | } | |
208 | } | |
209 | ||
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 | # Don't use floating point instructions, in case the board doesn't | |
218 | # support them. | |
219 | # send "set mipsfpu off\n" | |
220 | # expect -re ".*$prompt $" {} | |
221 | ||
222 | # if $verbose>1 then { | |
223 | # send_user "Setting up target, please wait...\n" | |
224 | # } | |
225 | # send "target mips $targetname\n" | |
226 | # set timeout 60 | |
227 | # expect { | |
228 | # -re "Remote MIPS debugging.*$prompt $" { | |
229 | # if $verbose>1 then { | |
230 | # send_user "Set target to $targetname\n" | |
231 | # } | |
232 | # } | |
233 | # timeout { | |
234 | # perror "Couldn't set MIPS target." | |
235 | # set timeout 10 | |
236 | # return -1 | |
237 | # } | |
238 | # } | |
239 | set timeout 10 | |
240 | } | |
241 | ||
242 | expect_after { | |
243 | "<return>" { send "\n"; perror "Window too small." } | |
244 | -re "\(y or n\) " { send "n\n"; perror "Got interactive prompt." } | |
245 | buffer_full { perror "internal buffer is full." } | |
246 | eof { perror "eof -- pty is hosed." } | |
247 | timeout { perror "timeout." } | |
248 | "virtual memory exhausted" { perror "virtual memory exhausted." } | |
249 | "Undefined command" { perror "send string probably wrong." } | |
250 | } | |
251 | ||
252 | proc gdb_exit { } { | |
253 | catch default_gdb_exit | |
254 | } | |
255 | ||
256 | gdb_start | |
257 | ||
258 | # make sure gdb has actually started, otherwise if the first test | |
259 | # timesout, DejaGnu crashes | |
260 | send "\n" | |
261 | expect { | |
262 | -re "$prompt" | |
263 | } |