]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/testsuite: Prevent globals leaking between test scripts
authorAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 12 Jun 2020 13:09:33 +0000 (15:09 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 12 Jun 2020 13:09:33 +0000 (15:09 +0200)
commita29d5112814e7a6744f03bddfe6756e2aa5e7a50
tree9475dd9d41c62c3fa2c7c021b8c548fdcc240978
parent8c74a764f2cf5ea5e6997e35ba0f755fe2c09889
gdb/testsuite: Prevent globals leaking between test scripts

Many of the test scripts create variables in the global namespace,
these variables will then be present for the following test scripts.
In most cases this is harmless, but in some cases this can cause
problems.

For example, if a variable is created as an array in one script, but
then assigned as a scalar in a different script, this will cause a TCL
error.

The solution proposed in this patch is to have the GDB test harness
record a list of all known global variables at the point just before
we source the test script.  Then, after the test script has run, we
again iterate over all global variables.  Any variable that was not in
the original list is deleted, unless it was marked as a persistent global
variable using gdb_persistent_global.

The assumption here is that no test script should need to create a
global variable that will outlive the lifetime of the test script
itself.  With this patch in place all tests currently seem to pass, so
the assumption seems to hold.

gdb/testsuite/ChangeLog:

2020-06-12  Andrew Burgess  <andrew.burgess@embecosm.com>
    Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_known_globals, gdb_persistent_globals): New global.
(gdb_persistent_global, gdb_persistent_global_no_decl): New proc.
(gdb_setup_known_globals): New proc.
(gdb_cleanup_globals): New proc.
* lib/gdb.exp (load_lib): New override proc.
(gdb_stdin_log_init): Set var in_file as persistent global.
* lib/pascal.exp (gdb_stdin_log_init): Set vars
pascal_compiler_is_gpc, pascal_compiler_is_fpc, gpc_compiler and
fpc_compiler as persistent global.
gdb/testsuite/ChangeLog
gdb/testsuite/lib/gdb.exp
gdb/testsuite/lib/pascal.exp