53d2152ed35a4bbf4d62c67bc30a7978549bb270
[deliverable/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 { } {
25 global gdb_prompt
26 global exit_status
27 global timeout
28
29 set timeout 60
30
31 verbose "Timeout is now $timeout seconds" 2
32 if [target_info exists gdb_protocol] {
33 set targetname "[target_info gdb_protocol]"
34 } else {
35 perror "No protocol specified for [target_info name].";
36 return -1;
37 }
38 if [target_info exists baud] {
39 gdb_test "set remotebaud [target_info baud]" "" ""
40 }
41 if [target_info exists gdb_serial] {
42 set serialport "[target_info gdb_serial]";
43 } elseif [target_info exists netport] {
44 set serialport "[target_info netport]"
45 } else {
46 set serialport "[target_info serial]"
47 }
48
49 for {set j 1} {$j <= 2} {incr j} {
50 for {set i 1} {$i <= 3} {incr i} {
51 send_gdb "target $targetname $serialport\n"
52 gdb_expect {
53 -re "A program is being debugged already.*ill it.*y or n. $" {
54 send_gdb "y\n";
55 exp_continue;
56 }
57 -re ".*Couldn't establish connection to remote.*$gdb_prompt" {
58 verbose "Connection failed"
59 }
60 -re "Remote MIPS debugging.*$gdb_prompt" {
61 verbose "Set target to $targetname"
62 return
63 }
64 -re "Remote debugging using $serialport.*$gdb_prompt" {
65 verbose "Set target to $targetname"
66 return
67 }
68 -re "Remote target $targetname connected to.*$gdb_prompt" {
69 verbose "Set target to $targetname"
70 return
71 }
72 -re "Ending remote.*$gdb_prompt" { }
73 -re "Connection refused.*$gdb_prompt" {
74 verbose "Connection refused by remote target. Pausing, and trying again."
75 sleep 30
76 continue
77 }
78 timeout {
79 send_gdb "\ 3";
80 break
81 }
82 }
83 }
84 if { $j == 1 && ![reboot_target] } {
85 break;
86 }
87 }
88
89 perror "Couldn't set target for $targetname, port is $serialport."
90 return -1;
91 }
92
93 proc gdb_target_exec { } {
94 gdb_test "target exec" "No exec file now." "" ".*Kill it.*y or n.*" "y"
95
96 }
97 #
98 # gdb_load -- load a file into the debugger.
99 # return a -1 if anything goes wrong.
100 #
101 proc gdb_load { arg } {
102 global verbose
103 global loadpath
104 global loadfile
105 global GDB
106 global gdb_prompt
107 global timeout
108
109 for { set j 1; } { $j <= 2 } {incr j; } {
110 if [target_info exists gdb,use_standard_load] {
111 gdb_target_exec;
112 remote_push_conn host;
113 set state [remote_ld target $arg];
114 remote_close target;
115 remote_pop_conn host;
116 if { $state == "pass" } {
117 if { $arg != "" } {
118 if [gdb_file_cmd $arg] { return -1 }
119 }
120 gdb_target_monitor;
121 gdb_test "list main" ".*" ""
122 verbose "Loaded $arg into $GDB\n";
123 return 1;
124 }
125 } else {
126 if { $arg != "" } {
127 if [gdb_file_cmd $arg] { return -1 }
128 }
129 gdb_target_monitor
130
131 if [target_info exists gdb_sect_offset] {
132 set textoff [target_info gdb_sect_offset];
133 send_gdb "sect .text $textoff\n";
134 gdb_expect {
135 -re "(0x\[0-9a-z]+) - 0x\[0-9a-z\]+ is \\.data" {
136 set dataoff $expect_out(1,string);
137 exp_continue;
138 }
139 -re "(0x\[0-9a-z\]+) - 0x\[0-9a-z\]+ is \\.bss" {
140 set bssoff $expect_out(1,string);
141 exp_continue;
142 }
143 -re "$gdb_prompt" { }
144 }
145 set dataoff [format 0x%x [expr $dataoff + $textoff]];
146 set bssoff [format 0x%x [expr $bssoff + $textoff]];
147 send_gdb "sect .data $dataoff\n";
148 gdb_expect {
149 -re "$gdb_prompt" { }
150 }
151 send_gdb "sect .bss $bssoff\n";
152 gdb_expect {
153 -re "$gdb_prompt" { }
154 }
155 }
156 if [is_remote host] {
157 # FIXME:
158 set arg a.out;
159 }
160
161 verbose "Loading $arg"
162 if [target_info exists gdb_load_offset] {
163 set command "load $arg [target_info gdb_load_offset]\n";
164 } else {
165 set command "load $arg\n";
166 }
167 send_gdb $command;
168 set timeout 1000
169 verbose "Timeout is now $timeout seconds" 2
170 gdb_expect {
171 -re ".*\[Ff\]ailed.*$gdb_prompt $" {
172 verbose "load failed";
173 }
174 -re ".*$gdb_prompt $" {
175 verbose "Loaded $arg into $GDB\n"
176 return 1
177 }
178 timeout {
179 if { $verbose > 1 } {
180 perror "Timed out trying to load $arg."
181 }
182 }
183 }
184 }
185
186 gdb_target_exec;
187
188 if { $j == 1 } {
189 if { ![reboot_target] } {
190 break;
191 }
192 }
193 }
194 perror "Couldn't load file into GDB.";
195 return -1;
196 }
197
198 proc gdb_start { } {
199 global timeout
200 global reboot
201 global gdb_prompt;
202
203 # reboot the board to get a clean start
204 if $reboot then {
205 reboot_target;
206 }
207
208 if [board_info target exists gdb_prompt] {
209 set gdb_prompt [board_info target gdb_prompt];
210 }
211
212 catch default_gdb_start;
213
214 set timeout 10
215 verbose "Timeout is now $timeout seconds" 2
216 }
This page took 0.159206 seconds and 3 git commands to generate.