1# Test Framework Driver for GDB driving a ROM monitor (via monitor.c).
2#   Copyright 1995 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
18load_lib gdb.exp
19
20#
21# gdb_version -- extract and print the version number of gdb
22#
23proc gdb_version {} {
24    default_gdb_version
25}
26
27#
28# gdb_target_monitor
29# Set gdb to target the monitor
30#
31proc gdb_target_monitor { } {
32    global prompt
33    global exit_status
34    global targetname
35    global serialport
36    global baud
37    global target_info
38
39    set timeout 60
40    verbose "Timeout is now $timeout seconds" 2
41    if {$baud != ""} then {
42	send "set remotebaud $baud\n"
43    }
44    if [info exists target_info(target,target)] {
45	set targetname "$target_info(target,target)"
46    }
47    if [info exists target_info(target,netport)] {
48	set serialport "$target_info(target,netport)"
49    }
50    for {set i 1} {$i <= 3} {incr i} {
51	send "target $targetname $serialport\n"
52	expect {
53		-re "Remote target $targetname connected to.*$prompt $"	{
54		     verbose "Set target to $targetname"
55		     return
56		}
57		-re "Connection refused" {
58		    verbose "Connection refused by remote target.  Pausing, and trying again."
59		    sleep 30
60		    continue
61		}
62		timeout {
63		    break
64		}
65	}
66    }
67
68    perror "Couldn't set target for $targetname."
69    cleanup
70    exit $exit_status
71}
72
73#
74# gdb_load -- load a file into the debugger.
75#             return a -1 if anything goes wrong.
76#
77proc gdb_load { arg } {
78    global verbose
79    global loadpath
80    global loadfile
81    global GDB
82    global prompt
83
84    if [gdb_file_cmd $arg] then { return -1 }
85
86    gdb_target_monitor
87
88    verbose "Loading $arg"
89    send "load $arg\n"
90    set timeout 1000
91    verbose "Timeout is now $timeout seconds" 2
92    expect {
93	-re ".*$prompt $" {
94	    if { $verbose > 1 } {
95		send_user "Loaded $arg into $GDB\n"
96	    }
97	    return 1
98	}
99	-re "$prompt $"     {
100	    if { $verbose > 1 } {
101		perror "GDB couldn't load."
102	    }
103	}
104	timeout {
105	    if { $verbose > 1 } {
106	 perror "Timed out trying to load $arg."
107	    }
108	}
109    }
110}
111
112#
113# gdb_start -- start GDB running.
114#
115proc gdb_start { } {
116    default_gdb_start
117}
118
119#
120# gdb_exit -- exit gdb
121#
122proc gdb_exit { } {
123    catch default_gdb_exit
124}
125
126gdb_start
127