This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
On Thu, Jun 18, 2015 at 8: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. 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? Here is an implementation of save_vars (bad name I know) which can successfully replace the manual saving/restoring of globals done in gdbinit-history.exp, gdbhistsize-history.exp and readline.exp. (TCL sure is cool.)
Attachment:
tmp (2).diff
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |