Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1998-2020 Free Software Foundation, Inc. |
74cf1395 JM |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
74cf1395 JM |
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 | |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
74cf1395 | 15 | |
74cf1395 | 16 | |
f76495c8 | 17 | standard_testfile average.c sum.c |
74cf1395 | 18 | |
f76495c8 TT |
19 | if {[build_executable $testfile.exp $testfile \ |
20 | [list $srcfile $srcfile2] debug] == -1} { | |
5b362f04 | 21 | untested "failed to compile" |
f76495c8 | 22 | return -1 |
74cf1395 JM |
23 | } |
24 | ||
25 | # | |
26 | # start gdb -- start gdb running, default procedure | |
27 | # | |
28 | proc dbx_gdb_start { } { | |
74cf1395 | 29 | global GDB |
6b8ce727 | 30 | global INTERNAL_GDBFLAGS GDBFLAGS |
74cf1395 JM |
31 | global prompt |
32 | global spawn_id | |
33 | global timeout | |
6b8ce727 | 34 | verbose "Spawning $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS" |
74cf1395 JM |
35 | |
36 | if { [which $GDB] == 0 } then { | |
37 | perror "$GDB does not exist." | |
38 | exit 1 | |
39 | } | |
40 | ||
41 | set oldtimeout $timeout | |
42 | set timeout [expr "$timeout + 60"] | |
6b8ce727 | 43 | eval "spawn $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS" |
74cf1395 JM |
44 | gdb_expect { |
45 | -re ".*\r\n$gdb_prompt $" { | |
46 | verbose "GDB initialized." | |
47 | } | |
48 | -re "$prompt $" { | |
49 | perror "GDB never initialized." | |
50 | return -1 | |
51 | } | |
52 | timeout { | |
53 | perror "(timeout) GDB never initialized." | |
54 | return -1 | |
55 | } | |
56 | } | |
57 | set timeout $oldtimeout | |
58 | # force the height to "unlimited", so no pagers get used | |
59 | send_gdb "set height 0\n" | |
60 | gdb_expect { | |
61 | -re ".*$prompt $" { | |
62 | verbose "Setting height to 0." 2 | |
63 | } | |
64 | timeout { | |
65 | warning "Couldn't set the height to 0." | |
66 | } | |
67 | } | |
68 | # force the width to "unlimited", so no wraparound occurs | |
69 | send_gdb "set width 0\n" | |
70 | gdb_expect { | |
71 | -re ".*$prompt $" { | |
72 | verbose "Setting width to 0." 2 | |
73 | } | |
74 | timeout { | |
75 | warning "Couldn't set the width to 0." | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
80 | ||
81 | proc dbx_reinitialize_dir { subdir } { | |
82 | global gdb_prompt | |
83 | ||
84 | send_gdb "use\n" | |
85 | gdb_expect { | |
86 | -re "Reinitialize source path to empty.*y or n. " { | |
87 | send_gdb "y\n" | |
88 | gdb_expect { | |
89 | -re "Source directories searched.*$gdb_prompt $" { | |
90 | send_gdb "use $subdir\n" | |
91 | gdb_expect { | |
92 | -re "Source directories searched.*$gdb_prompt $" { | |
93 | verbose "Dir set to $subdir" | |
94 | } | |
95 | -re ".*$gdb_prompt $" { | |
96 | perror "Dir \"$subdir\" failed." | |
97 | } | |
98 | } | |
99 | } | |
100 | -re ".*$gdb_prompt $" { | |
101 | perror "Dir \"$subdir\" failed." | |
102 | } | |
103 | } | |
104 | } | |
105 | -re ".*$gdb_prompt $" { | |
106 | perror "Dir \"$subdir\" failed." | |
107 | } | |
108 | } | |
109 | } | |
110 | ||
111 | # In "testsuite/config/unix-gdb.exp", the routine "gdb_load" | |
112 | # is defined as "gdb_file_cmd". The binding of "gdb_file_cmd" | |
113 | # is done at invocation time. Before this file is processed, | |
114 | # it binds to the definition in "testsuite/lib/gdb.exp"; after | |
115 | # this file is processed, it binds to this definition. | |
116 | # TCL lets us overrides a previous routine definition without a | |
117 | # warning (isn't that special?). | |
118 | # | |
119 | # This means that tests before use "file" to load a target, and | |
120 | # tests afterwards use the pair "symbol-file" "exec-file". | |
121 | # | |
122 | # I'm leaving it as it is for now because at the moment it | |
123 | # is the only test we have of the use of the combination of | |
124 | # "symbol-file" and "exec-file" to load a debugging target (the | |
125 | # other definition uses "file". | |
126 | # | |
127 | # Symbol-file and exec-file should be tested explicitly, not | |
128 | # as a side effect of running a particular test (in this case, | |
129 | # "testsuite/gdb.compat/dbx.exp"). | |
130 | # | |
131 | # CM: Renamed the procedure so it does not override the orginal file name. | |
132 | # Having the test suite change behavior depending on the tests run makes | |
133 | # it extremely difficult to reproduce errors. I've also added a | |
134 | # "dbx_gdb_load" procedure. This and only this test will call these | |
135 | # procedures now. I also added an "expect" to the "send exec-file" line. | |
136 | # The "expect" waits for a prompt to appear. Otherwise, if the tests run | |
137 | # too quickly, the caller could send another command before the prompt | |
138 | # of this command returns, causing the test to get out of sync and fail | |
139 | # seemingly randomly or only on a loaded system. | |
140 | # | |
7be570e7 JM |
141 | # Problem is, though, that the testsuite config files can override the definition of |
142 | # gdb_load (without notice, as was mentioned above). Unfortunately, the gdb_load proc | |
143 | # that was copied into this test was a copy of the unix native version. | |
144 | # | |
145 | # The real problem that we're attempting to solve is how to load an exec and symbol | |
146 | # file into gdb for a dbx session. So why not just override gdb_file_cmd with the | |
147 | # right sequence of events, allowing gdb_load to do its normal thing? This way | |
148 | # remotes and simulators will work, too. | |
1e50cda1 DJ |
149 | # |
150 | # [drow 2002-03-30]: We can restore the old gdb_file_cmd afterwards, though. | |
151 | set old_gdb_file_cmd_args [info args gdb_file_cmd] | |
152 | set old_gdb_file_cmd_body [info body gdb_file_cmd] | |
153 | ||
7be570e7 | 154 | proc gdb_file_cmd {arg} { |
74cf1395 JM |
155 | global loadpath |
156 | global loadfile | |
157 | global GDB | |
158 | global gdb_prompt | |
159 | global spawn_id | |
160 | upvar timeout timeout | |
b741e217 DJ |
161 | global last_loaded_file |
162 | ||
163 | set last_loaded_file $arg | |
74cf1395 | 164 | |
7be570e7 | 165 | if [is_remote host] { |
4ec70201 | 166 | set arg [remote_download host $arg] |
7be570e7 JM |
167 | if { $arg == "" } { |
168 | error "download failed" | |
ae59b1da | 169 | return -1 |
7be570e7 JM |
170 | } |
171 | } | |
172 | ||
74cf1395 JM |
173 | send_gdb "symbol-file $arg\n" |
174 | gdb_expect { | |
3453e7e4 | 175 | -re "Reading symbols from.*$gdb_prompt $" { |
74cf1395 JM |
176 | verbose "\t\tLoaded $arg into the $GDB" |
177 | send_gdb "exec-file $arg\n" | |
178 | gdb_expect { | |
1e50cda1 DJ |
179 | -re "A program is being debugged already.*Kill it.*y or n. $" { |
180 | send_gdb "y\n" | |
181 | verbose "\t\tKilling previous program being debugged" | |
182 | exp_continue | |
183 | } | |
74cf1395 JM |
184 | -re ".*$gdb_prompt $" { |
185 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
186 | return 0 | |
187 | } | |
188 | timeout { | |
189 | perror "(timeout) Couldn't load $arg" | |
190 | return -1 | |
191 | } | |
192 | } | |
193 | return 0 | |
194 | } | |
195 | -re "has no symbol-table.*$gdb_prompt $" { | |
196 | perror "$arg wasn't compiled with \"-g\"" | |
197 | return -1 | |
198 | } | |
74cf1395 JM |
199 | -re "Load new symbol table from \".*\".*y or n. $" { |
200 | send_gdb "y\n" | |
1e50cda1 | 201 | exp_continue |
74cf1395 JM |
202 | } |
203 | -re ".*No such file or directory.*$gdb_prompt $" { | |
204 | perror "($arg) No such file or directory\n" | |
205 | return -1 | |
206 | } | |
207 | -re "$gdb_prompt $" { | |
208 | perror "couldn't load $arg into $GDB." | |
209 | return -1 | |
210 | } | |
211 | timeout { | |
212 | perror "couldn't load $arg into $GDB (timed out)." | |
213 | return -1 | |
214 | } | |
215 | eof { | |
216 | # This is an attempt to detect a core dump, but seems not to | |
217 | # work. Perhaps we need to match .* followed by eof, in which | |
218 | # expect does not seem to have a way to do that. | |
219 | perror "couldn't load $arg into $GDB (end of file)." | |
220 | return -1 | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
74cf1395 JM |
225 | # |
226 | #test_breakpoints | |
227 | # | |
228 | proc test_breakpoints { } { | |
6acc2dde AA |
229 | set stop_line [gdb_get_line_number "stop-in-main"] |
230 | gdb_test "stop in main" "Breakpoint.*at.*: file.*average\.c, line $stop_line\." | |
231 | gdb_test "status" "Num.*Type.*Disp.*Enb.*Address.*What\r\n1\[ \r\]+breakpoint\[ \r\]+keep y.*in main at.*average\.c:$stop_line.*" | |
232 | set stop_line [gdb_get_line_number "stop-at-call"] | |
233 | gdb_test "stop at average.c:$stop_line" "Breakpoint.*at.*: file.*average\.c, line $stop_line.*" | |
234 | gdb_test "stop in average.c:$stop_line" "Usage: stop in <function . address>" | |
65e65158 | 235 | gdb_test "stop at main" "Usage: stop at LINE" |
74cf1395 JM |
236 | } |
237 | ||
238 | # | |
239 | #test_assign | |
240 | # | |
241 | proc test_assign { } { | |
7be570e7 JM |
242 | global decimal |
243 | global gdb_prompt | |
244 | ||
245 | gdb_run_cmd | |
fa43b1d7 PA |
246 | set test "running to main" |
247 | gdb_test_multiple "" $test { | |
248 | -re "Break.* at .*:$decimal.*$gdb_prompt $" { | |
249 | pass $test | |
250 | } | |
251 | -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { | |
252 | pass $test | |
253 | } | |
7be570e7 JM |
254 | } |
255 | send_gdb "assign first=1\n" | |
256 | gdb_expect { | |
257 | -re "No symbol \"first\" in current context.*$" { fail "assign first" } | |
5e5ebfe6 | 258 | -re "$gdb_prompt $" { pass "assign first" } |
7be570e7 JM |
259 | timeout { fail "assign first (timeout)" } |
260 | } | |
74cf1395 JM |
261 | gdb_test "print first" ".1 = 1" |
262 | } | |
263 | ||
264 | # | |
265 | #test_whereis | |
266 | # | |
267 | proc test_whereis { } { | |
e3a91079 | 268 | gdb_test "whereis my_list" "All variables matching regular expression \"my_list\":\r\n\r\nFile.*average\.c:\r\n.*\tstatic int my_list\\\[10\\\];" |
74cf1395 JM |
269 | } |
270 | ||
271 | # | |
272 | #test_func | |
273 | # | |
274 | proc test_func { } { | |
6acc2dde AA |
275 | global decimal |
276 | global srcfile2 | |
f6978de9 MS |
277 | gdb_test "cont" ".*" "cont 1" |
278 | gdb_test "step" ".*" | |
74cf1395 | 279 | gdb_test "func sum" "'sum' not within current stack frame\." |
6acc2dde AA |
280 | set stop_line [gdb_get_line_number "stop-in-sum" $srcfile2] |
281 | gdb_test "stop in sum" "Breakpoint.*at.*: file.*sum\.c, line $stop_line\." | |
f6978de9 | 282 | gdb_test "cont" ".*" "cont 2" |
9d622bda | 283 | gdb_test "func print_average" ".*in print_average.*\\(list=.*, low=0, high=6\\).*at.*average\.c:${decimal}\r\n${decimal}\[ \t\]+total = sum\\(list, low, high\\);" |
74cf1395 JM |
284 | } |
285 | ||
286 | # Start with a fresh gdb. | |
287 | ||
288 | gdb_exit | |
289 | global GDBFLAGS | |
290 | set saved_gdbflags $GDBFLAGS | |
291 | ||
292 | set GDBFLAGS "$GDBFLAGS --dbx" | |
293 | gdb_start | |
294 | dbx_reinitialize_dir $srcdir/$subdir | |
7be570e7 | 295 | gdb_load ${binfile} |
74cf1395 JM |
296 | |
297 | test_breakpoints | |
298 | test_assign | |
299 | test_whereis | |
300 | gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*" | |
301 | test_func | |
302 | ||
303 | #exit and cleanup | |
304 | gdb_exit | |
305 | ||
306 | set GDBFLAGS $saved_gdbflags | |
1e50cda1 DJ |
307 | eval proc gdb_file_cmd {$old_gdb_file_cmd_args} {$old_gdb_file_cmd_body} |
308 | ||
74cf1395 | 309 | return 0 |