Commit | Line | Data |
---|---|---|
31ca3f4c ILT |
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 | |
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 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 | ||
31ca3f4c ILT |
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 | |
cb58e516 | 62 | global targetname |
31ca3f4c ILT |
63 | |
64 | set loadfile [file tail $arg] | |
65 | set loadpath [file dirname $arg] | |
cb58e516 | 66 | |
31ca3f4c ILT |
67 | send "file $arg\n" |
68 | expect { | |
cb58e516 | 69 | -re "A program is being debugged already..*Kill it.*y or n. $" { |
31ca3f4c | 70 | send "y\n" |
90fba5fa | 71 | exp_continue |
31ca3f4c | 72 | } |
cb58e516 | 73 | -re "Reading symbols from.*done..*$prompt $" {} |
8f07e537 | 74 | -re "$prompt $" { perror "GDB couldn't read file" } |
cb58e516 KH |
75 | timeout { perror "(timeout) read symbol file" ; return -1 } |
76 | } | |
77 | ||
78 | send "target mips $targetname\n" | |
79 | set timeout 60 | |
80 | expect { | |
81 | -re "Remote MIPS debugging.*$prompt $" { | |
82 | if $verbose>1 then { | |
83 | send_user "Set target to $targetname\n" | |
84 | } | |
85 | } | |
86 | timeout { | |
87 | perror "Couldn't set MIPS target." | |
88 | set timeout 10 | |
89 | return -1 | |
90 | } | |
31ca3f4c | 91 | } |
cb58e516 | 92 | |
31ca3f4c ILT |
93 | send "load $arg\n" |
94 | if $verbose>1 then { | |
95 | send_user "Loading $arg into $GDB\n" | |
96 | } | |
48d10a25 | 97 | set timeout 2400 |
31ca3f4c ILT |
98 | expect { |
99 | -re "Loading.*$prompt $" { | |
100 | if $verbose>1 then { | |
101 | send_user "Loaded $arg into $GDB\n" | |
102 | } | |
103 | set timeout 30 | |
31ca3f4c ILT |
104 | } |
105 | -re "$prompt $" { | |
106 | if $verbose>1 then { | |
cb58e516 | 107 | perror "GDB couldn't load." |
31ca3f4c ILT |
108 | } |
109 | } | |
110 | timeout { | |
111 | if $verbose>1 then { | |
cb58e516 | 112 | perror "Timed out trying to load $arg." |
31ca3f4c ILT |
113 | } |
114 | } | |
115 | } | |
116 | set timeout 10 | |
117 | if [info exists expect_out(buffer)] then { | |
118 | send_log $expect_out(buffer) | |
119 | } | |
120 | return 0 | |
121 | } | |
122 | ||
31ca3f4c ILT |
123 | # |
124 | # gdb_start -- start GDB running. | |
125 | # | |
126 | proc gdb_start { } { | |
127 | global GDB | |
128 | global GDBFLAGS | |
129 | global spawn_id | |
130 | global shell_id | |
131 | global prompt | |
132 | global verbose | |
133 | global targetname | |
134 | global connectmode | |
135 | global reboot | |
136 | global baud | |
137 | ||
138 | # reboot the board to get a clean start | |
139 | if $reboot then { | |
140 | if ![info exists connectmode] then { | |
141 | set connectmode "kermit" | |
142 | } | |
143 | if ![info exists baud] then { | |
144 | set baud 9600 | |
145 | } | |
cb58e516 | 146 | set shell_id [ eval $connectmode "$targetname" ] |
48d10a25 ILT |
147 | send -i $shell_id "\n" |
148 | expect { | |
149 | -i $shell_id -re "<IDT>$" { } | |
150 | timeout { | |
151 | send -i $shell_id "\CC" | |
152 | expect { | |
153 | -i $shell_id -re "<IDT>$" { } | |
154 | timeout { | |
8f07e537 | 155 | perror "(timeout) board did not come up."; return -1 |
48d10a25 ILT |
156 | } |
157 | } | |
158 | } | |
31ca3f4c | 159 | } |
48d10a25 ILT |
160 | send -i $shell_id "go 0xbfc00000\n" |
161 | expect { | |
162 | -i $shell_id -re "<IDT>$" { } | |
8f07e537 | 163 | timeout { perror "(timeout) board did not come up."; return -1 } |
31ca3f4c | 164 | } |
48d10a25 | 165 | verbose "about to exit kermit" |
31ca3f4c ILT |
166 | exit_remote_shell $shell_id |
167 | } | |
168 | ||
169 | set GDB [which $GDB] | |
170 | # start GDB | |
171 | if [ llength $GDBFLAGS ] then { | |
172 | spawn $GDB $GDBFLAGS | |
173 | } else { | |
174 | spawn $GDB | |
175 | } | |
176 | expect { | |
cb58e516 KH |
177 | -re ".*\r\n$prompt $" { |
178 | verbose "GDB initialized." | |
179 | } | |
180 | -re "$prompt $" { | |
181 | perror "GDB never initialized." | |
182 | return -1 | |
183 | } | |
184 | timeout { | |
185 | perror "(timeout) GDB never initialized." | |
186 | return -1 | |
31ca3f4c | 187 | } |
31ca3f4c ILT |
188 | } |
189 | ||
190 | # force the height to "unlimited", so no pagers get used | |
191 | send "set height 0\n" | |
192 | expect -re ".*$prompt $" {} | |
193 | # force the width to "unlimited", so no wraparound occurs | |
194 | send "set width 0\n" | |
195 | expect -re ".*$prompt $" {} | |
196 | ||
197 | # Don't use floating point instructions, in case the board doesn't | |
198 | # support them. | |
199 | send "set mipsfpu off\n" | |
200 | expect -re ".*$prompt $" {} | |
201 | ||
cb58e516 KH |
202 | # if $verbose>1 then { |
203 | # send_user "Setting up target, please wait...\n" | |
204 | # } | |
205 | # send "target mips $targetname\n" | |
206 | # set timeout 60 | |
207 | # expect { | |
208 | # -re "Remote MIPS debugging.*$prompt $" { | |
209 | # if $verbose>1 then { | |
210 | # send_user "Set target to $targetname\n" | |
211 | # } | |
212 | # } | |
213 | # timeout { | |
214 | # perror "Couldn't set MIPS target." | |
215 | # set timeout 10 | |
216 | # return -1 | |
217 | # } | |
218 | # } | |
31ca3f4c ILT |
219 | set timeout 10 |
220 | } | |
221 | ||
222 | expect_after { | |
8f07e537 BC |
223 | "<return>" { send "\n"; perror "Window too small." } |
224 | -re "\(y or n\) " { send "n\n"; perror "Got interactive prompt." } | |
225 | buffer_full { perror "internal buffer is full." } | |
226 | eof { perror "eof -- pty is hosed." } | |
227 | timeout { perror "timeout." } | |
228 | "virtual memory exhausted" { perror "virtual memory exhausted." } | |
229 | "Undefined command" { perror "send string probably wrong." } | |
31ca3f4c ILT |
230 | } |
231 | ||
3f677d9e | 232 | proc gdb_exit { } { |
3f677d9e RS |
233 | catch default_gdb_exit |
234 | } | |
235 | ||
31ca3f4c ILT |
236 | gdb_start |
237 | ||
238 | # make sure gdb has actually started, otherwise if the first test | |
239 | # timesout, DejaGnu crashes | |
240 | send "\n" | |
241 | expect { | |
242 | -re "$prompt" | |
243 | } |