This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Test the interaction between GDBHISTSIZE and .gdbinit
- From: Patrick Palka <patrick at parcs dot ath dot cx>
- To: Doug Evans <dje at google dot com>
- Cc: Pedro Alves <palves at redhat dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Mon, 22 Jun 2015 09:46:13 -0400
- Subject: Re: [PATCH] Test the interaction between GDBHISTSIZE and .gdbinit
- Authentication-results: sourceware.org; auth=none
- References: <1434572241-16019-1-git-send-email-patrick at parcs dot ath dot cx> <55828A13 dot 8030703 at redhat dot com> <CA+C-WL94mhYR4xtquXuR8U6D8Sia7jWhLE-vq=PCKJAE56xEug at mail dot gmail dot com> <CADPb22TQcHeyXqcv5ENZ9sEM5DokqyCjyt3dONQAjLn_YspmPg at mail dot gmail dot com>
On Mon, Jun 22, 2015 at 9:21 AM, Doug Evans <dje@google.com> wrote:
> On Thu, Jun 18, 2015 at 7:44 AM, Patrick Palka <patrick@parcs.ath.cx> wrote:
>> 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.
>
> http://tcl.tk/man/tcl8.5/TclCmd/array.htm
>
>> 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.
>
> I haven't read the save_vars patch yet, but how about:
>
> array set old_env [array get env]
> ...
> array unset env ;# <<<<<<<<<<<<<<<
> array set env [array get old_env]
> array unset old_env
>
> It might be a teensy bit simpler to do:
>
> set old_env [array get env]
> ...
> array set env $old_env
> unset old_env
>
> Dunno.
The env array is "magical" so I'm not sure if these techniques may work on it.