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