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: Pedro Alves <palves at redhat dot com>
- Cc: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Thu, 18 Jun 2015 08:44:49 -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>
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?