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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [gdb-5.3/] [gdb/] [testsuite/] [config/] [gdbserver.exp] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
# Test framework for GDB (remote protocol) using a "gdbserver",
2
# ie. a debug agent running as a native process on the same or
3
# a different host.
4
 
5
#   Copyright 2000, 2002 Free Software Foundation, Inc.
6
 
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
 
21
# Please email any bugs, comments, and/or additions to this file to:
22
# bug-gdb@prep.ai.mit.edu
23
 
24
# This file was written by Michael Snyder. (msnyder@redhat.com)
25
 
26
#
27
# This module to be used for testing gdb with a "gdbserver"
28
# built either from libremote or from gdb/gdbserver.
29
#
30
 
31
# Load the basic testing library, and the remote stuff.
32
load_lib ../config/monitor.exp
33
 
34
#
35
# To be addressed or set in your baseboard config file:
36
#
37
#   set_board_info gdb_protocol "remote"
38
#       Unles you have a gdbserver that uses a different protocol...
39
#
40
#   set_board_info use_gdb_stub 1
41
#       This tells the rest of the test suite not to do things
42
#       like "run" which don't work well on remote targets.
43
#
44
#   set_board_info gdb,do_reload_on_run 1
45
#       Unles you have a gdbserver that can handle multiple sessions.
46
#
47
#   set_board_info noargs 1
48
#       At present there is no provision in the remote protocol
49
#       for passing arguments.  This test framework does not
50
#       address the issue, so it's best to set this variable
51
#       in your baseboard configuration file.
52
#       FIXME: there's no reason why the test harness couldn't
53
#       pass commandline args when it spawns gdbserver.
54
#
55
#   set_board_info gdb,noinferiorio 1
56
#       Neither the traditional gdbserver nor the one in libremote
57
#       can presently capture stdout and relay it to GDB via the
58
#       'O' packet.  This means that tests involving printf will
59
#       fail unles you set this varibale in your baseboard
60
#       configuration file.
61
#
62
#   set_board_info gdb,no_hardware_watchpoints 1
63
#       Unles you have a gdbserver that supports hardware watchpoints.
64
#       FIXME: gdb should detect if the target doesn't support them,
65
#       and fall back to using software watchpoints.
66
#
67
#   set_board_info gdb_server_prog
68
#       This will be the path to the gdbserver program you want to test.
69
#       Defaults to "gdbserver".
70
#
71
#   set_board_info sockethost
72
#       The name of the host computer whose socket is being used.
73
#       Defaults to "localhost".  Note: old gdbserver requires
74
#       that you define this, but libremote/gdbserver does not.
75
#
76
#   set_board_info socketport
77
#       Port id to use for socket connection.  If not set explicitly,
78
#       it will start at "2345" and increment for each use.
79
#
80
 
81
 
82
 
83
#
84
# gdb_load -- load a file into the debugger.
85
#             return a -1 if anything goes wrong.
86
#
87
 
88
global server_exec;
89
global portnum;
90
set portnum "2345";
91
 
92
proc gdb_load { arg } {
93
    global host_exec;
94
    global server_exec;
95
    global portnum;
96
    global verbose;
97
    global gdb_prompt;
98
 
99
    # Port id -- either specified in baseboard file, or managed here.
100
    if [target_info exists gdb,socketport] {
101
        set portnum [target_info gdb,socketport];
102
    } else {
103
        # Bump the port number to avoid conflicts with hung ports.
104
        incr portnum;
105
    }
106
 
107
    # Extract the local and remote host ids from the target board struct.
108
 
109
    if [target_info exists sockethost] {
110
        set debughost  [target_info sockethost];
111
    } else {
112
        set debughost "localhost:";
113
    }
114
    # Extract the protocol
115
    if [target_info exists gdb_protocol] {
116
        set protocol [target_info gdb_protocol];
117
    } else {
118
        set protocol "remote";
119
    }
120
 
121
    # Extract the name of the gdbserver, if known (default 'gdbserver').
122
    if [target_info exists gdb_server_prog] {
123
        set gdbserver [target_info gdb_server_prog];
124
    } else {
125
        set gdbserver "gdbserver";
126
    }
127
    # Extract the socket hostname
128
    if [target_info exists sockethost] {
129
        set sockethost [target_info sockethost];
130
    } else {
131
        set sockethost ""
132
    }
133
 
134
    # Export the host:port pair.
135
    set gdbport $debughost$portnum;
136
 
137
    # Remember new exec file.
138
    if { $arg == "" } {
139
        if { ! [info exists host_exec] } {
140
            send_gdb "info files\n";
141
            gdb_expect 30 {
142
                -re "Symbols from \"(\[^\"\]+)\"" {
143
                    set host_exec $expect_out(1,string);
144
                    exp_continue;
145
                }
146
                -re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
147
                    set host_exec $expect_out(1,string);
148
                    exp_continue;
149
                }
150
                -re "$gdb_prompt $" { }
151
            }
152
        }
153
    } else {
154
        set host_exec $arg
155
        if [info exists server_exec] { unset server_exec }
156
    }
157
 
158
    if { ! [info exists server_exec] } {
159
        if [is_remote target] {
160
            set server_exec [remote_download target $host_exec]
161
        } else {
162
            set server_exec $host_exec
163
        }
164
    }
165
 
166
    # Fire off the debug agent
167
    if [target_info exists gdb_server_args] {
168
        # This flavour of gdbserver takes as arguments those specified
169
        # in the board configuration file
170
        set custom_args [target_info gdb_server_args];
171
        set server_spawn_id [remote_spawn target \
172
               "$gdbserver $custom_args"]
173
    } else {
174
        # This flavour of gdbserver takes as arguments the port information
175
        # and the name of the executable file to be debugged.
176
        set server_spawn_id [remote_spawn target \
177
            "$gdbserver $sockethost$portnum $server_exec"]
178
    }
179
 
180
    # We can't call close, because if gdbserver is local then that means
181
    # that it will get a SIGHUP.
182
    ## close -i $server_spawn_id
183
    wait -nowait -i $server_spawn_id
184
 
185
    # Give it a little time to establish
186
    sleep 1
187
 
188
    # tell gdb what file we are debugging
189
    if { $arg != "" } {
190
        if [gdb_file_cmd $arg] {
191
            return -1;
192
        }
193
    }
194
 
195
    # attach to the "serial port"
196
    gdb_target_cmd $protocol $gdbport;
197
 
198
    # do the real load if needed
199
    if [target_info exists gdb_server_do_load] {
200
        send_gdb "load\n"
201
        set timeout 2400
202
        verbose "Timeout is now $timeout seconds" 2
203
        gdb_expect {
204
            -re ".*$gdb_prompt $" {
205
                if $verbose>1 then {
206
                    send_user "Loaded $arg into $GDB\n"
207
                }
208
                set timeout 30
209
                verbose "Timeout is now $timeout seconds" 2
210
                return 1
211
            }
212
            -re "$gdb_prompt $"     {
213
                if $verbose>1 then {
214
                    perror "GDB couldn't load."
215
                }
216
            }
217
            timeout {
218
                if $verbose>1 then {
219
                    perror "Timed out trying to load $arg."
220
                }
221
            }
222
        }
223
    }
224
 
225
    return 0;
226
}

powered by: WebSVN 2.1.0

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