Commit | Line | Data |
---|---|---|
9c646a6e | 1 | # Test Framework Driver for GDB driving an external simulator |
b6ba6518 | 2 | # Copyright 1999, 2001 Free Software Foundation, Inc. |
9c646a6e BE |
3 | # |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | ||
18 | load_lib gdb.exp | |
19 | ||
20 | proc sid_start {} { | |
9c646a6e BE |
21 | global verbose |
22 | ||
23 | set port [lindex [split [target_info netport] ":"] 1] | |
24 | ||
25 | # Set a default endianness | |
26 | case [target_info multilib_flags] in { | |
27 | { *big-endian* *-EB* *-meb* } { set sidendian "-EB" } | |
28 | { *little-endian* *-EL* *-mel* } { set sidendian "-EL" } | |
29 | default { | |
30 | if {[target_info exists sim,defaultendian]} then { | |
31 | set sidendian [target_info sim,defaultendian] | |
32 | } else { | |
33 | warning "Unknown target endianness - assuming -EB" | |
34 | set sidendian "-EB" | |
35 | } | |
36 | } | |
37 | } | |
38 | # set verbosity conditionally | |
39 | if {$verbose > 0} then { set sidverbose "--verbose" } else { set sidverbose "" } | |
40 | ||
41 | # test to see whether to use use sid in build or install tree | |
42 | set use_build_tree [file exists ../../sid] | |
43 | ||
44 | if {$use_build_tree} then { | |
45 | set pre_spawn { | |
46 | global env | |
47 | set env(SID_LIBRARY_PATH) [join [glob "../../sid/component/*"] ":"] | |
48 | set env(SID) "../../sid/main/dynamic/sid" | |
49 | set env(MKSID) "../../sid/main/static/mksid" | |
50 | if {! [file exists $env(SID)]} then { error "Cannot find sid in build tree" } | |
51 | } | |
ca3f91ed MS |
52 | if { [board_info target sim,protocol] == "sid" } { |
53 | set spawncmd "[target_info sim] [target_info sim,options] -e \"set gdb-socket sockaddr-local 0.0.0.0:$port\"" | |
54 | } else { | |
55 | set spawncmd "../../sid/bsp/[target_info sim] $sidverbose $sidendian --gdb=$port [target_info sim,options]" | |
56 | } | |
9c646a6e BE |
57 | set post_spawn { |
58 | global env | |
59 | unset env(SID_LIBRARY_PATH) | |
60 | unset env(MKSID) | |
61 | unset env(SID) | |
62 | } | |
63 | } else { | |
ca3f91ed MS |
64 | global find_rawsid; |
65 | ||
9c646a6e | 66 | set pre_spawn {} |
ca3f91ed MS |
67 | if { [board_info target sim,protocol] == "sid" } { |
68 | # FIXME: sim,options may be from the build tree, should find | |
69 | # it in the install tree. | |
70 | set spawncmd "sid [target_info sim,options] -e \"set gdb-socket sockaddr-local 0.0.0.0:$port\"" | |
71 | } else { | |
72 | set spawncmd "[target_info sim] $sidverbose $sidendian --gdb=$port [target_info sim,options]" | |
73 | } | |
9c646a6e BE |
74 | set post_spawn {} |
75 | } | |
76 | ||
77 | eval $pre_spawn | |
ca3f91ed | 78 | if {[catch [list remote_spawn host $spawncmd] msg]} { |
9c646a6e BE |
79 | perror $msg |
80 | exit 1 | |
81 | } | |
82 | eval $post_spawn | |
83 | ||
84 | expect_background { | |
85 | -re \[^\n\]*\n { | |
86 | regsub "\n" $expect_out(buffer) {} msg | |
87 | verbose "SID: $msg" 2 | |
88 | } | |
89 | } | |
90 | ||
91 | # There should be no need to sleep to give SID time to start; | |
92 | # GDB would wait for a fair while for the stub to respond. | |
93 | sleep 4 | |
94 | ||
ca3f91ed MS |
95 | if ![target_info exists gdb,no_push_conn] { |
96 | remote_push_conn host; | |
97 | } | |
9c646a6e BE |
98 | } |
99 | ||
100 | # | |
101 | # Handle GDB talking to SID | |
102 | # | |
103 | ||
104 | proc gdb_start {} { | |
105 | sid_start | |
106 | return [default_gdb_start] | |
107 | } | |
108 | ||
109 | proc sid_exit {} { | |
ca3f91ed MS |
110 | if ![target_info exists gdb,no_push_conn] { |
111 | remote_close host; | |
112 | remote_pop_conn host; | |
9c646a6e BE |
113 | } |
114 | } | |
115 | ||
116 | proc gdb_exit {} { | |
117 | set result [default_gdb_exit] | |
118 | sid_exit | |
119 | return $result | |
120 | } | |
121 | ||
122 | # | |
123 | # gdb_target_sid | |
124 | # Set gdb to target the simulator | |
125 | # | |
126 | proc send_target_sid { } { | |
127 | # wait a little while, giving sid time to shut down & restart its | |
128 | # gdb socket | |
129 | sleep 4 | |
130 | send_gdb "target [target_info gdb_protocol] [target_info netport]\n" | |
131 | } | |
132 | ||
133 | proc gdb_target_sid { } { | |
134 | global gdb_prompt | |
135 | global exit_status | |
136 | ||
137 | send_target_sid | |
138 | ||
139 | global timeout | |
140 | set prev_timeout $timeout | |
141 | set timeout 60 | |
142 | verbose "Timeout is now $timeout seconds" 2 | |
143 | gdb_expect { | |
66c756c6 MS |
144 | -re ".*\[Ee\]rror.*$gdb_prompt $" { |
145 | perror "Couldn't set target for remote simulator." | |
146 | cleanup | |
147 | gdb_exit | |
148 | } | |
9c646a6e BE |
149 | -re "Remote debugging using.*$gdb_prompt" { |
150 | verbose "Set target to sid" | |
151 | } | |
152 | timeout { | |
153 | perror "Couldn't set target for remote simulator." | |
154 | cleanup | |
66c756c6 | 155 | gdb_exit |
9c646a6e BE |
156 | } |
157 | } | |
158 | set timeout $prev_timeout | |
159 | verbose "Timeout is now $timeout seconds" 2 | |
160 | } | |
161 | ||
162 | # | |
163 | # gdb_load -- load a file into the debugger. | |
164 | # return a -1 if anything goes wrong. | |
165 | # | |
166 | proc gdb_load { arg } { | |
167 | global verbose | |
168 | global loadpath | |
169 | global loadfile | |
170 | global GDB | |
171 | global gdb_prompt | |
66c756c6 | 172 | global retval |
9c646a6e BE |
173 | |
174 | gdb_unload | |
175 | if [gdb_file_cmd $arg] then { return -1 } | |
176 | gdb_target_sid | |
177 | ||
178 | send_gdb "load\n" | |
179 | global timeout | |
180 | set prev_timeout $timeout | |
181 | set timeout 2400 | |
182 | verbose "Timeout is now $timeout seconds" 2 | |
183 | gdb_expect { | |
66c756c6 MS |
184 | -re ".*\[Ee\]rror.*$gdb_prompt $" { |
185 | if $verbose>1 then { | |
186 | perror "Error during download." | |
187 | } | |
188 | set retval -1; | |
189 | } | |
9c646a6e BE |
190 | -re ".*$gdb_prompt $" { |
191 | if $verbose>1 then { | |
192 | send_user "Loaded $arg into $GDB\n" | |
193 | } | |
66c756c6 | 194 | set retval 1; |
9c646a6e BE |
195 | } |
196 | -re "$gdb_prompt $" { | |
197 | if $verbose>1 then { | |
198 | perror "GDB couldn't load." | |
199 | } | |
66c756c6 | 200 | set retval -1; |
9c646a6e BE |
201 | } |
202 | timeout { | |
203 | if $verbose>1 then { | |
204 | perror "Timed out trying to load $arg." | |
205 | } | |
66c756c6 | 206 | set retval -1; |
9c646a6e BE |
207 | } |
208 | } | |
209 | set timeout $prev_timeout | |
66c756c6 MS |
210 | verbose "Timeout is now $timeout seconds" 2 |
211 | return $retval; | |
9c646a6e | 212 | } |