mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-22 19:09:31 +08:00
testsuite: refactor spawn and wait for attach
Several places in the testsuite have a copy of a snippet of code that spawns a test program, waits a bit, and then does some PID munging for Cygwin. This is in order to have GDB attach to the spawned program. This refactors all that to a common procedure. (multi-attach.exp wants to spawn multiple processes, so this makes the new procedure's interface work with lists.) Tested on x86_64 Fedora 20. gdb/testsuite/ChangeLog: 2014-09-11 Pedro Alves <palves@redhat.com> * lib/gdb.exp (spawn_wait_for_attach): New procedure. * gdb.base/attach.exp (do_attach_tests, do_call_attach_tests) (do_command_attach_tests): Use spawn_wait_for_attach. * gdb.base/solib-overlap.exp: Likewise. * gdb.multi/multi-attach.exp: Likewise. * gdb.python/py-prompt.exp: Likewise. * gdb.python/py-sync-interp.exp: Likewise. * gdb.server/ext-attach.exp: Likewise.
This commit is contained in:
@ -1,3 +1,14 @@
|
|||||||
|
2014-09-11 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
|
* lib/gdb.exp (spawn_wait_for_attach): New procedure.
|
||||||
|
* gdb.base/attach.exp (do_attach_tests, do_call_attach_tests)
|
||||||
|
(do_command_attach_tests): Use spawn_wait_for_attach.
|
||||||
|
* gdb.base/solib-overlap.exp: Likewise.
|
||||||
|
* gdb.multi/multi-attach.exp: Likewise.
|
||||||
|
* gdb.python/py-prompt.exp: Likewise.
|
||||||
|
* gdb.python/py-sync-interp.exp: Likewise.
|
||||||
|
* gdb.server/ext-attach.exp: Likewise.
|
||||||
|
|
||||||
2014-09-11 Gabriel Krisman Bertazi <gabriel@krisman.be>
|
2014-09-11 Gabriel Krisman Bertazi <gabriel@krisman.be>
|
||||||
|
|
||||||
* gdb.fortran/array-element.exp: Remove unexpected "continue"
|
* gdb.fortran/array-element.exp: Remove unexpected "continue"
|
||||||
|
@ -70,13 +70,7 @@ proc do_attach_tests {} {
|
|||||||
# Start the program running and then wait for a bit, to be sure
|
# Start the program running and then wait for a bit, to be sure
|
||||||
# that it can be attached to.
|
# that it can be attached to.
|
||||||
|
|
||||||
set testpid [eval exec $binfile &]
|
set testpid [spawn_wait_for_attach $binfile]
|
||||||
exec sleep 2
|
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
|
||||||
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify that we cannot attach to nonsense.
|
# Verify that we cannot attach to nonsense.
|
||||||
|
|
||||||
@ -279,16 +273,7 @@ proc do_attach_tests {} {
|
|||||||
|
|
||||||
remote_exec build "kill -9 ${testpid}"
|
remote_exec build "kill -9 ${testpid}"
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
set testpid [spawn_wait_for_attach $binfile]
|
||||||
# that it can be attached to.
|
|
||||||
|
|
||||||
set testpid [eval exec $binfile &]
|
|
||||||
exec sleep 2
|
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
|
||||||
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify that we can attach to the process, and find its a.out
|
# Verify that we can attach to the process, and find its a.out
|
||||||
# when we're cd'd to some directory that doesn't contain the
|
# when we're cd'd to some directory that doesn't contain the
|
||||||
@ -335,16 +320,7 @@ proc do_call_attach_tests {} {
|
|||||||
global gdb_prompt
|
global gdb_prompt
|
||||||
global binfile2
|
global binfile2
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
set testpid [spawn_wait_for_attach $binfile2]
|
||||||
# that it can be attached to.
|
|
||||||
|
|
||||||
set testpid [eval exec $binfile2 &]
|
|
||||||
exec sleep 2
|
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
|
||||||
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Attach
|
# Attach
|
||||||
|
|
||||||
@ -397,16 +373,7 @@ proc do_command_attach_tests {} {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
set testpid [spawn_wait_for_attach $binfile]
|
||||||
# that it can be attached to.
|
|
||||||
|
|
||||||
set testpid [eval exec $binfile &]
|
|
||||||
exec sleep 2
|
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
|
||||||
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
gdb_exit
|
gdb_exit
|
||||||
if $verbose>1 then {
|
if $verbose>1 then {
|
||||||
|
@ -82,16 +82,7 @@ foreach prelink_lib1 {0x40000000 0x50000000} { with_test_prefix "$prelink_lib1"
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
set testpid [spawn_wait_for_attach $binfile]
|
||||||
# that it can be attached to.
|
|
||||||
|
|
||||||
set testpid [eval exec $binfile &]
|
|
||||||
sleep 2
|
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
|
||||||
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
remote_exec build "mv -f ${binfile_lib1} ${binfile_lib1}-running"
|
remote_exec build "mv -f ${binfile_lib1} ${binfile_lib1}-running"
|
||||||
remote_exec build "mv -f ${binfile_lib2} ${binfile_lib2}-running"
|
remote_exec build "mv -f ${binfile_lib2} ${binfile_lib2}-running"
|
||||||
|
@ -30,15 +30,10 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug additiona
|
|||||||
|
|
||||||
# Start the programs running and then wait for a bit, to be sure that
|
# Start the programs running and then wait for a bit, to be sure that
|
||||||
# they can be attached to.
|
# they can be attached to.
|
||||||
set testpid1 [eval exec $binfile &]
|
|
||||||
set testpid2 [eval exec $binfile &]
|
set pid_list [spawn_wait_for_attach [list $binfile $binfile]]
|
||||||
exec sleep 2
|
set testpid1 [lindex $pid_list 0]
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
set testpid2 [lindex $pid_list 1]
|
||||||
# testpid{1,2} are the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid1 [ exec ps -e | gawk "{ if (\$1 == $testpid1) print \$4; }" ]
|
|
||||||
set testpid2 [ exec ps -e | gawk "{ if (\$1 == $testpid2) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
gdb_test "attach $testpid1" \
|
gdb_test "attach $testpid1" \
|
||||||
"Attaching to program: .*, process $testpid1.*(in|at).*" \
|
"Attaching to program: .*, process $testpid1.*(in|at).*" \
|
||||||
|
@ -80,15 +80,7 @@ gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
|
|||||||
"prompt_hook argument is default prompt. 2"
|
"prompt_hook argument is default prompt. 2"
|
||||||
gdb_exit
|
gdb_exit
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
set testpid [spawn_wait_for_attach $binfile]
|
||||||
# that it can be attached to.
|
|
||||||
set testpid [eval exec $binfile &]
|
|
||||||
exec sleep 2
|
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
|
||||||
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
|
set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
|
||||||
set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
|
set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
|
||||||
|
@ -41,15 +41,7 @@ if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
set testpid [spawn_wait_for_attach $binfile]
|
||||||
# that it can be attached to.
|
|
||||||
set testpid [eval exec $binfile &]
|
|
||||||
exec sleep 2
|
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
|
||||||
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Test command 'where' is executed when command 'attach' is done, otherwise
|
# Test command 'where' is executed when command 'attach' is done, otherwise
|
||||||
# function 'sleep' may not show up in backtrace.
|
# function 'sleep' may not show up in backtrace.
|
||||||
|
@ -44,15 +44,7 @@ gdbserver_start_extended
|
|||||||
|
|
||||||
gdb_test_no_output "set remote exec-file $target_exec" "set remote exec-file"
|
gdb_test_no_output "set remote exec-file $target_exec" "set remote exec-file"
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
set testpid [spawn_wait_for_attach $binfile]
|
||||||
# that it can be attached to.
|
|
||||||
set testpid [eval exec $binfile &]
|
|
||||||
exec sleep 2
|
|
||||||
if { [istarget "*-*-cygwin*"] } {
|
|
||||||
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
||||||
# different due to the way fork/exec works.
|
|
||||||
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
gdb_test "attach $testpid" \
|
gdb_test "attach $testpid" \
|
||||||
"Attaching to program: .*, process $testpid.*(in|at).*" \
|
"Attaching to program: .*, process $testpid.*(in|at).*" \
|
||||||
|
@ -3324,6 +3324,31 @@ proc gdb_exit { } {
|
|||||||
catch default_gdb_exit
|
catch default_gdb_exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Start a set of programs running and then wait for a bit, to be sure
|
||||||
|
# that they can be attached to. Return a list of the processes' PIDs.
|
||||||
|
|
||||||
|
proc spawn_wait_for_attach { executable_list } {
|
||||||
|
set pid_list {}
|
||||||
|
|
||||||
|
foreach {executable} $executable_list {
|
||||||
|
lappend pid_list [eval exec $executable &]
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
if { [istarget "*-*-cygwin*"] } {
|
||||||
|
for {set i 0} {$i < [llength $pid_list]} {incr i} {
|
||||||
|
# testpid is the Cygwin PID, GDB uses the Windows PID,
|
||||||
|
# which might be different due to the way fork/exec works.
|
||||||
|
set testpid [lindex $pid_list $i]
|
||||||
|
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
||||||
|
set pid_list [lreplace $pid_list $i $i $testpid]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pid_list
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# gdb_load_cmd -- load a file into the debugger.
|
# gdb_load_cmd -- load a file into the debugger.
|
||||||
# ARGS - additional args to load command.
|
# ARGS - additional args to load command.
|
||||||
|
Reference in New Issue
Block a user