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