Re: [PATCH 3/3][gdb/testsuite] Warn about leaked global array

Pedro Alves
2020-06-04T11:16:16Z

On 6/3/20 4:35 PM, Tom de Vries wrote:
> @@ -47,6 +47,10 @@ proc pascal_init {} {
> set pascal_compiler_is_fpc 0
> set gpc_compiler [transform gpc]
> set fpc_compiler [transform fpc]
> + gdb_persistent_global pascal_compiler_is_gpc
> + gdb_persistent_global pascal_compiler_is_fpc
> + gdb_persistent_global gpc_compiler
> + gdb_persistent_global fpc_compiler

> @@ -47,6 +47,10 @@ proc pascal_init {} {
> set pascal_compiler_is_fpc 0
> set gpc_compiler [transform gpc]
> set fpc_compiler [transform fpc]
> + gdb_persistent_global pascal_compiler_is_gpc
> + gdb_persistent_global pascal_compiler_is_fpc
> + gdb_persistent_global gpc_compiler
> + gdb_persistent_global fpc_compiler

Can we make gdb_persistent_global proc also do the "global $var"
in the caller's scope, so that it could be used to replace
the "global" statement? With that, you would only have to declare
the variable once, and this hunk here would instead be:

diff --git c/gdb/testsuite/lib/pascal.exp w/gdb/testsuite/lib/pascal.exp
index aad69a2de0..ff11864294 100644
--- c/gdb/testsuite/lib/pascal.exp
+++ w/gdb/testsuite/lib/pascal.exp
@@ -33,10 +33,10 @@ set pascal_init_done 0

proc pascal_init {} {
global pascal_init_done
- global pascal_compiler_is_gpc
- global pascal_compiler_is_fpc
- global gpc_compiler
- global fpc_compiler
+ gdb_persistent_global pascal_compiler_is_gpc
+ gdb_persistent_global pascal_compiler_is_fpc
+ gdb_persistent_global gpc_compiler
+ gdb_persistent_global fpc_compiler
global env

Thanks,
Pedro Alves