1 # Copyright 1998-2020 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 standard_testfile average.c sum.c
19 if {[build_executable $testfile.exp $testfile \
20 [list $srcfile $srcfile2] debug] == -1} {
21 untested "failed to compile"
26 # start gdb -- start gdb running, default procedure
28 proc dbx_gdb_start { } {
30 global INTERNAL_GDBFLAGS GDBFLAGS
34 verbose "Spawning $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS"
36 if { [which $GDB] == 0 } then {
37 perror "$GDB does not exist."
41 set oldtimeout $timeout
42 set timeout [expr "$timeout + 60"]
43 eval "spawn $GDB -dbx $INTERNAL_GDBFLAGS $GDBFLAGS"
45 -re ".*\r\n$gdb_prompt $" {
46 verbose "GDB initialized."
49 perror "GDB never initialized."
53 perror "(timeout) GDB never initialized."
57 set timeout $oldtimeout
58 # force the height to "unlimited", so no pagers get used
59 send_gdb "set height 0\n"
62 verbose "Setting height to 0." 2
65 warning "Couldn't set the height to 0."
68 # force the width to "unlimited", so no wraparound occurs
69 send_gdb "set width 0\n"
72 verbose "Setting width to 0." 2
75 warning "Couldn't set the width to 0."
81 proc dbx_reinitialize_dir { subdir } {
86 -re "Reinitialize source path to empty.*y or n. " {
89 -re "Source directories searched.*$gdb_prompt $" {
90 send_gdb "use $subdir\n"
92 -re "Source directories searched.*$gdb_prompt $" {
93 verbose "Dir set to $subdir"
95 -re ".*$gdb_prompt $" {
96 perror "Dir \"$subdir\" failed."
100 -re ".*$gdb_prompt $" {
101 perror "Dir \"$subdir\" failed."
105 -re ".*$gdb_prompt $" {
106 perror "Dir \"$subdir\" failed."
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?).
119 # This means that tests before use "file" to load a target, and
120 # tests afterwards use the pair "symbol-file" "exec-file".
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".
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").
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.
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.
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.
151 proc local_gdb_file_cmd {arg} {
157 upvar timeout timeout
158 global last_loaded_file
160 set last_loaded_file $arg
162 if [is_remote host] {
163 set arg [remote_download host $arg]
165 error "download failed"
170 send_gdb "symbol-file $arg\n"
172 -re "Reading symbols from.*$gdb_prompt $" {
173 verbose "\t\tLoaded $arg into the $GDB"
174 send_gdb "exec-file $arg\n"
176 -re "A program is being debugged already.*Kill it.*y or n. $" {
178 verbose "\t\tKilling previous program being debugged"
181 -re ".*$gdb_prompt $" {
182 verbose "\t\tLoaded $arg with new symbol table into $GDB"
186 perror "(timeout) Couldn't load $arg"
192 -re "has no symbol-table.*$gdb_prompt $" {
193 perror "$arg wasn't compiled with \"-g\""
196 -re "Load new symbol table from \".*\".*y or n. $" {
200 -re ".*No such file or directory.*$gdb_prompt $" {
201 perror "($arg) No such file or directory\n"
204 -re "$gdb_prompt $" {
205 perror "couldn't load $arg into $GDB."
209 perror "couldn't load $arg into $GDB (timed out)."
213 # This is an attempt to detect a core dump, but seems not to
214 # work. Perhaps we need to match .* followed by eof, in which
215 # expect does not seem to have a way to do that.
216 perror "couldn't load $arg into $GDB (end of file)."
225 proc test_breakpoints { } {
226 set stop_line [gdb_get_line_number "stop-in-main"]
227 gdb_test "stop in main" "Breakpoint.*at.*: file.*average\.c, line $stop_line\."
228 gdb_test "status" "Num.*Type.*Disp.*Enb.*Address.*What\r\n1\[ \r\]+breakpoint\[ \r\]+keep y.*in main at.*average\.c:$stop_line.*"
229 set stop_line [gdb_get_line_number "stop-at-call"]
230 gdb_test "stop at average.c:$stop_line" "Breakpoint.*at.*: file.*average\.c, line $stop_line.*"
231 gdb_test "stop in average.c:$stop_line" "Usage: stop in <function . address>"
232 gdb_test "stop at main" "Usage: stop at LINE"
238 proc test_assign { } {
243 set test "running to main"
244 gdb_test_multiple "" $test {
245 -re "Break.* at .*:$decimal.*$gdb_prompt $" {
248 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" {
252 send_gdb "assign first=1\n"
254 -re "No symbol \"first\" in current context.*$" { fail "assign first" }
255 -re "$gdb_prompt $" { pass "assign first" }
256 timeout { fail "assign first (timeout)" }
258 gdb_test "print first" ".1 = 1"
264 proc test_whereis { } {
265 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\\\];"
274 gdb_test "cont" ".*" "cont 1"
276 gdb_test "func sum" "'sum' not within current stack frame\."
277 set stop_line [gdb_get_line_number "stop-in-sum" $srcfile2]
278 gdb_test "stop in sum" "Breakpoint.*at.*: file.*sum\.c, line $stop_line\."
279 gdb_test "cont" ".*" "cont 2"
280 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\\);"
283 # Start with a fresh gdb.
287 with_override gdb_file_cmd local_gdb_file_cmd {
289 set GDBFLAGS "$GDBFLAGS --dbx"
292 dbx_reinitialize_dir $srcdir/$subdir
298 gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*"