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