]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/config/monitor.exp
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / config / monitor.exp
1 # Test Framework Driver for GDB driving a ROM monitor (via monitor.c).
2 # Copyright 1995, 1997 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 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 #
21 # gdb_target_monitor
22 # Set gdb to target the monitor
23 #
24 proc gdb_target_monitor { exec_file } {
25 global gdb_prompt
26 global exit_status
27 global timeout
28
29 if [target_info exists gdb_protocol] {
30 set targetname "[target_info gdb_protocol]"
31 } else {
32 perror "No protocol specified for [target_info name].";
33 return -1;
34 }
35 if [target_info exists baud] {
36 gdb_test "set remotebaud [target_info baud]" "" ""
37 }
38 if [target_info exists gdb_serial] {
39 set serialport "[target_info gdb_serial]";
40 } elseif [target_info exists netport] {
41 set serialport "[target_info netport]"
42 } else {
43 set serialport "[target_info serial]"
44 }
45
46 for {set j 1} {$j <= 2} {incr j} {
47 if [gdb_file_cmd $exec_file] { return -1; }
48
49 for {set i 1} {$i <= 3} {incr i} {
50 send_gdb "target $targetname $serialport\n"
51 gdb_expect 60 {
52 -re "A program is being debugged already.*ill it.*y or n. $" {
53 send_gdb "y\n";
54 exp_continue;
55 }
56 -re "Couldn't establish connection to remote.*$gdb_prompt" {
57 verbose "Connection failed";
58 }
59 -re "Remote MIPS debugging.*$gdb_prompt" {
60 verbose "Set target to $targetname";
61 return 0;
62 }
63 -re "Remote debugging using .*$serialport.*$gdb_prompt" {
64 verbose "Set target to $targetname";
65 return 0;
66 }
67 -re "Remote target $targetname connected to.*$gdb_prompt" {
68 verbose "Set target to $targetname";
69 return 0;
70 }
71 -re "Connected to.*$gdb_prompt" {
72 verbose "Set target to $targetname";
73 return 0;
74 }
75 -re "Ending remote.*$gdb_prompt" { }
76 -re "Connection refused.*$gdb_prompt" {
77 verbose "Connection refused by remote target. Pausing, and trying again."
78 sleep 30
79 continue
80 }
81 -re "Timeout reading from remote system.*$gdb_prompt" {
82 verbose "Got timeout error from gdb.";
83 }
84 timeout {
85 send_gdb "\ 3";
86 break
87 }
88 }
89 }
90
91 gdb_target_exec;
92
93 if { $j == 1 && ![reboot_target] } {
94 break;
95 }
96 }
97
98 perror "Couldn't set target for $targetname, port is $serialport.";
99 return -1;
100 }
101
102 proc gdb_target_exec { } {
103 gdb_test "target exec" "No executable file now." "" ".*Kill it.*y or n.*" "y"
104
105 }
106 #
107 # gdb_load -- load a file into the debugger.
108 # return a -1 if anything goes wrong.
109 #
110 proc gdb_load { arg } {
111 global verbose
112 global loadpath
113 global loadfile
114 global GDB
115 global gdb_prompt
116 global timeout
117 global last_gdb_file;
118
119 if { $arg == "" } {
120 if [info exists last_gdb_file] {
121 set arg $last_gdb_file;
122 } else {
123 send_gdb "info files\n";
124 gdb_expect 30 {
125 -re "Symbols from \"(\[^\"\]+)\"" {
126 set arg $expect_out(1,string);
127 exp_continue;
128 }
129 -re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
130 set arg $expect_out(1,string);
131 exp_continue;
132 }
133 -re "$gdb_prompt $" { }
134 }
135 }
136 }
137
138 set last_gdb_file $arg;
139
140 for { set j 1; } { $j <= 2 } {incr j; } {
141 if [target_info exists gdb,use_standard_load] {
142 gdb_target_exec;
143 if ![target_info exists gdb,no_push_conn] {
144 remote_push_conn host;
145 }
146 set state [remote_ld target $arg];
147 if ![target_info exists gdb,no_push_conn] {
148 remote_close target;
149 remote_pop_conn host;
150 }
151 if { $state == "pass" } {
152 if [gdb_target_monitor $arg] { return -1; }
153 gdb_test "list main" ".*" ""
154 verbose "Loaded $arg into $GDB\n";
155 return 0;
156 }
157 } else {
158
159 if [gdb_target_monitor $arg] { return -1 }
160
161 if [is_remote host] {
162 # FIXME: Multiple downloads. bleah.
163 set farg [remote_download host $arg];
164 } else {
165 set farg $arg;
166 }
167
168 if { $arg != "" && [target_info exists gdb_sect_offset] } {
169 set textoff [target_info gdb_sect_offset];
170 send_gdb "sect .text $textoff\n";
171 gdb_expect 30 {
172 -re "(0x\[0-9a-z]+) - 0x\[0-9a-z\]+ is \\.data" {
173 set dataoff $expect_out(1,string);
174 exp_continue;
175 }
176 -re "(0x\[0-9a-z\]+) - 0x\[0-9a-z\]+ is \\.bss" {
177 set bssoff $expect_out(1,string);
178 exp_continue;
179 }
180 -re "$gdb_prompt" { }
181 }
182 set dataoff [format 0x%x [expr $dataoff + $textoff]];
183 set bssoff [format 0x%x [expr $bssoff + $textoff]];
184 send_gdb "sect .data $dataoff\n";
185 gdb_expect 30 {
186 -re "$gdb_prompt" { }
187 }
188 send_gdb "sect .bss $bssoff\n";
189 gdb_expect 30 {
190 -re "$gdb_prompt" { }
191 }
192 }
193
194 verbose "Loading $farg"
195 if [target_info exists gdb_load_offset] {
196 set command "load $farg [target_info gdb_load_offset]\n";
197 } else {
198 set command "load $farg\n";
199 }
200 send_gdb $command;
201 gdb_expect 1600 {
202 -re "\[Ff\]ailed.*$gdb_prompt $" {
203 verbose "load failed";
204 }
205 -re "Timeout reading from remote.*$gdb_prompt" {
206 }
207 -re "$gdb_prompt $" {
208 verbose "Loaded $farg into $GDB\n"
209 return 0;
210 }
211 timeout {
212 if { $verbose > 1 } {
213 perror "Timed out trying to load $farg."
214 }
215 }
216 }
217 }
218
219 # Make sure we don't have an open connection to the target.
220 gdb_target_exec;
221
222 if { $j == 1 } {
223 if { ![reboot_target] } {
224 break;
225 }
226 }
227 }
228 perror "Couldn't load file into GDB.";
229 return -1;
230 }