Commit | Line | Data |
---|---|---|
19fa4a0a MW |
1 | # Copyright (C) 1988, 1990, 1991, 1992 Free Software Foundation, Inc. |
2 | ||
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program; if not, write to the Free Software | |
15 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # DejaGnu@cygnus.com | |
19 | ||
20 | # This file was written by Rob Savoye. (rob@cygnus.com) | |
21 | ||
22 | # variables that need to set up | |
23 | # | |
24 | if ![info exists prompt] then { | |
25 | set prompt "\(gdb\)" | |
26 | } | |
27 | # some convenience abbreviations | |
28 | # | |
29 | if ![info exists hex] then { | |
30 | set hex "0x\[0-9A-Fa-f\]+" | |
31 | } | |
32 | if ![info exists decimal] then { | |
33 | set decimal "\[0-9\]+" | |
34 | } | |
35 | ||
36 | # | |
37 | # gdb_version -- extract and print the version number of gcc | |
38 | # | |
39 | proc gdb_version {} { | |
40 | global GDB | |
41 | global GDBFLAGS | |
42 | set tmp [exec echo "q" | $GDB] | |
43 | set version [lindex $tmp [lsearch $tmp "\[0-9\]*"]] | |
44 | set version [string range $version 0 [expr [string length $version]-2]] | |
45 | clone_output "[which $GDB] version $version $GDBFLAGS\n" | |
46 | } | |
47 | ||
48 | # | |
49 | # gdb_unload -- unload a file if one is loaded | |
50 | # | |
51 | ||
52 | proc gdb_unload {} { | |
53 | global verbose | |
54 | global GDB | |
55 | global prompt | |
56 | send "file\n" | |
57 | expect { | |
58 | -re "No exec file now\.\r" { continue -expect } | |
59 | -re "No symbol file now\.\r" { continue -expect } | |
60 | -re "A program is being debugged already..*Kill it\? \(y or n\) $"\ | |
61 | { send "y\n" | |
62 | if $verbose>1 then { | |
63 | send_user "\t\tKilling previous program being debugged\n" | |
64 | } | |
65 | continue -expect | |
66 | } | |
67 | -re "Discard symbol table from .*\? \(y or n\) $" { | |
68 | send "y\n" | |
69 | continue -expect | |
70 | } | |
71 | -re "$prompt $" {} | |
72 | timeout { | |
73 | error "Couldn't unload file in $GDB (timed out)." | |
05a291bb | 74 | return -1 |
19fa4a0a MW |
75 | } |
76 | } | |
77 | } | |
78 | ||
79 | # | |
80 | # gdb_load -- load a file into the debugger. | |
05a291bb | 81 | # return a -1 if anything goes wrong. |
19fa4a0a MW |
82 | # |
83 | proc gdb_load { arg } { | |
84 | global verbose | |
85 | global loadpath | |
86 | global loadfile | |
87 | global GDB | |
88 | global prompt | |
89 | ||
90 | set loadfile [file tail $arg] | |
91 | set loadpath [file dirname $arg] | |
19fa4a0a MW |
92 | send "file $arg\n" |
93 | expect { | |
94 | -re "Reading symbols from.*done.*$prompt $"\ | |
95 | { if $verbose>1 then { | |
96 | send_user "\t\tLoaded $arg into the $GDB\n" | |
97 | } | |
98 | } | |
99 | -re "has no symbol-table.*$prompt $" { | |
100 | error "$arg wasn't compiled with \"-g\"\n" | |
101 | return -1 | |
102 | } | |
103 | -re "A program is being debugged already..*Kill it\? \(y or n\) $"\ | |
104 | { send "y\n" | |
105 | if $verbose>1 then { | |
106 | send_user "\t\tKilling previous program being debugged\n" | |
107 | } | |
108 | continue -expect | |
109 | } | |
110 | -re "Load new symbol table from.*\? \(y or n\) $"\ | |
111 | { send "y\n" | |
112 | expect { | |
113 | -re "Reading symbols from.*done.*$prompt $" | |
114 | { if $verbose>1 then { | |
115 | send_user "\t\tLoaded $arg with new symbol table into $GDB\n" | |
116 | } | |
117 | } | |
05a291bb | 118 | timeout { error "(timeout) Couldn't load $arg, other program already loaded."; return -1 } |
19fa4a0a MW |
119 | } |
120 | } | |
121 | -re ".*No such file or directory.*$prompt $"\ | |
05a291bb RS |
122 | { error "($arg) No such file or directory\n"; return -1 } |
123 | -re "$prompt $" { error "couldn't load $arg into $GDB."; return -1 } | |
124 | timeout { error "couldn't load $arg into $GDB (timed out)."; return -1 } | |
19fa4a0a MW |
125 | } |
126 | } | |
127 | ||
128 | # | |
129 | # gdb_exit -- kills the gdb process currently running | |
130 | # | |
131 | proc gdb_exit {} { | |
132 | global verbose | |
133 | global GDB | |
134 | global GDBFLAGS | |
135 | set timeout 1 | |
136 | ||
400b81b5 FF |
137 | if $verbose>1 then { |
138 | send_user "Quitting $GDB $GDBFLAGS\n" | |
139 | } | |
19fa4a0a MW |
140 | catch "send \"quit\n\"" result |
141 | if [string match "write\(spawn_id=\[0-9\]+\): Bad file number" $result] then { | |
521cce59 | 142 | catch "close" |
19fa4a0a MW |
143 | return 0 |
144 | } | |
145 | expect { | |
146 | eof { | |
147 | if $verbose>1 then { | |
148 | send_user "Got EOF from $GDB\n" | |
149 | } | |
150 | } | |
151 | timeout { | |
152 | if $verbose>1 then { | |
153 | send_user "Got TIMEOUT from $GDB\n" | |
154 | } | |
400b81b5 | 155 | close |
19fa4a0a MW |
156 | } |
157 | -re "The program is running. Quit anyway? (y or n) $"\ | |
158 | { send "y\n" | |
159 | if $verbose>1 then { | |
160 | send_user "\t\tKilling program being debugged\n" | |
161 | } | |
400b81b5 | 162 | close |
19fa4a0a MW |
163 | } |
164 | } | |
521cce59 RS |
165 | catch "close" |
166 | ||
167 | if $verbose>1 then { | |
168 | send_user "Quitting $GDB $GDBFLAGS\n" | |
169 | } | |
19fa4a0a MW |
170 | } |
171 | ||
172 | # | |
173 | # start gdb -- start gdb running | |
174 | # | |
175 | ||
176 | proc gdb_start {} { | |
177 | global verbose | |
178 | global GDB | |
179 | global GDBFLAGS | |
180 | global prompt | |
181 | global spawn_id | |
182 | global timeout | |
183 | if $verbose>1 then { | |
184 | send_user "Spawning $GDB $GDBFLAGS\n" | |
185 | } | |
186 | ||
187 | set oldtimeout $timeout | |
188 | set timeout [expr "$timeout + 60"] | |
189 | if [ llength $GDBFLAGS ] then { | |
190 | spawn $GDB $GDBFLAGS | |
191 | } else { | |
192 | spawn $GDB | |
193 | } | |
194 | expect { | |
195 | -re ".*$prompt $" { if $verbose>1 then { | |
196 | send_user "GDB initialized for native mode\n" } | |
197 | } | |
05a291bb RS |
198 | -re "$prompt $" { error "GDB never initialized."; return -1 } |
199 | timeout { error "(timeout) GDB never initialized."; return -1 } | |
19fa4a0a MW |
200 | } |
201 | set timeout $oldtimeout | |
202 | # force the height to "unlimited", so no pagers get used | |
203 | send "set height 0\n" | |
204 | expect -re ".*$prompt $" {} | |
205 | # force the width to "unlimited", so no wraparound occurs | |
206 | send "set width 0\n" | |
207 | expect -re ".*$prompt $" {} | |
208 | } | |
209 | ||
210 | expect_after { | |
211 | "<return>" { send "\n"; error "Window too small." } | |
212 | -re "\(y or n\) " { send "n\n"; error "Got interactive prompt." } | |
213 | buffer_full { error "internal buffer is full." } | |
214 | eof { error "eof -- pty is hosed." } | |
215 | timeout { error "timeout." } | |
216 | "virtual memory exhausted" { error "virtual memory exhausted." } | |
217 | "Undefined command" { error "send string probably wrong." } | |
218 | } | |
219 | ||
220 | load_lib gdb.exp | |
221 | ||
222 | set binpath /s1/users/rob/vxworks/bin/somewhere-bogus-that-needs-configuring | |
223 | set bin $GDB | |
224 | ||
225 | gdb_start | |
226 |