binutils-gdb/gdb/cli
Philippe Waroquiers 9ad9b77d64 Implement convenience functions to examine GDB settings.
The new convenience functions $_gdb_setting and $_gdb_setting_str
provide access to the GDB settings in user-defined commands.
Similarly, $_gdb_maint_setting and $_gdb_maint_setting_str
provide access to the GDB maintenance settings.

The patch was developed following a comment of Eli about the
'set may-call-functions'.  Eli said that user-defined functions
should have a way to change their behavior according to this setting.
Rather than have a specialized $_may_call_functions, this patch
implements a general way to access any GDB setting.

Compared to doing such access via Python 'gdb.parameter' and/or
'gdb.execute("set somesetting tosomevalue"):
* The 'with' command is much better than the above python usage:
  if the user types C-c or an error happens between the set pagination off
  and the python "set pagination on", the above python
  does not restore the original setting.

* Effectively, with the "gdb.parameter" python one liner, it is possible to do
  simple 'if' conditions, such as set and restore pagination.
  But mixing the "python if" within canned
  sequence of commands is cumbersome for non trivial combinations.
  E.g. if several commands have to be done for a certain condition
  accessed from python, I guess something like will be needed:
     python if __some_setting: gdb.execute("some command")
     python if __some_setting: gdb.execute("some other command")
     python if __some_setting: gdb.execute("some different command")
  (without speaking about nested "if-s").

  With the convenience function:
     if $_gdb_setting("some_setting")
        some command
        some other command
        some different command
     end
  Integer settings (for example print elements) will also be more difficult
  to use.
  For example, a user defined function that scans and prints a linked list
  might want to use the value of "set print elements" to stop printing
  the linked list.
  Doing that by mixing python expression/if is likely doable, but seems
  not easy with the above one liners.

So, in summary, the $_gdb_setting and $_gdb_setting_str avoids to have the
heterogeneous mix of python and GDB commands in one single script
(and of course, it works even if python is not configured, but that
must be an unusual setup I guess).

gdb/ChangeLog
2019-10-31  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-cmds.c (setting_cmd, value_from_setting)
	(gdb_setting_internal_fn, gdb_maint_setting_internal_fn)
	(str_value_from_setting, gdb_setting_str_internal_fn)
	(gdb_maint_setting_str_internal_fn): New functions.
	(_initialize_cli_cmds): Define the new convenience functions.
	* gdb/cli/cli-setshow.h (get_setshow_command_value_string): Constify.
	* gdb/cli/cli-setshow.c (get_setshow_command_value_string): Constify.
2019-10-31 23:31:43 +01:00
..
cli-cmds.c Implement convenience functions to examine GDB settings. 2019-10-31 23:31:43 +01:00
cli-cmds.h Move declaration of max_user_call_depth to header 2019-10-12 14:31:26 -05:00
cli-decode.c [gdb] Fix more typos in comments (2) 2019-10-26 09:55:32 +02:00
cli-decode.h
cli-dump.c
cli-interp.c
cli-interp.h
cli-logging.c Use styled_string for "show logging filename" 2019-10-01 15:12:41 -06:00
cli-option.c
cli-option.h
cli-script.c [gdb] Fix more typos in comments (2) 2019-10-26 09:55:32 +02:00
cli-script.h
cli-setshow.c Implement convenience functions to examine GDB settings. 2019-10-31 23:31:43 +01:00
cli-setshow.h Implement convenience functions to examine GDB settings. 2019-10-31 23:31:43 +01:00
cli-style.c [gdb] Fix set/show style metadata help text 2019-10-03 10:15:39 +02:00
cli-style.h
cli-utils.c
cli-utils.h [gdb] Fix more typos in comments (2) 2019-10-26 09:55:32 +02:00