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