public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Patrick Palka <patrick@parcs.ath.cx>
To: Pedro Alves <palves@redhat.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Test the interaction between GDBHISTSIZE and .gdbinit
Date: Thu, 18 Jun 2015 12:45:00 -0000	[thread overview]
Message-ID: <CA+C-WL94mhYR4xtquXuR8U6D8Sia7jWhLE-vq=PCKJAE56xEug@mail.gmail.com> (raw)
In-Reply-To: <55828A13.8030703@redhat.com>

On Thu, Jun 18, 2015 at 5:06 AM, Pedro Alves <palves@redhat.com> 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?

  reply	other threads:[~2015-06-18 12:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17 20:17 Patrick Palka
2015-06-18  9:06 ` Pedro Alves
2015-06-18 12:45   ` Patrick Palka [this message]
2015-06-18 14:47     ` Patrick Palka
2015-06-18 15:29       ` Pedro Alves
2015-08-11 22:11         ` Pedro Alves
2015-08-12 12:44           ` Patrick Palka
2015-06-23 16:48       ` Doug Evans
2015-06-22 13:21     ` Doug Evans
2015-06-22 13:46       ` Patrick Palka
2015-06-22 13:59         ` Doug Evans

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='CA+C-WL94mhYR4xtquXuR8U6D8Sia7jWhLE-vq=PCKJAE56xEug@mail.gmail.com' \
    --to=patrick@parcs.ath.cx \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).