1 # Copyright 1998-2013 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 set testfile1 "average"
19 set testfile "dbx-test"
20 set binfile1 ${objdir}/${subdir}/${testfile1}
21 set binfile2 ${objdir}/${subdir}/${testfile2}
22 set binfile ${objdir}/${subdir}/${testfile}
26 if { [gdb_compile "${srcdir}/${subdir}/average.c" "${binfile1}.o" object {debug}] != "" } {
31 if { [gdb_compile "${srcdir}/${subdir}/sum.c" "${binfile2}.o" object {debug}] != "" } {
36 if { [gdb_compile "${binfile1}.o ${binfile2}.o" ${binfile} executable {debug}] != "" } {
42 # start gdb -- start gdb running, default procedure
44 proc dbx_gdb_start { } {
47 global INTERNAL_GDBFLAGS GDBFLAGS
51 verbose "Spawning $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS"
53 if { [which $GDB] == 0 } then {
54 perror "$GDB does not exist."
58 set oldtimeout $timeout
59 set timeout [expr "$timeout + 60"]
60 eval "spawn $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS"
62 -re ".*\r\n$gdb_prompt $" {
63 verbose "GDB initialized."
66 perror "GDB never initialized."
70 perror "(timeout) GDB never initialized."
74 set timeout $oldtimeout
75 # force the height to "unlimited", so no pagers get used
76 send_gdb "set height 0\n"
79 verbose "Setting height to 0." 2
82 warning "Couldn't set the height to 0."
85 # force the width to "unlimited", so no wraparound occurs
86 send_gdb "set width 0\n"
89 verbose "Setting width to 0." 2
92 warning "Couldn't set the width to 0."
98 proc dbx_reinitialize_dir { subdir } {
103 -re "Reinitialize source path to empty.*y or n. " {
106 -re "Source directories searched.*$gdb_prompt $" {
107 send_gdb "use $subdir\n"
109 -re "Source directories searched.*$gdb_prompt $" {
110 verbose "Dir set to $subdir"
112 -re ".*$gdb_prompt $" {
113 perror "Dir \"$subdir\" failed."
117 -re ".*$gdb_prompt $" {
118 perror "Dir \"$subdir\" failed."
122 -re ".*$gdb_prompt $" {
123 perror "Dir \"$subdir\" failed."
128 # In "testsuite/config/unix-gdb.exp", the routine "gdb_load"
129 # is defined as "gdb_file_cmd". The binding of "gdb_file_cmd"
130 # is done at invocation time. Before this file is processed,
131 # it binds to the definition in "testsuite/lib/gdb.exp"; after
132 # this file is processed, it binds to this definition.
133 # TCL lets us overrides a previous routine definition without a
134 # warning (isn't that special?).
136 # This means that tests before use "file" to load a target, and
137 # tests afterwards use the pair "symbol-file" "exec-file".
139 # I'm leaving it as it is for now because at the moment it
140 # is the only test we have of the use of the combination of
141 # "symbol-file" and "exec-file" to load a debugging target (the
142 # other definition uses "file".
144 # Symbol-file and exec-file should be tested explicitly, not
145 # as a side effect of running a particular test (in this case,
146 # "testsuite/gdb.compat/dbx.exp").
148 # CM: Renamed the procedure so it does not override the orginal file name.
149 # Having the test suite change behavior depending on the tests run makes
150 # it extremely difficult to reproduce errors. I've also added a
151 # "dbx_gdb_load" procedure. This and only this test will call these
152 # procedures now. I also added an "expect" to the "send exec-file" line.
153 # The "expect" waits for a prompt to appear. Otherwise, if the tests run
154 # too quickly, the caller could send another command before the prompt
155 # of this command returns, causing the test to get out of sync and fail
156 # seemingly randomly or only on a loaded system.
158 # Problem is, though, that the testsuite config files can override the definition of
159 # gdb_load (without notice, as was mentioned above). Unfortunately, the gdb_load proc
160 # that was copied into this test was a copy of the unix native version.
162 # The real problem that we're attempting to solve is how to load an exec and symbol
163 # file into gdb for a dbx session. So why not just override gdb_file_cmd with the
164 # right sequence of events, allowing gdb_load to do its normal thing? This way
165 # remotes and simulators will work, too.
167 # [drow 2002-03-30]: We can restore the old gdb_file_cmd afterwards, though.
168 set old_gdb_file_cmd_args [info args gdb_file_cmd]
169 set old_gdb_file_cmd_body [info body gdb_file_cmd]
171 proc gdb_file_cmd {arg} {
178 upvar timeout timeout
179 global last_loaded_file
181 set last_loaded_file $arg
183 if [is_remote host] {
184 set arg [remote_download host $arg];
186 error "download failed"
191 send_gdb "symbol-file $arg\n"
193 -re "Detected 64-bit symbol file.\r\nInvoking.*gdb64.*$gdb_prompt $" {
194 verbose "\t\tLoaded $arg into the $GDB"
195 send_gdb "exec-file $arg\n"
197 -re ".*$gdb_prompt $" {
198 verbose "\t\tLoaded $arg with new symbol table into $GDB"
202 perror "(timeout) Couldn't load $arg"
208 -re "Reading symbols from.*done.*$gdb_prompt $" {
209 verbose "\t\tLoaded $arg into the $GDB"
210 send_gdb "exec-file $arg\n"
212 -re "A program is being debugged already.*Kill it.*y or n. $" {
214 verbose "\t\tKilling previous program being debugged"
217 -re ".*$gdb_prompt $" {
218 verbose "\t\tLoaded $arg with new symbol table into $GDB"
222 perror "(timeout) Couldn't load $arg"
228 -re "has no symbol-table.*$gdb_prompt $" {
229 perror "$arg wasn't compiled with \"-g\""
232 -re "Load new symbol table from \".*\".*y or n. $" {
236 -re ".*No such file or directory.*$gdb_prompt $" {
237 perror "($arg) No such file or directory\n"
240 -re "$gdb_prompt $" {
241 perror "couldn't load $arg into $GDB."
245 perror "couldn't load $arg into $GDB (timed out)."
249 # This is an attempt to detect a core dump, but seems not to
250 # work. Perhaps we need to match .* followed by eof, in which
251 # expect does not seem to have a way to do that.
252 perror "couldn't load $arg into $GDB (end of file)."
261 proc test_breakpoints { } {
262 gdb_test "stop in main" "Breakpoint.*at.*: file.*average\.c, line 38\."
263 gdb_test "status" "Num.*Type.*Disp.*Enb.*Address.*What\r\n1\[ \r\]+breakpoint\[ \r\]+keep y.*in main at.*average\.c:38.*"
264 gdb_test "stop at average.c:43" "Breakpoint.*at.*: file.*average\.c, line 43.*"
265 gdb_test "stop in average.c:43" "Usage: stop in <function . address>"
266 gdb_test "stop at main" "Usage: stop at <line>"
272 proc test_assign { } {
278 -re "Break.* at .*:$decimal.*$gdb_prompt $" { pass "running to main" }
279 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { pass "running to main" }
280 -re "$gdb_prompt $" { fail "running to main" }
281 timeout { fail "running to main (timeout)" }
283 send_gdb "assign first=1\n"
285 -re "No symbol \"first\" in current context.*$" { fail "assign first" }
286 -re "$gdb_prompt $" { pass "assign first" }
287 timeout { fail "assign first (timeout)" }
289 gdb_test "print first" ".1 = 1"
295 proc test_whereis { } {
296 gdb_test "whereis my_list" "All variables matching regular expression \"my_list\":\r\n\r\nFile.*average\.c:\r\nstatic int my_list\\\[10\\\];"
303 gdb_test "cont" ".*" "cont 1"
305 # This always fails, but it's not clear why. -sts 1999-08-17
307 gdb_test "func sum" "'sum' not within current stack frame\."
308 gdb_test "stop in sum" "Breakpoint.*at.*: file.*sum\.c, line 11\."
309 gdb_test "cont" ".*" "cont 2"
310 # This always fails, but it's not clear why. -sts 1999-08-17
312 gdb_test "func print_average" ".*in print_average.*\\(list=.*, low=0, high=6\\).*at.*average\.c:24\r\n24\[ \t\]+total = sum\\(list, low, high\\);"
315 # Start with a fresh gdb.
319 set saved_gdbflags $GDBFLAGS
321 set GDBFLAGS "$GDBFLAGS --dbx"
323 dbx_reinitialize_dir $srcdir/$subdir
329 gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*"
335 set GDBFLAGS $saved_gdbflags
336 eval proc gdb_file_cmd {$old_gdb_file_cmd_args} {$old_gdb_file_cmd_body}