Re: [PATCH 5/7] gdb: add mechanism to auto-save startup options

Eli Zaretskii via Gdb-patches
2020-10-08T06:36:19Z

> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Wed, 7 Oct 2020 21:05:09 +0100
> Cc: Tom Tromey <tom@tromey.com>
>
> As we add settings to GDB (in the following patches) that effect GDB's
> startup behaviour a user might desire a mechanism to automatically
> save these options into a file.
>
> The reason that this could be important is that, unlike other,
> non-startup options, the startup options will only effect GDB's
> startup process. As a result setting the option within a GDB session
> will not change how the user experiences that session, but could only
> effect the following sessions.
>
> We could take the position that it is entirely the users
> responsibility to add these options to a startup file and maintain
> them, however, this commit provides a mechanism to automate that
> management.
>
> If a user adds the following lines to ~/.config/gdb/gdbstartup:
>
> set startup-save-filename ~/.config/gdb/auto-save
> source ~/.config/gdb/auto-save
>
> Then GDB will write all startup options to the file auto-save file any
> time one of the options is modified. The source ensures that the
> options are reloaded correctly.

Sorry, I don't think I understand the use case you describe. Since
the startup options only affect the behavior during the startup
process, and will not change anything if set during the session
itself, why would the user want to change one of those settings
during the session? AFAIU, such a change will not affect GDB's
behavior in any way.

> +extern void _initialize_cli_setshow ();
> +void
> +_initialize_cli_setshow ()
> +{
> + add_setshow_filename_cmd ("startup-save-filename", class_support,
> + &startup_save_filename, _("\
> +Set the filename to which startup options should be written."), _("\
> +Show the filename to which startup options are written."), _("\
> +Some options only effect the startup of GDB. When these options are\n\
> +modified GDB can arrange to write the values of all of these options\n\
> +to a file which can then be sourced during startup to reapply these\n\
> +options."),

This doesn't mention that merely setting the variable has the effect
of turning on the auto-saving (as far as I understand).

> +@node Automatically saving startup settings
> +@section Automatically saving startup settings
> +@table @code
> +@kindex show startup-save-filename
> +@kindex set startup-save-filename filename
> +@cindex @value{GDBN} startup settings
> +@item show startup-save-filename
> +@itemx set startup-save-filename @var{filename}
> +Some settings only effect the early startup behaviour of @value{GDBN}.
^^^^^^
"affect"

Also, I don't think "early startup behavior" is a term we explain
anywhere, so it presents a small puzzle to the reader. Can we explain
it somewhere?

> +In order to make use of these settings they will need to be added to a
> +startup file, for example @file{~/.config/gdb/gdbstartup}
> +(@pxref{Startup}).
> +
> +When @samp{startup-save-filename} is set to a valid path @value{GDBN}
> +will automatically save all startup settings to this file whenever they
> +are modified in a @value{GDBN} session. The save file can then be
> +loaded using @samp{source} (@pxref{Command Files}).
> +
> +For example, these commands could be placed into
> +@file{~/.config/gdb/gdbstartup} in order to have GDB automatically
> +save and restore startup settings:
> +
> +@smallexample
> +set startup-save-filename ~/.config/gdb/autosave
> +source ~/.config/gdb/autosave
> +@end smallexample
> +@end table

I think this should explain the use case when this is useful, see
above. Upon reading this description, I don't think I understand the
use case.

Thanks.