Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / gdb.threads / step.exp
blobaa5639347b766c5b4fb9723573cc0ddf0fea599b
1 # step.exp -- Expect script to test gdb with step.c
2 # Copyright (C) 1992, 1997 Free Software Foundation, Inc.
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.
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.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Hiro Sugawara. (hiro@lynx.com)
23 # This test really needs some major surgery to be acceptable, but
24 # I'm just about burnt out on lynx work, so I'm not doing it now.
26 # * The test has an indeterminate number of pass/fails
27 # for each run (it runs a small group of tests until
28 # it's timer kicks off). This is very bad for nightly
29 # automated regression testing.
31 # * It tries to "step" from withint he prologue of a
32 # function. This isn't support in gdb (it's going
33 # to act like a continue).
35 # * This test rarely check that it stopped in sensible
36 # places. (see previous bullet -- this test doesn't
37 # catch the fact it continued rather than stepped)
40 if $tracelevel then {
41 strace $tracelevel
44 set program_exited 0
46 proc set_bp { where } {
47 global gdb_prompt
49 send_gdb "break $where\n"
50 # The first regexp is what we get with -g, the second without -g.
51 gdb_expect {
52 -re "Break.* at .*: file .*, line \[0-9\]*.*$gdb_prompt $" {}
53 -re "Breakpoint \[0-9\]* at 0x\[0-9a-f\]*.*$gdb_prompt $" {}
54 -re "$gdb_prompt $" { fail "setting breakpoint at $where" ; return 0 }
55 timeout { fail "setting breakpoint at $where (timeout)" ; return 0 }
57 pass "set_bp"
60 proc step_it { cmd } {
61 global gdb_prompt
62 global program_exited
64 send_gdb "$cmd\n"
65 gdb_expect {
66 -re "0x\[0-9A-Fa-f\]* *in.*\r\n$gdb_prompt $" { pass "step_it"; return 0 }
67 -re "0x\[0-9A-Fa-f\]* *\[0-9\]*.*\r\n$gdb_prompt $" { pass "step_it"; return 1 }
68 -re "Program exited .*\n$gdb_prompt $" {
69 set program_exited 1
70 return -1
72 -re "$gdb_prompt $" { fail "single-stepping ($cmd).\n" ; return -1 }
73 timeout { fail "single-stepping ($cmd) timout.\n" ; return -1 }
77 proc step_inst {} {
78 step_it "stepi"
81 proc step_source {} {
82 step_it "step"
85 proc continue_all {} {
86 global gdb_prompt
88 send_gdb "continue\n"
89 gdb_expect {
90 -re "Breakpoint \[0-9\]*, thread\[0-9\]* .*$gdb_prompt $" {
91 pass "continue_all"
92 return 0
94 -re "Program exited .*\n$gdb_prompt $" {
95 set program_exited 1
96 return 1;
98 -re "$gdb_prompt $" { fail "continue" ; return -1 }
99 timeout { fail "continue (timeout)" ; return -1 }
103 proc check_threads { num_threads } {
104 global gdb_prompt
106 set curr_thread 0
107 send_gdb "info threads\n"
108 while { $num_threads > 0 } {
109 gdb_expect {
110 -re "\\* *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
111 incr curr_thread
112 set num_threads [expr $num_threads - 1]
114 -re " *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
115 set num_threads [expr $num_threads - 1]
117 -re "$gdb_prompt $" {
118 if { $num_threads < 0 } {
119 fail "check_threads (too many)" ; return -1
121 break
123 timeout { fail "check_threads (timeout)" ; return -1 }
127 if { $curr_thread == 0 } {
128 fail "check_threads (no current thread)\n"
129 return -1
131 if { $curr_thread > 1 } {
132 fail "check_threads (more than one current thread)\n"
133 return -1
135 return 0
138 proc test_cond_wait {} {
139 global program_exited
141 set_bp 135
142 runto 179
143 while { 1 } {
144 set stepi_counter 0
145 while { [step_inst] } {
146 if { $program_exited } { break }
147 incr stepi_counter
148 if { $stepi_counter > 30 } {
149 fail "too many stepi's per line\n"
150 return -1
153 if { $program_exited } { break }
154 step_source
155 if { $program_exited } { break }
156 continue_all
157 if { $program_exited } { break }
158 check_threads 3
162 proc do_tests {} {
163 global prms_id
164 global bug_id
165 global subdir
166 global objdir
167 global srcdir
168 global binfile
169 global gdb_prompt
171 set prms_id 0
172 set bug_id 0
174 # Start with a fresh gdb.
176 gdb_exit
177 gdb_start
178 gdb_reinitialize_dir $srcdir/$subdir
179 gdb_load $objdir/$subdir/$binfile
181 send_gdb "set width 0\n"
182 gdb_expect -re "$gdb_prompt $"
184 test_cond_wait
187 # Check to see if we have an executable to test. If not, then either we
188 # haven't tried to compile one, or the compilation failed for some reason.
189 # In either case, just notify the user and skip the tests in this file.
191 set binfile "step"
192 set srcfile "step.c"
194 if ![file exists $objdir/$subdir/$binfile] then {
195 if $all_flag then {
196 warning "$binfile does not exist; tests suppressed."
198 } else {
199 do_tests