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