From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by sourceware.org (Postfix) with ESMTPS id 4372C3851C27 for ; Wed, 3 Jun 2020 12:54:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4372C3851C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wm1-x342.google.com with SMTP id c71so1812127wmd.5 for ; Wed, 03 Jun 2020 05:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5gz/c/hircyfsuKaiu5Epe4Ra8v1148gOwJhf1MG8Us=; b=eDNYwf6XsXJV2aO0ZCijPq6MCeWTw55qaFP7ey/G+v8n+iHxPQHQvskyht05q4OzIV L+7TRdbysWTxeOzN0SIyzcZHz+UgULy9xfRu2GZfPFeAKMw592tgJOSDdll1hsXcJxAE LvIoE6anPPCdX69isVQRNOzaBxFejqph1tuO49q7MxqoapfB6xJe5tkYRhQME2574OKy Z7QaZ8t/0fkxY1QDIXwle331s1cmqqWoFN3PLcH5haM5FB8MAJQ5LYwQXr6OdPWKfChJ TfpmJdXcUOm3pGLjYq/I1J7hA+RvbVYGwYqINW8wXGtCqdU9wovUx3qxtpY1bQVpomNn 9gvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5gz/c/hircyfsuKaiu5Epe4Ra8v1148gOwJhf1MG8Us=; b=bDHnUqmDXyvDxkSaAY+ODFqDecbzcQpx1FxTvNkQQfNdqBl13eWHSkdjhMnjKeUF3f H3LWI766vDb/92xnyckTWOS8PrrE6+QZAQe59gaN7DCLMsm0+yWarsWl18vjAzRXjL7w MD6nTclviFIjb1dXyw/5nJ0rxJCnXPyNS7E6ZKQmMfXFqDEm3hbnG8iMy7LVu2wOb8Km UZ8j4tCkS0agta/e0UUbKBo5k8ke8wkx+VWmPuG6ZWd77kSSwdQWtAyphab5i3FifJP8 teFL/4ssNYMyGldmM9vqUnmP8CKbNuVrC/38pWA8xLcKJjwI8tnHspTdKnAt5Rz5xoW5 1BJg== X-Gm-Message-State: AOAM53379xVQylv8oW931auunWXqtyLsPTCR4bsGjjmedcT6Zjbmos60 vgEnJGNppvCBf4YZp+d5WG9qjlpdy5U= X-Google-Smtp-Source: ABdhPJzyhvFBoS5Ow2c8moqmx7AVx6hcqGJnCB5IT84s1aR1Jh0Yd/uoGD30ztVKL96icxDdol4h5g== X-Received: by 2002:a1c:5541:: with SMTP id j62mr8088252wmb.64.1591188854346; Wed, 03 Jun 2020 05:54:14 -0700 (PDT) Received: from localhost (host86-128-12-16.range86-128.btcentralplus.com. [86.128.12.16]) by smtp.gmail.com with ESMTPSA id 128sm3069840wme.39.2020.06.03.05.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 05:54:13 -0700 (PDT) Date: Wed, 3 Jun 2020 13:54:12 +0100 From: Andrew Burgess To: Tom de Vries Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 3/3][gdb/testsuite] Warn about leaked global array Message-ID: <20200603125412.GD3522@embecosm.com> References: <20200519163004.GA9045@delia> <20200602153830.GZ3522@embecosm.com> <20200602155211.GA3522@embecosm.com> <6382e582-c2f3-a999-f604-979958d6a064@suse.de> <20200602170139.GB3522@embecosm.com> <20200602201829.GC3522@embecosm.com> <191ae1d7-3363-08a9-b9fe-f006f9186708@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <191ae1d7-3363-08a9-b9fe-f006f9186708@suse.de> X-Operating-System: Linux/5.5.17-200.fc31.x86_64 (x86_64) X-Uptime: 13:51:39 up 44 days, 3:26, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Jun 2020 12:54:20 -0000 * Tom de Vries [2020-06-03 12:24:09 +0200]: > 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. I couldn't work out why my testing was going fine if this problem exists... then I realised that my testing script was causing the tests to run in parallel! I like the load_lib override solution. I think a solution that avoids having to place each test into a new namespace would be a good thing if we can pull it off. Thanks, Andrew > > > > 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 > } > } >