Updated copyright notices for most files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / step.exp
CommitLineData
c906108c 1# step.exp -- Expect script to test gdb with step.c
9b254dd1 2# Copyright (C) 1992, 1997, 2007, 2008 Free Software Foundation, Inc.
c906108c
SS
3
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c
SS
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file was written by Hiro Sugawara. (hiro@lynx.com)
21#
22# This test really needs some major surgery to be acceptable, but
23# I'm just about burnt out on lynx work, so I'm not doing it now.
24#
25# * The test has an indeterminate number of pass/fails
26# for each run (it runs a small group of tests until
27# it's timer kicks off). This is very bad for nightly
28# automated regression testing.
29#
30# * It tries to "step" from withint he prologue of a
31# function. This isn't support in gdb (it's going
32# to act like a continue).
33#
34# * This test rarely check that it stopped in sensible
35# places. (see previous bullet -- this test doesn't
36# catch the fact it continued rather than stepped)
37
38
39if $tracelevel then {
40 strace $tracelevel
41}
42
43set program_exited 0
44
45proc set_bp { where } {
46 global gdb_prompt
47
48 send_gdb "break $where\n"
49 # The first regexp is what we get with -g, the second without -g.
50 gdb_expect {
51 -re "Break.* at .*: file .*, line \[0-9\]*.*$gdb_prompt $" {}
52 -re "Breakpoint \[0-9\]* at 0x\[0-9a-f\]*.*$gdb_prompt $" {}
53 -re "$gdb_prompt $" { fail "setting breakpoint at $where" ; return 0 }
54 timeout { fail "setting breakpoint at $where (timeout)" ; return 0 }
55 }
56 pass "set_bp"
57}
58
59proc step_it { cmd } {
60 global gdb_prompt
61 global program_exited
62
63 send_gdb "$cmd\n"
64 gdb_expect {
65 -re "0x\[0-9A-Fa-f\]* *in.*\r\n$gdb_prompt $" { pass "step_it"; return 0 }
66 -re "0x\[0-9A-Fa-f\]* *\[0-9\]*.*\r\n$gdb_prompt $" { pass "step_it"; return 1 }
67 -re "Program exited .*\n$gdb_prompt $" {
68 set program_exited 1
69 return -1
70 }
71 -re "$gdb_prompt $" { fail "single-stepping ($cmd).\n" ; return -1 }
72 timeout { fail "single-stepping ($cmd) timout.\n" ; return -1 }
73 }
74}
75
76proc step_inst {} {
77 step_it "stepi"
78}
79
80proc step_source {} {
81 step_it "step"
82}
83
84proc continue_all {} {
85 global gdb_prompt
86
87 send_gdb "continue\n"
88 gdb_expect {
89 -re "Breakpoint \[0-9\]*, thread\[0-9\]* .*$gdb_prompt $" {
90 pass "continue_all"
91 return 0
92 }
93 -re "Program exited .*\n$gdb_prompt $" {
94 set program_exited 1
95 return 1;
96 }
97 -re "$gdb_prompt $" { fail "continue" ; return -1 }
98 timeout { fail "continue (timeout)" ; return -1 }
99 }
100}
101
102proc check_threads { num_threads } {
103 global gdb_prompt
104
105 set curr_thread 0
106 send_gdb "info threads\n"
107 while { $num_threads > 0 } {
108 gdb_expect {
109 -re "\\* *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
110 incr curr_thread
111 set num_threads [expr $num_threads - 1]
112 }
113 -re " *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
114 set num_threads [expr $num_threads - 1]
115 }
116 -re "$gdb_prompt $" {
117 if { $num_threads < 0 } {
118 fail "check_threads (too many)" ; return -1
119 }
120 break
121 }
122 timeout { fail "check_threads (timeout)" ; return -1 }
123 }
124 }
125
126 if { $curr_thread == 0 } {
127 fail "check_threads (no current thread)\n"
128 return -1
129 }
130 if { $curr_thread > 1 } {
131 fail "check_threads (more than one current thread)\n"
132 return -1
133 }
134 return 0
135}
136
137proc test_cond_wait {} {
138 global program_exited
139
140 set_bp 135
141 runto 179
142 while { 1 } {
143 set stepi_counter 0
144 while { [step_inst] } {
145 if { $program_exited } { break }
146 incr stepi_counter
147 if { $stepi_counter > 30 } {
148 fail "too many stepi's per line\n"
149 return -1
150 }
151 }
152 if { $program_exited } { break }
153 step_source
154 if { $program_exited } { break }
155 continue_all
156 if { $program_exited } { break }
157 check_threads 3
158 }
159}
160
161proc do_tests {} {
162 global prms_id
163 global bug_id
164 global subdir
165 global objdir
166 global srcdir
167 global binfile
168 global gdb_prompt
169
170 set prms_id 0
171 set bug_id 0
172
173 # Start with a fresh gdb.
174
175 gdb_exit
176 gdb_start
177 gdb_reinitialize_dir $srcdir/$subdir
178 gdb_load $objdir/$subdir/$binfile
179
180 send_gdb "set width 0\n"
181 gdb_expect -re "$gdb_prompt $"
182
183 test_cond_wait
184}
185
186# Check to see if we have an executable to test. If not, then either we
187# haven't tried to compile one, or the compilation failed for some reason.
188# In either case, just notify the user and skip the tests in this file.
189
190set binfile "step"
191set srcfile "step.c"
192
193if ![file exists $objdir/$subdir/$binfile] then {
194 if $all_flag then {
195 warning "$binfile does not exist; tests suppressed."
196 }
197} else {
198 do_tests
199}
This page took 0.804863 seconds and 4 git commands to generate.