OSDN Git Service

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