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