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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [gdb/] [testsuite/] [config/] [sid.exp] - Blame information for rev 387

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

Line No. Rev Author Line
1 227 jeremybenn
# Test Framework Driver for GDB driving an external simulator
2
#   Copyright 1999, 2001, 2007, 2008, 2009, 2010
3
#   Free Software Foundation, Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program.  If not, see .
17
 
18
load_lib gdb.exp
19
 
20
proc sid_start {} {
21
    global verbose
22
 
23
    set port [lindex [split [target_info netport] ":"] 1]
24
 
25
    # Set a default endianness
26
    case [target_info multilib_flags] in {
27
        { *big-endian* *-EB* *-meb* } { set sidendian "-EB" }
28
        { *little-endian* *-EL* *-mel* } { set sidendian "-EL" }
29
        default {
30
            if {[target_info exists sim,defaultendian]} then {
31
                set sidendian [target_info sim,defaultendian]
32
            } else {
33
                # rely on endianness settings in sid configuration defaults
34
                set sidendian ""
35
            }
36
        }
37
    }
38
    case $sidendian in {
39
        { -EB } { set sidendian2 {-e "set cpu endian big"} }
40
        { -EL } { set sidendian2 {-e "set cpu endian little"} }
41
        default { set sidendian2 {} }
42
    }
43
 
44
    # test to see whether to use use sid in build or install tree
45
    set use_build_tree [file exists ../../sid]
46
 
47
    if {$use_build_tree} then {
48
        set pre_spawn {
49
            global env
50
            set env(SID_LIBRARY_PATH) [join [glob "../../sid/component/*"] ":"]
51
            set env(SID) "../../sid/main/dynamic/sid"
52
            if {! [file exists $env(SID)]} then { error "Cannot find sid in build tree" }
53
        }
54
        if { [board_info target sim,protocol] == "sid" } {
55
            set spawncmd "[target_info sim] [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
56
        } elseif { [board_info target sim,protocol] == "rawsid" } {
57
            set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
58
        } else {
59
            set spawncmd "../../sid/bsp/[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
60
        }
61
        set post_spawn {
62
            global env
63
            unset env(SID_LIBRARY_PATH)
64
            unset env(SID)
65
        }
66
    } else {
67
        set pre_spawn {}
68
        if { [board_info target sim,protocol] == "sid" } {
69
            # FIXME: sim,options may be from the build tree, should find
70
            # it in the install tree.
71
            set spawncmd "sid [target_info sim,options] $sidendian2 -e \"set cpu-gdb-socket sockaddr-local 0.0.0.0:$port\""
72
        } elseif { [board_info target sim,protocol] == "rawsid" } {
73
            set spawncmd "[target_info sim] [target_info sim,options] -$sidendian --gdb=$port"
74
        } else {
75
            set spawncmd "[target_info sim] $sidendian --gdb=$port [target_info sim,options]"
76
        }
77
        set post_spawn {}
78
    }
79
 
80
    eval $pre_spawn
81
    if {[catch [list remote_spawn host $spawncmd] msg]} {
82
        perror $msg
83
        exit 1
84
    }
85
    eval $post_spawn
86
 
87
    # Don't do the following any more; it breaks with "runtest ... < /dev/null"
88
#    expect_background {
89
#       -re \[^\n\]*\n {
90
#           regsub "\n" $expect_out(buffer) {} msg
91
#           verbose "SID: $msg" 2
92
#       }
93
#    }
94
 
95
    # There should be no need to sleep to give SID time to start;
96
    # GDB would wait for a fair while for the stub to respond.
97
    sleep 4
98
 
99
    if ![target_info exists gdb,no_push_conn] {
100
        remote_push_conn host;
101
    }
102
}
103
 
104
#
105
# Handle GDB talking to SID
106
#
107
 
108
proc gdb_start {} {
109
    sid_start
110
    return [default_gdb_start]
111
}
112
 
113
proc sid_exit {} {
114
    if ![target_info exists gdb,no_push_conn] {
115
        remote_close host;
116
        remote_pop_conn host;
117
    }
118
}
119
 
120
proc gdb_exit {} {
121
    set result [default_gdb_exit]
122
    sid_exit
123
    return $result
124
}
125
 
126
#
127
# gdb_target_sid
128
# Set gdb to target the simulator
129
#
130
proc send_target_sid { } {
131
    # wait a little while, giving sid time to shut down & restart its
132
    # gdb socket
133
    sleep 4
134
    send_gdb "target [target_info gdb_protocol] [target_info netport]\n"
135
}
136
 
137
proc gdb_target_sid { } {
138
    global gdb_prompt
139
    global exit_status
140
 
141
    send_target_sid
142
 
143
    global timeout
144
    set prev_timeout $timeout
145
    set timeout 60
146
    verbose "Timeout is now $timeout seconds" 2
147
    gdb_expect {
148
        -re ".*\[Ee\]rror.*$gdb_prompt $" {
149
            perror "Couldn't set target for remote simulator."
150
            cleanup
151
            gdb_exit
152
        }
153
        -re "Remote debugging using.*$gdb_prompt"       {
154
            verbose "Set target to sid"
155
        }
156
        timeout {
157
            perror "Couldn't set target for remote simulator."
158
            cleanup
159
            gdb_exit
160
        }
161
    }
162
    set timeout $prev_timeout
163
    verbose "Timeout is now $timeout seconds" 2
164
}
165
 
166
#
167
# gdb_load -- load a file into the debugger.
168
#             return a -1 if anything goes wrong.
169
#
170
proc gdb_load { arg } {
171
    global verbose
172
    global loadpath
173
    global loadfile
174
    global GDB
175
    global gdb_prompt
176
    global retval
177
 
178
    if { $arg != "" } {
179
        if [gdb_file_cmd $arg] then { return -1 }
180
    }
181
 
182
    gdb_target_sid
183
 
184
    send_gdb "load\n"
185
    global timeout
186
    set prev_timeout $timeout
187
    set timeout 2400
188
    verbose "Timeout is now $timeout seconds" 2
189
    gdb_expect {
190
        -re ".*\[Ee\]rror.*$gdb_prompt $" {
191
            if $verbose>1 then {
192
                perror "Error during download."
193
            }
194
            set retval -1;
195
        }
196
        -re ".*$gdb_prompt $" {
197
            if $verbose>1 then {
198
                send_user "Loaded $arg into $GDB\n"
199
            }
200
            set retval 0;
201
        }
202
        -re "$gdb_prompt $"     {
203
            if $verbose>1 then {
204
                perror "GDB couldn't load."
205
            }
206
            set retval -1;
207
        }
208
        timeout {
209
            if $verbose>1 then {
210
                perror "Timed out trying to load $arg."
211
            }
212
            set retval -1;
213
        }
214
    }
215
    set timeout $prev_timeout
216
    verbose "Timeout is now $timeout seconds" 2
217
    return $retval;
218
}

powered by: WebSVN 2.1.0

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