Commit | Line | Data |
---|---|---|
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 | 16 | |
c906108c SS |
17 | # This file was written by Hiro Sugawara. (hiro@lynx.com) |
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 | if $tracelevel then { | |
37 | strace $tracelevel | |
38 | } | |
39 | ||
40 | set program_exited 0 | |
41 | ||
42 | proc set_bp { where } { | |
43 | global gdb_prompt | |
44 | ||
45 | send_gdb "break $where\n" | |
46 | # The first regexp is what we get with -g, the second without -g. | |
47 | gdb_expect { | |
48 | -re "Break.* at .*: file .*, line \[0-9\]*.*$gdb_prompt $" {} | |
49 | -re "Breakpoint \[0-9\]* at 0x\[0-9a-f\]*.*$gdb_prompt $" {} | |
50 | -re "$gdb_prompt $" { fail "setting breakpoint at $where" ; return 0 } | |
51 | timeout { fail "setting breakpoint at $where (timeout)" ; return 0 } | |
52 | } | |
53 | pass "set_bp" | |
54 | } | |
55 | ||
56 | proc step_it { cmd } { | |
57 | global gdb_prompt | |
58 | global program_exited | |
59 | ||
60 | send_gdb "$cmd\n" | |
61 | gdb_expect { | |
62 | -re "0x\[0-9A-Fa-f\]* *in.*\r\n$gdb_prompt $" { pass "step_it"; return 0 } | |
63 | -re "0x\[0-9A-Fa-f\]* *\[0-9\]*.*\r\n$gdb_prompt $" { pass "step_it"; return 1 } | |
64 | -re "Program exited .*\n$gdb_prompt $" { | |
65 | set program_exited 1 | |
66 | return -1 | |
67 | } | |
68 | -re "$gdb_prompt $" { fail "single-stepping ($cmd).\n" ; return -1 } | |
69 | timeout { fail "single-stepping ($cmd) timout.\n" ; return -1 } | |
70 | } | |
71 | } | |
72 | ||
73 | proc step_inst {} { | |
74 | step_it "stepi" | |
75 | } | |
76 | ||
77 | proc step_source {} { | |
78 | step_it "step" | |
79 | } | |
80 | ||
81 | proc continue_all {} { | |
82 | global gdb_prompt | |
83 | ||
84 | send_gdb "continue\n" | |
85 | gdb_expect { | |
86 | -re "Breakpoint \[0-9\]*, thread\[0-9\]* .*$gdb_prompt $" { | |
87 | pass "continue_all" | |
88 | return 0 | |
89 | } | |
90 | -re "Program exited .*\n$gdb_prompt $" { | |
91 | set program_exited 1 | |
92 | return 1; | |
93 | } | |
94 | -re "$gdb_prompt $" { fail "continue" ; return -1 } | |
95 | timeout { fail "continue (timeout)" ; return -1 } | |
96 | } | |
97 | } | |
98 | ||
99 | proc check_threads { num_threads } { | |
100 | global gdb_prompt | |
101 | ||
102 | set curr_thread 0 | |
103 | send_gdb "info threads\n" | |
104 | while { $num_threads > 0 } { | |
105 | gdb_expect { | |
106 | -re "\\* *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" { | |
107 | incr curr_thread | |
108 | set num_threads [expr $num_threads - 1] | |
109 | } | |
110 | -re " *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" { | |
111 | set num_threads [expr $num_threads - 1] | |
112 | } | |
113 | -re "$gdb_prompt $" { | |
114 | if { $num_threads < 0 } { | |
115 | fail "check_threads (too many)" ; return -1 | |
116 | } | |
117 | break | |
118 | } | |
119 | timeout { fail "check_threads (timeout)" ; return -1 } | |
120 | } | |
121 | } | |
122 | ||
123 | if { $curr_thread == 0 } { | |
124 | fail "check_threads (no current thread)\n" | |
125 | return -1 | |
126 | } | |
127 | if { $curr_thread > 1 } { | |
128 | fail "check_threads (more than one current thread)\n" | |
129 | return -1 | |
130 | } | |
131 | return 0 | |
132 | } | |
133 | ||
134 | proc test_cond_wait {} { | |
135 | global program_exited | |
136 | ||
137 | set_bp 135 | |
138 | runto 179 | |
139 | while { 1 } { | |
140 | set stepi_counter 0 | |
141 | while { [step_inst] } { | |
142 | if { $program_exited } { break } | |
143 | incr stepi_counter | |
144 | if { $stepi_counter > 30 } { | |
145 | fail "too many stepi's per line\n" | |
146 | return -1 | |
147 | } | |
148 | } | |
149 | if { $program_exited } { break } | |
150 | step_source | |
151 | if { $program_exited } { break } | |
152 | continue_all | |
153 | if { $program_exited } { break } | |
154 | check_threads 3 | |
155 | } | |
156 | } | |
157 | ||
158 | proc do_tests {} { | |
159 | global prms_id | |
160 | global bug_id | |
161 | global subdir | |
162 | global objdir | |
163 | global srcdir | |
164 | global binfile | |
165 | global gdb_prompt | |
166 | ||
167 | set prms_id 0 | |
168 | set bug_id 0 | |
169 | ||
170 | # Start with a fresh gdb. | |
171 | ||
172 | gdb_exit | |
173 | gdb_start | |
174 | gdb_reinitialize_dir $srcdir/$subdir | |
175 | gdb_load $objdir/$subdir/$binfile | |
176 | ||
177 | send_gdb "set width 0\n" | |
178 | gdb_expect -re "$gdb_prompt $" | |
179 | ||
180 | test_cond_wait | |
181 | } | |
182 | ||
183 | # Check to see if we have an executable to test. If not, then either we | |
184 | # haven't tried to compile one, or the compilation failed for some reason. | |
185 | # In either case, just notify the user and skip the tests in this file. | |
186 | ||
187 | set binfile "step" | |
188 | set srcfile "step.c" | |
189 | ||
190 | if ![file exists $objdir/$subdir/$binfile] then { | |
191 | if $all_flag then { | |
192 | warning "$binfile does not exist; tests suppressed." | |
193 | } | |
194 | } else { | |
195 | do_tests | |
196 | } |