OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [config/] [monitor.exp] - Blame information for rev 106

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.