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