# step.exp -- Expect script to test gdb with step.c
|
# step.exp -- Expect script to test gdb with step.c
|
# Copyright (C) 1992, 1997, 2007, 2008, 2009, 2010
|
# Copyright (C) 1992, 1997, 2007, 2008, 2009, 2010
|
# Free Software Foundation, Inc.
|
# Free Software Foundation, Inc.
|
|
|
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation; either version 3 of the License, or
|
# the Free Software Foundation; either version 3 of the License, or
|
# (at your option) any later version.
|
# (at your option) any later version.
|
#
|
#
|
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
#
|
#
|
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
# along with this program. If not, see .
|
# along with this program. If not, see .
|
|
|
# This file was written by Hiro Sugawara. (hiro@lynx.com)
|
# This file was written by Hiro Sugawara. (hiro@lynx.com)
|
#
|
#
|
# This test really needs some major surgery to be acceptable, but
|
# This test really needs some major surgery to be acceptable, but
|
# I'm just about burnt out on lynx work, so I'm not doing it now.
|
# I'm just about burnt out on lynx work, so I'm not doing it now.
|
#
|
#
|
# * The test has an indeterminate number of pass/fails
|
# * The test has an indeterminate number of pass/fails
|
# for each run (it runs a small group of tests until
|
# for each run (it runs a small group of tests until
|
# it's timer kicks off). This is very bad for nightly
|
# it's timer kicks off). This is very bad for nightly
|
# automated regression testing.
|
# automated regression testing.
|
#
|
#
|
# * It tries to "step" from withint he prologue of a
|
# * It tries to "step" from withint he prologue of a
|
# function. This isn't support in gdb (it's going
|
# function. This isn't support in gdb (it's going
|
# to act like a continue).
|
# to act like a continue).
|
#
|
#
|
# * This test rarely check that it stopped in sensible
|
# * This test rarely check that it stopped in sensible
|
# places. (see previous bullet -- this test doesn't
|
# places. (see previous bullet -- this test doesn't
|
# catch the fact it continued rather than stepped)
|
# catch the fact it continued rather than stepped)
|
|
|
|
|
if $tracelevel then {
|
if $tracelevel then {
|
strace $tracelevel
|
strace $tracelevel
|
}
|
}
|
|
|
set program_exited 0
|
set program_exited 0
|
|
|
proc set_bp { where } {
|
proc set_bp { where } {
|
global gdb_prompt
|
global gdb_prompt
|
|
|
send_gdb "break $where\n"
|
send_gdb "break $where\n"
|
# The first regexp is what we get with -g, the second without -g.
|
# The first regexp is what we get with -g, the second without -g.
|
gdb_expect {
|
gdb_expect {
|
-re "Break.* at .*: file .*, line \[0-9\]*.*$gdb_prompt $" {}
|
-re "Break.* at .*: file .*, line \[0-9\]*.*$gdb_prompt $" {}
|
-re "Breakpoint \[0-9\]* at 0x\[0-9a-f\]*.*$gdb_prompt $" {}
|
-re "Breakpoint \[0-9\]* at 0x\[0-9a-f\]*.*$gdb_prompt $" {}
|
-re "$gdb_prompt $" { fail "setting breakpoint at $where" ; return 0 }
|
-re "$gdb_prompt $" { fail "setting breakpoint at $where" ; return 0 }
|
timeout { fail "setting breakpoint at $where (timeout)" ; return 0 }
|
timeout { fail "setting breakpoint at $where (timeout)" ; return 0 }
|
}
|
}
|
pass "set_bp"
|
pass "set_bp"
|
}
|
}
|
|
|
proc step_it { cmd } {
|
proc step_it { cmd } {
|
global gdb_prompt
|
global gdb_prompt
|
global program_exited
|
global program_exited
|
|
|
send_gdb "$cmd\n"
|
send_gdb "$cmd\n"
|
gdb_expect {
|
gdb_expect {
|
-re "0x\[0-9A-Fa-f\]* *in.*\r\n$gdb_prompt $" { pass "step_it"; return 0 }
|
-re "0x\[0-9A-Fa-f\]* *in.*\r\n$gdb_prompt $" { pass "step_it"; return 0 }
|
-re "0x\[0-9A-Fa-f\]* *\[0-9\]*.*\r\n$gdb_prompt $" { pass "step_it"; return 1 }
|
-re "0x\[0-9A-Fa-f\]* *\[0-9\]*.*\r\n$gdb_prompt $" { pass "step_it"; return 1 }
|
-re "Program exited .*\n$gdb_prompt $" {
|
-re "Program exited .*\n$gdb_prompt $" {
|
set program_exited 1
|
set program_exited 1
|
return -1
|
return -1
|
}
|
}
|
-re "$gdb_prompt $" { fail "single-stepping ($cmd).\n" ; return -1 }
|
-re "$gdb_prompt $" { fail "single-stepping ($cmd).\n" ; return -1 }
|
timeout { fail "single-stepping ($cmd) timout.\n" ; return -1 }
|
timeout { fail "single-stepping ($cmd) timout.\n" ; return -1 }
|
}
|
}
|
}
|
}
|
|
|
proc step_inst {} {
|
proc step_inst {} {
|
step_it "stepi"
|
step_it "stepi"
|
}
|
}
|
|
|
proc step_source {} {
|
proc step_source {} {
|
step_it "step"
|
step_it "step"
|
}
|
}
|
|
|
proc continue_all {} {
|
proc continue_all {} {
|
global gdb_prompt
|
global gdb_prompt
|
|
|
send_gdb "continue\n"
|
send_gdb "continue\n"
|
gdb_expect {
|
gdb_expect {
|
-re "Breakpoint \[0-9\]*, thread\[0-9\]* .*$gdb_prompt $" {
|
-re "Breakpoint \[0-9\]*, thread\[0-9\]* .*$gdb_prompt $" {
|
pass "continue_all"
|
pass "continue_all"
|
return 0
|
return 0
|
}
|
}
|
-re "Program exited .*\n$gdb_prompt $" {
|
-re "Program exited .*\n$gdb_prompt $" {
|
set program_exited 1
|
set program_exited 1
|
return 1;
|
return 1;
|
}
|
}
|
-re "$gdb_prompt $" { fail "continue" ; return -1 }
|
-re "$gdb_prompt $" { fail "continue" ; return -1 }
|
timeout { fail "continue (timeout)" ; return -1 }
|
timeout { fail "continue (timeout)" ; return -1 }
|
}
|
}
|
}
|
}
|
|
|
proc check_threads { num_threads } {
|
proc check_threads { num_threads } {
|
global gdb_prompt
|
global gdb_prompt
|
|
|
set curr_thread 0
|
set curr_thread 0
|
send_gdb "info threads\n"
|
send_gdb "info threads\n"
|
while { $num_threads > 0 } {
|
while { $num_threads > 0 } {
|
gdb_expect {
|
gdb_expect {
|
-re "\\* *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
|
-re "\\* *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
|
incr curr_thread
|
incr curr_thread
|
set num_threads [expr $num_threads - 1]
|
set num_threads [expr $num_threads - 1]
|
}
|
}
|
-re " *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
|
-re " *\[0-9\]* process \[0-9\]* thread \[0-9\]* .*\n" {
|
set num_threads [expr $num_threads - 1]
|
set num_threads [expr $num_threads - 1]
|
}
|
}
|
-re "$gdb_prompt $" {
|
-re "$gdb_prompt $" {
|
if { $num_threads < 0 } {
|
if { $num_threads < 0 } {
|
fail "check_threads (too many)" ; return -1
|
fail "check_threads (too many)" ; return -1
|
}
|
}
|
break
|
break
|
}
|
}
|
timeout { fail "check_threads (timeout)" ; return -1 }
|
timeout { fail "check_threads (timeout)" ; return -1 }
|
}
|
}
|
}
|
}
|
|
|
if { $curr_thread == 0 } {
|
if { $curr_thread == 0 } {
|
fail "check_threads (no current thread)\n"
|
fail "check_threads (no current thread)\n"
|
return -1
|
return -1
|
}
|
}
|
if { $curr_thread > 1 } {
|
if { $curr_thread > 1 } {
|
fail "check_threads (more than one current thread)\n"
|
fail "check_threads (more than one current thread)\n"
|
return -1
|
return -1
|
}
|
}
|
return 0
|
return 0
|
}
|
}
|
|
|
proc test_cond_wait {} {
|
proc test_cond_wait {} {
|
global program_exited
|
global program_exited
|
|
|
set_bp 135
|
set_bp 135
|
runto 179
|
runto 179
|
while { 1 } {
|
while { 1 } {
|
set stepi_counter 0
|
set stepi_counter 0
|
while { [step_inst] } {
|
while { [step_inst] } {
|
if { $program_exited } { break }
|
if { $program_exited } { break }
|
incr stepi_counter
|
incr stepi_counter
|
if { $stepi_counter > 30 } {
|
if { $stepi_counter > 30 } {
|
fail "too many stepi's per line\n"
|
fail "too many stepi's per line\n"
|
return -1
|
return -1
|
}
|
}
|
}
|
}
|
if { $program_exited } { break }
|
if { $program_exited } { break }
|
step_source
|
step_source
|
if { $program_exited } { break }
|
if { $program_exited } { break }
|
continue_all
|
continue_all
|
if { $program_exited } { break }
|
if { $program_exited } { break }
|
check_threads 3
|
check_threads 3
|
}
|
}
|
}
|
}
|
|
|
proc do_tests {} {
|
proc do_tests {} {
|
global prms_id
|
global prms_id
|
global bug_id
|
global bug_id
|
global subdir
|
global subdir
|
global objdir
|
global objdir
|
global srcdir
|
global srcdir
|
global binfile
|
global binfile
|
global gdb_prompt
|
global gdb_prompt
|
|
|
set prms_id 0
|
set prms_id 0
|
set bug_id 0
|
set bug_id 0
|
|
|
# Start with a fresh gdb.
|
# Start with a fresh gdb.
|
|
|
gdb_exit
|
gdb_exit
|
gdb_start
|
gdb_start
|
gdb_reinitialize_dir $srcdir/$subdir
|
gdb_reinitialize_dir $srcdir/$subdir
|
gdb_load $objdir/$subdir/$binfile
|
gdb_load $objdir/$subdir/$binfile
|
|
|
send_gdb "set width 0\n"
|
send_gdb "set width 0\n"
|
gdb_expect -re "$gdb_prompt $"
|
gdb_expect -re "$gdb_prompt $"
|
|
|
test_cond_wait
|
test_cond_wait
|
}
|
}
|
|
|
# Check to see if we have an executable to test. If not, then either we
|
# Check to see if we have an executable to test. If not, then either we
|
# haven't tried to compile one, or the compilation failed for some reason.
|
# haven't tried to compile one, or the compilation failed for some reason.
|
# In either case, just notify the user and skip the tests in this file.
|
# In either case, just notify the user and skip the tests in this file.
|
|
|
set binfile "step"
|
set binfile "step"
|
set srcfile "step.c"
|
set srcfile "step.c"
|
|
|
if ![file exists $objdir/$subdir/$binfile] then {
|
if ![file exists $objdir/$subdir/$binfile] then {
|
if $all_flag then {
|
if $all_flag then {
|
warning "$binfile does not exist; tests suppressed."
|
warning "$binfile does not exist; tests suppressed."
|
}
|
}
|
} else {
|
} else {
|
do_tests
|
do_tests
|
}
|
}
|
|
|