Fix global variable collision in gdb.multi/multi-kill.exp

The new gdb.multi/multi-kill.exp testcase added an 'testpid' array,
which may conflict with other global 'testpid' variables used by other
testcases, resulting in:

 ...
 ERROR: tcl error sourcing
 /data/gdb_versions/devel/src/gdb/testsuite/gdb.multi/multi-kill.exp.
 ERROR: can't set "testpid(1)": variable isn't array
     while executing
 "set testpid($num) [get_integer_valueof "pid" -1]"

or

 $ runtest gdb.threads/check-libthread-db.exp gdb.multi/multi-kill.exp
 ...
 Running /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.multi/multi-kill.exp ...
 Running /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.threads/check-libthread-db.exp ...
 ERROR: tcl error sourcing /home/pedro/gdb/binutils-gdb/src/gdb/testsuite/gdb.threads/check-libthread-db.exp.
 ERROR: can't set "testpid": variable is array
     while executing
 "set testpid [spawn_id_get_pid $test_spawn_id]"
     ("uplevel" body line 8)

Fix this with a namespace, like gdb.linespec/explicit.exp does.

gdb/testsuite/ChangeLog:
2020-05-15  Pedro Alves  <palves@redhat.com>

	* gdb.multi/multi-kill.exp: Wrap in namespace.
	(start_inferior): Add TESTPID parameter.  Use it instead of the
	testpid global.
	(top level): Define empty TESTPID array, and pass it down to
	start_inferior.
This commit is contained in:
Pedro Alves 2020-05-15 11:09:51 +01:00
parent 013707794a
commit 272c36b87f
2 changed files with 22 additions and 5 deletions

View File

@ -1,3 +1,11 @@
2020-05-15 Pedro Alves <palves@redhat.com>
* gdb.multi/multi-kill.exp: Wrap in namespace.
(start_inferior): Add TESTPID parameter. Use it instead of the
testpid global.
(top level): Define empty TESTPID array, and pass it down to
start_inferior.
2020-05-14 Tom de Vries <tdevries@suse.de>
* gdb.fortran/nested-funcs-2.exp: Use gdb_test_stdio to test inferior

View File

@ -39,11 +39,15 @@ save_vars { GDBFLAGS } {
clean_restart ${binfile}
}
# Wrap the entire test in a namespace to avoid contaminating other tests.
namespace eval $testfile {
# Start inferior NUM and record its PID in the TESTPID array.
proc start_inferior {num} {
proc start_inferior {num testpid} {
with_test_prefix "start_inferior $num" {
global testpid binfile srcfile
upvar $testpid tpid
global binfile srcfile
if {$num != 1} {
gdb_test "add-inferior" "Added inferior .*" \
@ -58,8 +62,8 @@ proc start_inferior {num} {
gdb_run_cmd
gdb_test "" ".*reakpoint .*, initialized .*${srcfile}.*" "run"
set testpid($num) [get_integer_valueof "pid" -1]
if {$testpid($num) == -1} {
set tpid($num) [get_integer_valueof "pid" -1]
if {$tpid($num) == -1} {
return -1
}
@ -71,8 +75,11 @@ proc start_inferior {num} {
# is killed while we're handling a killed event.
set NUM_INFS 10
# The array holding each inferior's PID, indexed by inferior number.
array set testpid {}
for {set i 1} {$i <= $NUM_INFS} {incr i} {
if {[start_inferior $i] < 0} {
if {[start_inferior $i testpid] < 0} {
return -1
}
}
@ -125,3 +132,5 @@ for {set i 2} {$i <= $NUM_INFS} {incr i} {
"continue to SIGKILL"
}
}
}