1 # Copyright
2000, 2002, 2003, 2004, 2005 Free Software Foundation
, Inc.
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.
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.
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.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
17 # This file is based
on config
/gdbserver.exp
, which was written by
18 # Michael Snyder
(msnyder@redhat.com
).
21 # To be addressed or
set in your baseboard config file
:
23 # set_board_info gdb_protocol
"remote"
24 # Unles you have a gdbserver that uses a different protocol...
26 # set_board_info gdb_server_prog
27 # This will be the path to the gdbserver
program you want to test.
28 # Defaults to
"gdbserver".
30 # set_board_info sockethost
31 # The
name of the host computer whose socket is being used.
32 # Defaults to
"localhost". Note: old gdbserver requires
33 # that you
define this
, but libremote
/gdbserver does not.
35 # set_board_info gdb
,socketport
36 # Port id to use
for socket connection.
If not
set explicitly
,
37 # it will start at
"2345" and increment for each use.
42 # Send gdb the
"target" command
44 proc gdb_target_cmd
{ targetname serialport
} {
47 for {set i
1} {$i
<= 3} {incr i
} {
48 send_gdb
"target $targetname $serialport\n"
50 -re
"A program is being debugged already.*ill it.*y or n. $" {
54 -re
"Couldn't establish connection to remote.*$gdb_prompt" {
55 verbose
"Connection failed"
57 -re
"Remote MIPS debugging.*$gdb_prompt" {
58 verbose
"Set target to $targetname"
61 -re
"Remote debugging using .*$serialport.*$gdb_prompt" {
62 verbose
"Set target to $targetname"
65 -re
"Remote target $targetname connected to.*$gdb_prompt" {
66 verbose
"Set target to $targetname"
69 -re
"Connected to.*$gdb_prompt" {
70 verbose
"Set target to $targetname"
73 -re
"Ending remote.*$gdb_prompt" { }
74 -re
"Connection refused.*$gdb_prompt" {
75 verbose
"Connection refused by remote target. Pausing, and trying again."
79 -re
"Timeout reading from remote system.*$gdb_prompt" {
80 verbose
"Got timeout error from gdb."
95 # Locate the gdbserver binary. Returns
"" if gdbserver could not be found.
97 proc find_gdbserver
{ } {
100 if [target_info
exists gdb_server_prog
] {
101 return [target_info gdb_server_prog
]
104 set gdbserver
"${GDB}server"
105 if { [file isdirectory $gdbserver
] } {
106 append gdbserver
"/gdbserver"
109 if { [file executable $gdbserver
] } {
116 #
Return non
-zero
if we should skip gdbserver
-specific tests.
118 proc skip_gdbserver_tests
{ } {
119 if { [find_gdbserver
] == "" } {
126 # Start a gdbserver process running SERVER_EXEC
, and
connect GDB
127 # to it. CHILD_ARGS are passed to the inferior.
129 # Returns the target protocol and socket to
connect to.
131 proc gdbserver_spawn
{ server_exec child_args
} {
134 # Port id
-- either specified in baseboard file
, or managed here.
135 if [target_info
exists gdb
,socketport
] {
136 set portnum
[target_info gdb
,socketport
]
138 # Bump the port number to avoid conflicts with hung ports.
142 # Extract the local and remote host ids from the target board struct.
143 if [target_info
exists sockethost
] {
144 set debughost
[target_info sockethost
]
146 set debughost
"localhost:"
149 # Extract the protocol
150 if [target_info
exists gdb_protocol
] {
151 set protocol
[target_info gdb_protocol
]
153 set protocol
"remote"
156 set gdbserver
[find_gdbserver
]
158 #
Export the host
:port pair.
159 set gdbport $debughost$portnum
161 # Fire
off the debug agent. This flavour of gdbserver takes as
162 # arguments the port information
, the
name of the executable file to
163 # be debugged
, and
any arguments.
164 set gdbserver_command
"$gdbserver :$portnum $server_exec"
165 if { $child_args
!= "" } {
166 append gdbserver_command
" $child_args"
169 set server_spawn_id
[remote_spawn target $gdbserver_command
]
171 # Wait
for the server to produce at least one line and an additional
172 # character of output. This will wait until
any TCP socket has been
173 # created
, so that GDB can
connect.
180 # We can
't just call close, because if gdbserver is local then that means
181 # that it will get a SIGHUP. Doing it this way could also allow us to
182 # get at the inferior's input or output
if necessary
, and means that we
183 # don
't need to redirect output.
188 # The spawn ID is already closed now (but not yet waited for).
189 wait -i $expect_out(spawn_id)
193 return [list $protocol $gdbport]
196 proc infer_host_exec { } {
199 send_gdb "info files\n"
201 -re "Symbols from \"(\[^\"\]+)\"" {
202 set host_exec $expect_out(1,string)
205 -re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\
]+)'," {
206 set host_exec $expect_out(1,string)
209 -re "$gdb_prompt $" { }
215 # Start a gdbserver process running HOST_EXEC and pass CHILD_ARGS
216 # to it. Return 0 on success, or non-zero on failure.
218 proc gdbserver_load { host_exec child_args } {
219 global gdbserver_host_exec
220 global gdbserver_server_exec
222 # If we weren't passed an explicit binary
, try to reuse the current
223 # one.
If we were
, be sure to redownload it.
225 if { $host_exec
== "" && $gdbserver_host_exec == "" } {
226 set gdbserver_host_exec
[infer_host_exec
]
227 } elseif
{ $host_exec
!= "" } {
228 set gdbserver_host_exec $host_exec
229 if [info exists gdbserver_server_exec
] { unset gdbserver_server_exec
}
232 if { ! [info exists gdbserver_server_exec
] } {
233 if [is_remote target
] {
234 set gdbserver_server_exec
[remote_download target $host_exec
/tmp
/[file tail $gdbserver_host_exec
].
[pid
]]
236 set gdbserver_server_exec $gdbserver_host_exec
240 set res
[gdbserver_spawn $gdbserver_server_exec $child_args
]
241 set protocol
[lindex $res
0]
242 set gdbport
[lindex $res
1]
244 if { $host_exec
!= "" } {
245 if [gdb_file_cmd $host_exec
] {
249 gdb_target_cmd $protocol $gdbport