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.
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.
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.
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/>.
18 # This file was written by Hiro Sugawara. (hiro@lynx.com)
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.
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.
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).
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)
43 proc set_bp { where } {
46 send_gdb "break $where\n"
47 # The first regexp is what we get with -g, the second without -g.
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 }
57 proc step_it { cmd } {
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 $" {
69 -re "$gdb_prompt $" { fail "single-stepping ($cmd).\n" ; return -1 }
70 timeout { fail "single-stepping ($cmd) timout.\n" ; return -1 }
82 proc continue_all {} {
87 -re "Breakpoint \[0-9\]*, thread\[0-9\]* .*$gdb_prompt $" {
91 -re "Program exited .*\n$gdb_prompt $" {
95 -re "$gdb_prompt $" { fail "continue" ; return -1 }
96 timeout { fail "continue (timeout)" ; return -1 }
100 proc check_threads { num_threads } {
104 send_gdb "info threads\n"
105 while { $num_threads > 0 } {
107 -re "\\* *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
109 set num_threads [expr $num_threads - 1]
111 -re " *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
112 set num_threads [expr $num_threads - 1]
114 -re "$gdb_prompt $" {
115 if { $num_threads < 0 } {
116 fail "check_threads (too many)" ; return -1
120 timeout { fail "check_threads (timeout)" ; return -1 }
124 if { $curr_thread == 0 } {
125 fail "check_threads (no current thread)\n"
128 if { $curr_thread > 1 } {
129 fail "check_threads (more than one current thread)\n"
135 proc test_cond_wait {} {
136 global program_exited
142 while { [step_inst] } {
143 if { $program_exited } { break }
145 if { $stepi_counter > 30 } {
146 fail "too many stepi's per line\n"
150 if { $program_exited } { break }
152 if { $program_exited } { break }
154 if { $program_exited } { break }
167 # Start with a fresh gdb.
171 gdb_reinitialize_dir $srcdir/$subdir
172 gdb_load $objdir/$subdir/$binfile
174 send_gdb "set width 0\n"
175 gdb_expect -re "$gdb_prompt $"
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.
187 if ![file exists $objdir/$subdir/$binfile] then {
189 warning "$binfile does not exist; tests suppressed."