From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66453 invoked by alias); 18 Jun 2015 12:45:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 66442 invoked by uid 89); 18 Jun 2015 12:45:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-oi0-f49.google.com Received: from mail-oi0-f49.google.com (HELO mail-oi0-f49.google.com) (209.85.218.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 18 Jun 2015 12:45:11 +0000 Received: by oiax193 with SMTP id x193so56366571oia.2 for ; Thu, 18 Jun 2015 05:45:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=XaESVX2u+lDTPZSREZR9UUsRCoLGI5qSYOY65HuXd9Y=; b=LNbm0m6QClg+xunEnLmmw4PVjI5pxZtDOxYWOqeCFy7gkJ5eGK/SeivJqtmHbSQg+9 scnNmejQvGSv1yP35d8GnCktz+bRD6xJw1LXC9JMfkgJwKlpBhhjg2xyEx9/2M7Nxn/D CikJI/ogTY1HpmgtkuT+dgkIet7R4n/VtaQqmQGZqim4WAJZh51pWyGTVXV924lHqwNW g5Ehvykgo6knvmKw8Y4ZkEfPqCyDkdxM4xc5duxUYV2jk+Oaa5MZ8Hh3TABMtVbKY/QV WDNnm7Za6Qd6P4bY5IRy824/T2kPcjyyEgrauIp3riMdX+ldZFblMdjpL/VampzExf0p QBpw== X-Gm-Message-State: ALoCoQmIDL/OV5QpulwjgBEl7sM4v47Rd0NDSQD+A7ApjxwM2YyT4nBtFpKERY6II3WdXMWGsUQe X-Received: by 10.202.54.3 with SMTP id d3mr8058500oia.103.1434631509746; Thu, 18 Jun 2015 05:45:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.96.167 with HTTP; Thu, 18 Jun 2015 05:44:49 -0700 (PDT) In-Reply-To: <55828A13.8030703@redhat.com> References: <1434572241-16019-1-git-send-email-patrick@parcs.ath.cx> <55828A13.8030703@redhat.com> From: Patrick Palka Date: Thu, 18 Jun 2015 12:45:00 -0000 Message-ID: Subject: Re: [PATCH] Test the interaction between GDBHISTSIZE and .gdbinit To: Pedro Alves Cc: "gdb-patches@sourceware.org" Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2015-06/txt/msg00386.txt.bz2 On Thu, Jun 18, 2015 at 5:06 AM, Pedro Alves wrote: > On 06/17/2015 09:17 PM, Patrick Palka wrote: >> The value inside the GDBHISTSIZE environment variable, only if valid, >> should override setting the history size through one's .gdbinit file. > > Thanks, looks good. > >> + unset -nocomplain env(GDBHISTSIZE) >> array set env [array get old_env] > > Though this unset looks unnecessary, given that the following line > restores the whole array. It turns out that array set env [array get old_env] does not completely restore the env array to its original state. What it seems to do is to reset each pre-existing environment variable (existing in the saved env array) to its original value. New environment variables that were set inside the env array in the meantime do not get unset after restoring. So e.g. after doing array set old_env [array get env] set env(SOME_NEW_VAR) foo array set env [array get old_env] the environment variable SOME_NEW_VAR=foo will still be in the env array. So this "array set env" trick is insufficient. That is why the unset of GDBHISTSIZE is necessary there. To make the pattern of "temporarily altering global variables, restoring their original value afterwards" more convenient and less error-prone, I've been thinking about introducing a new tcl proc that acts as a wrapper for saving/restoring a specified list of variables. Its use would look something like: save_vars { INTERNAL_GDBFLAGS env(GDBHISTSIZE) env(HOME) } { append INTERNAL_GDBFLAGS " -nx" unset -nocomplain env(GDBHISTSIZE) unset -nocomplain env(HOME) gdb_test .... more_gdb_test ... } which guarantees that after the body has finished executing, the given list of variables will have their contents restored to their original values. What do you think about this?