From: Tom de Vries <tdevries@suse.de>
To: Andrew Burgess <andrew.burgess@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 3/3][gdb/testsuite] Warn about leaked global array
Date: Wed, 3 Jun 2020 12:24:09 +0200 [thread overview]
Message-ID: <191ae1d7-3363-08a9-b9fe-f006f9186708@suse.de> (raw)
In-Reply-To: <d992a858-b7c8-a032-fba2-a1fcd5fc1b78@suse.de>
On 03-06-2020 12:09, Tom de Vries wrote:
> On 03-06-2020 11:38, Tom de Vries wrote:
>> On 03-06-2020 10:47, Tom de Vries wrote:
>>> ERROR: can't read "mi_gdb_prompt": no such variable
>>> while executing
>>> "expect {
>>> -i exp95 -timeout 10
>>> -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" {
>>> # We have a new format mi startup prompt. If we are
>>> # running mi1,..."
>>> ("uplevel" body line 1)
>>> invoked from within
>>> "uplevel $body" TCL READ VARNAME can't read "mi_gdb_prompt": no such
>>> variable
>>
>> So, the following happens:
>> - a test-case imports mi-support.exp using load_lib
>> - mi-support.exp sets mi_gdb_prompt
>> - the test-case finishes and the new global mi_gdb_prompt is unset,
>> because it was not set before the test-case
>> - a next test-case imports mi-support.exp using load_lib
>> - load_lib sees that the file already has been loaded, so it skips it
>> - mi_gdb_prompt remains unset
>> - the test-case uses mi_gdb_prompt, and we have an error.
>
> This naive solution seems to work.
>
> Perhaps we can override load_lib to do the same, automatically.
>
That seems to work, I'll test this through.
Thanks,
- Tom
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 66de9d6be3..bca47b96f2 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -25,6 +25,39 @@ if {$tool == ""} {
exit 2
}
+rename load_lib saved_load_lib
+
+array set gdb_persistent_globals {}
+
+proc gdb_persistent_global { varname } {
+ global gdb_persistent_globals
+ set gdb_persistent_globals($varname) 1
+}
+
+proc load_lib { file } {
+ array set known_global {}
+ foreach varname [info globals] {
+ set known_globals($varname) 1
+ }
+
+ set code [catch "saved_load_lib $file" result]
+
+ foreach varname [info globals] {
+ if { ![info exists known_globals($varname)] } {
+ gdb_persistent_global $varname
+ }
+ }
+
+ if {$code == 1} {
+ global errorInfo errorCode
+ return -code error -errorinfo $errorInfo -errorcode $errorCode
$result
+ } elseif {$code > 1} {
+ return -code $code $result
+ }
+
+ return $result
+}
+
load_lib libgloss.exp
load_lib cache.exp
load_lib gdb-utils.exp
@@ -5114,10 +5147,14 @@ proc gdb_setup_known_globals {} {
# GDB_KNOWN_GLOBALS array is unset, this ensures we don't "leak"
# globals from one test script to another.
proc gdb_cleanup_globals {} {
- global gdb_known_globals
+ global gdb_known_globals gdb_persistent_globals
foreach varname [info globals] {
if {![info exists gdb_known_globals($varname)]} {
+ if { [info exists gdb_persistent_globals($varname)] } {
+ continue
+ }
+ verbose -log "gdb_cleanup_globals: deleting $varname"
uplevel #0 unset $varname
}
}
next prev parent reply other threads:[~2020-06-03 10:24 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 16:30 Tom de Vries
2020-05-22 20:15 ` Tom Tromey
2020-06-02 13:08 ` Tom de Vries
2020-06-02 15:38 ` Andrew Burgess
2020-06-02 15:52 ` Andrew Burgess
2020-06-02 16:31 ` Tom de Vries
2020-06-02 17:01 ` Andrew Burgess
2020-06-02 20:18 ` Andrew Burgess
2020-06-03 8:47 ` Tom de Vries
2020-06-03 9:38 ` Tom de Vries
2020-06-03 10:09 ` Tom de Vries
2020-06-03 10:24 ` Tom de Vries [this message]
2020-06-03 12:54 ` Andrew Burgess
2020-06-03 15:35 ` Tom de Vries
2020-06-04 11:16 ` Pedro Alves
2020-06-04 12:29 ` Tom de Vries
2020-06-12 13:11 ` [committed] gdb/testsuite: Prevent globals leaking between test scripts Tom de Vries
2020-06-03 9:49 ` [PATCH 3/3][gdb/testsuite] Warn about leaked global array Pedro Alves
2020-06-04 11:40 ` Tom de Vries
2020-06-05 10:06 ` [PATCH][gdb/testsuite] Don't leak tuiterm.exp spawn override Tom de Vries
2020-06-11 13:55 ` Tom Tromey
2020-06-12 11:36 ` [committed][gdb/testsuite] " Tom de Vries
2020-06-15 19:46 ` Tom Tromey
2020-06-17 14:55 ` Tom de Vries
2020-06-17 15:28 ` Andreas Schwab
2020-06-11 12:11 ` [committed][gdb/testsuite] Make gdb.base/dbx.exp more robust Tom de Vries
2020-06-11 12:16 ` Pedro Alves
2020-06-11 14:39 ` Simon Marchi
2020-06-11 14:52 ` Tom de Vries
2020-06-11 14:59 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=191ae1d7-3363-08a9-b9fe-f006f9186708@suse.de \
--to=tdevries@suse.de \
--cc=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox