gdb: Have setter and getter callbacks for settings
authorLancelot SIX <lsix@lancelotsix.com>
Tue, 14 Sep 2021 22:36:53 +0000 (23:36 +0100)
committerLancelot SIX <lsix@lancelotsix.com>
Sun, 3 Oct 2021 16:53:16 +0000 (17:53 +0100)
commit702991711a91bd47b209289562843a11e7009396
treeb7b71ddfc72ce5ebddc1118cba7f97f3fb2700d8
parente0700ba44c5695d07f4cc9841315adc91ca18bf5
gdb: Have setter and getter callbacks for settings

The main motivation behind this improvement is to help the
implementation of a patch Simon Marchi is preparing to fix a bug when
MI or Python try to access parameters that are inferior dependent (see
PR/28085).

This commit extends the previous ones, which introduces the setting
object to represent a static variable whose value can be set or shown
with the appropriate commands.  This patch proposes that a setting can
either contain a pointer to a static variable holding a setting, or
pointers to a pair of setter and getter callback functions.

The callbacks functions can be used to retrieve or change the value with
custom logic.  This is useful when the source of truth for a given
setting is not contained in the variable pointed to by the setting
instance.

Given that the callback function call is hidden within the setting
abstraction introduced earlier, none of the sites accessing the setting
needs to be updated.  The registered getter or setter is used whatever
the way to access it is (through MI, Python, Guile, the "with" command
and the $_gdb_setting / $_gdb_setting_str convenience functions).

All the add_setshow_*_cmd are given a new overload that will accept the
pair of function pointers (set / get functions) instead of the pointer
to a global variable.

Tested on GNU/Linux x86_64 with no regression observed.

Change-Id: Ieb81fef57550632ff66e6aa85f637372a226be8c
Co-authored-by: Simon Marchi <simon.marchi@polymtl.ca>
gdb/cli/cli-decode.c
gdb/command.h