public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFAv2 0/3] Convenience functions $_gdb_setting/$_gdb_int_setting
@ 2019-07-05 19:58 Philippe Waroquiers
  2019-07-05 19:58 ` [RFAv2 1/3] Implement convenience functions to examine GDB settings Philippe Waroquiers
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Philippe Waroquiers @ 2019-07-05 19:58 UTC (permalink / raw)
  To: gdb-patches

As part of the discussion of 'show | set may-call-functions [on|off]',
Eli suggested to have a way to access the GDB settings from
user defined commands.

So, this patch series implements this.

2 functions are provided:
  * $_gdb_setting that gives access to all settings, giving back a string value.
  * $_gdb_int_setting, giving access to boolean, auto-boolean and integers.
    This is easier to use for such types than the string version.

This is a v2 that just rebase to a recent master, as the code has
to be updated due to the 'cli option' framework.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFAv2 3/3] NEWS and documentation for $_gdb_setting and $_gdb_int_setting.
  2019-07-05 19:58 [RFAv2 0/3] Convenience functions $_gdb_setting/$_gdb_int_setting Philippe Waroquiers
  2019-07-05 19:58 ` [RFAv2 1/3] Implement convenience functions to examine GDB settings Philippe Waroquiers
  2019-07-05 19:58 ` [RFAv2 2/3] Test the convenience functions $_gdb_setting and $_gdb_int_setting Philippe Waroquiers
@ 2019-07-05 19:58 ` Philippe Waroquiers
  2019-07-06  6:23   ` Eli Zaretskii
  2 siblings, 1 reply; 7+ messages in thread
From: Philippe Waroquiers @ 2019-07-05 19:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

---
 gdb/ChangeLog       |  3 +++
 gdb/NEWS            |  5 +++++
 gdb/doc/ChangeLog   |  5 +++++
 gdb/doc/gdb.texinfo | 48 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 61 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ab414dca9f..bfde05e363 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -9111,6 +9111,9 @@ fill-column: 74
 version-control: never
 coding: utf-8
 End:
+2019-04-28  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+	* NEWS: Mention $_gdb_setting and $_gdb_int_setting.
 
 2019-04-28  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
diff --git a/gdb/NEWS b/gdb/NEWS
index 34c544c3d5..d17d37ceff 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -11,6 +11,11 @@
   scripts that should work error-free with many different versions,
   such as in system-wide init files.
 
+* New built-in convenience functions $_gdb_setting and $_gdb_int_setting
+  provide access to values of the GDB settings.  They are handy
+  for changing the logic of user defined commands depending on the
+  current GDB settings.
+
 * GDB now supports Thread Local Storage (TLS) variables on several
   FreeBSD architectures (amd64, i386, powerpc, riscv).  Other
   architectures require kernel changes.  TLS is not yet supported for
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 1025916003..536444f628 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -12944,3 +12944,8 @@ fill-column: 74
 version-control: never
 coding: utf-8
 End:
+2019-04-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+	* gdb.texinfo (Convenience Funs): Document the new
+	$_gdb_setting and $_gdb_int_setting convenience functions.
+
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 299c4a12a1..e122fbb77b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -11820,6 +11820,54 @@ $3 = void
 $4 = 1
 @end smallexample
 
+@item $_gdb_setting (@var{setting})
+@findex $_gdb_setting@r{, convenience function}
+Return the value of the @value{GDBN} @var{setting} as a string.
+@var{setting} is any setting that can be used in a @code{set} or
+@code{show} command (@pxref{Controlling GDB}).
+
+@smallexample
+(@value{GDBP}) show print frame-arguments
+Printing of non-scalar frame arguments is "scalars".
+(@value{GDBP}) p $_gdb_setting("print frame-arguments")
+$2 = "scalars"
+(@value{GDBP}) p $_gdb_setting("height")
+$3 = "30"
+((@value{GDBP})
+@end smallexample
+
+@item $_gdb_int_setting (@var{setting})
+@findex $_gdb_int_setting@r{, convenience function}
+Return the value of the @value{GDBN} @var{setting} as an integer.
+This only works for boolean, auto boolean and integer settings.
+The boolean values @code{on} and @code{off} are converted to
+the integer values @code{0} and @code{1}.  The value @code{auto} is
+converted to the value  @code{2}.
+Some integer settings accepts an @code{unlimited} value.
+Depending on the setting, the unlimited value is converted to a @code{0}
+or a @code{-1} value.
+
+@smallexample
+@group
+(@value{GDBP}) p $_gdb_setting("height")
+$3 = "30"
+(@value{GDBP}) p $_gdb_int_setting("height")
+$4 = 30
+(@value{GDBP}) set height unlimited
+(@value{GDBP}) p $_gdb_setting("height")
+$5 = "unlimited"
+(@value{GDBP}) p $_gdb_int_setting("height")
+$6 = 0
+@end group
+@group
+(@value{GDBP}) p $_gdb_setting("remote hardware-watchpoint-limit")
+$7 = "unlimited"
+(@value{GDBP}) p $_gdb_int_setting("remote hardware-watchpoint-limit")
+$8 = -1
+(@value{GDBP})
+@end group
+@end smallexample
+
 @end table
 
 These functions require @value{GDBN} to be configured with
-- 
2.20.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFAv2 1/3] Implement convenience functions to examine GDB settings.
  2019-07-05 19:58 [RFAv2 0/3] Convenience functions $_gdb_setting/$_gdb_int_setting Philippe Waroquiers
@ 2019-07-05 19:58 ` Philippe Waroquiers
  2019-07-05 19:58 ` [RFAv2 2/3] Test the convenience functions $_gdb_setting and $_gdb_int_setting Philippe Waroquiers
  2019-07-05 19:58 ` [RFAv2 3/3] NEWS and documentation for " Philippe Waroquiers
  2 siblings, 0 replies; 7+ messages in thread
From: Philippe Waroquiers @ 2019-07-05 19:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

The new convenience functions $_gdb_setting and $_gdb_int_setting
provide access to the GDB settings in user-defined commands.
---
 gdb/ChangeLog         |  10 ++++
 gdb/cli/cli-cmds.c    | 105 ++++++++++++++++++++++++++++++++++++++++++
 gdb/cli/cli-setshow.c |  43 ++++++++++++-----
 gdb/cli/cli-setshow.h |   5 ++
 4 files changed, 151 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a462b27ba5..ab414dca9f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -9112,3 +9112,13 @@ version-control: never
 coding: utf-8
 End:
 
+2019-04-28  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+	* cli/cli-cmds.c (setting_cmd, gdb_int_setting_internal_fn,
+	gdb_setting_internal_fn): New functions.
+	(_initialize_cli_cmds): Define the new convenience functions.
+	* cli/cli-setshow.h (do_print_setting): New declaration.
+	* cli/cli-setshow.c (do_print_setting): New function (mostly
+	copied from do_show_command).
+	(do_show_command): Call do_print_setting.
+	(do_print_setting): New function.
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 368ddf526d..a4d3f5ec9e 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1905,6 +1905,100 @@ show_max_user_call_depth (struct ui_file *file, int from_tty,
 		    value);
 }
 
+/* Returns the cmd_list_element corresponding to the first argument
+   of ARGV, which must contain one single value.
+   Throws an error if no value provided, or value not correct.
+   FNNAME is used in the error message.  */
+
+static cmd_list_element *
+setting_cmd (const char *fnname, int argc, struct value **argv)
+{
+  if (argc == 0)
+    error (_("You must provide an argument to %s"), fnname);
+  if (argc != 1)
+    error (_("You can only provide one argument to %s"), fnname);
+
+  struct type *type0 = check_typedef (value_type (argv[0]));
+
+  if (TYPE_CODE (type0) != TYPE_CODE_ARRAY
+      && TYPE_CODE (type0) != TYPE_CODE_STRING)
+    error (_("First argument of %s must be a string."), fnname);
+
+  int len0 = TYPE_LENGTH (type0);
+  std::vector<char> arg0 (len0);
+
+  memcpy (arg0.data (), value_contents (argv[0]), len0);
+
+  const char *a0 = arg0.data ();
+  cmd_list_element *cmd = lookup_cmd (&a0, showlist, "", -1, 0);
+
+  if (cmd == nullptr || cmd_type (cmd) != show_cmd)
+    error (_("First argument of %s must be a "
+	     "valid setting of the 'show' command."), fnname);
+
+  return cmd;
+}
+
+/* Implementation of the convenience function $_gdb_int_setting.  */
+
+static struct value *
+gdb_int_setting_internal_fn (struct gdbarch *gdbarch,
+			     const struct language_defn *language,
+			     void *cookie, int argc, struct value **argv)
+{
+  cmd_list_element *cmd = setting_cmd ("$_gdb_int_setting", argc, argv);
+
+  switch (cmd->var_type)
+    {
+    case var_boolean:
+    case var_integer:
+    case var_zinteger:
+    case var_zuinteger_unlimited:
+      return value_from_longest (builtin_type (gdbarch)->builtin_int,
+				 *(int *) cmd->var);
+    case var_auto_boolean:
+      {
+	int val = *(int *) cmd->var;
+
+	if (val == 0)
+	  val = 1;
+	else if (val == 1)
+	  val = 0;
+	return value_from_longest (builtin_type (gdbarch)->builtin_int,
+				   val);
+      }
+    case var_uinteger:
+      if (*(unsigned int *) cmd->var == UINT_MAX)
+	return value_from_longest (builtin_type (gdbarch)->builtin_int,
+				   0);
+      else
+	return value_from_longest (builtin_type (gdbarch)->builtin_int,
+				   *(unsigned int *) cmd->var);
+    case var_zuinteger:
+      return value_from_longest (builtin_type (gdbarch)->builtin_int,
+				 *(unsigned int *) cmd->var);
+    default:
+      error (_("Setting type not convertible to integer"));
+    }
+}
+
+/* Implementation of the convenience function $_gdb_setting.  */
+
+static struct value *
+gdb_setting_internal_fn (struct gdbarch *gdbarch,
+			 const struct language_defn *language,
+			 void *cookie, int argc, struct value **argv)
+{
+  cmd_list_element *cmd = setting_cmd ("$_gdb_setting", argc, argv);
+  string_file stb;
+
+  do_print_setting (&stb, cmd);
+
+  return value_cstring (stb.c_str (), strlen (stb.c_str ()),
+			builtin_type (gdbarch)->builtin_char);
+}
+
+
 void
 _initialize_cli_cmds (void)
 {
@@ -2045,6 +2139,17 @@ abbreviations for commands and/or values.  E.g.:\n\
   set_cmd_completer_handle_brkchars (c, with_command_completer);
   add_com_alias ("w", "with", class_vars, 1);
 
+  add_internal_function ("_gdb_setting", _("\
+$_gdb_setting - returns the value of a GDB setting as a string.\n\
+Usage: $_gdb_setting (setting)"),
+			 gdb_setting_internal_fn, NULL);
+
+  add_internal_function ("_gdb_int_setting", _("\
+$_gdb_int_setting - returns the value of an integer GDB setting as an integer.\n\
+Usage: $_int_gdb_int_setting (setting)\n\
+Throws an error if SETTING cannot be converted to an integer."),
+			 gdb_int_setting_internal_fn, NULL);
+
   add_cmd ("commands", no_set_class, show_commands, _("\
 Show the history of commands you typed.\n\
 You can supply a command number to start with, or a `+' to start after\n\
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 6fb32441ac..56c9dcab9f 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -634,29 +634,29 @@ get_setshow_command_value_string (cmd_list_element *c)
     {
     case var_string:
       if (*(char **) c->var)
-	stb.putstr (*(char **) c->var, '"');
+	stb->putstr (*(char **) c->var, '"');
       break;
     case var_string_noescape:
     case var_optional_filename:
     case var_filename:
     case var_enum:
       if (*(char **) c->var)
-	stb.puts (*(char **) c->var);
+	stb->puts (*(char **) c->var);
       break;
     case var_boolean:
-      stb.puts (*(int *) c->var ? "on" : "off");
+      stb->puts (*(int *) c->var ? "on" : "off");
       break;
     case var_auto_boolean:
       switch (*(enum auto_boolean*) c->var)
 	{
 	case AUTO_BOOLEAN_TRUE:
-	  stb.puts ("on");
+	  stb->puts ("on");
 	  break;
 	case AUTO_BOOLEAN_FALSE:
-	  stb.puts ("off");
+	  stb->puts ("off");
 	  break;
 	case AUTO_BOOLEAN_AUTO:
-	  stb.puts ("auto");
+	  stb->puts ("auto");
 	  break;
 	default:
 	  gdb_assert_not_reached ("invalid var_auto_boolean");
@@ -667,29 +667,48 @@ get_setshow_command_value_string (cmd_list_element *c)
     case var_zuinteger:
       if (c->var_type == var_uinteger
 	  && *(unsigned int *) c->var == UINT_MAX)
-	stb.puts ("unlimited");
+	stb->puts ("unlimited");
       else
-	stb.printf ("%u", *(unsigned int *) c->var);
+	stb->printf ("%u", *(unsigned int *) c->var);
       break;
     case var_integer:
     case var_zinteger:
       if (c->var_type == var_integer
 	  && *(int *) c->var == INT_MAX)
-	stb.puts ("unlimited");
+	stb->puts ("unlimited");
       else
-	stb.printf ("%d", *(int *) c->var);
+	stb->printf ("%d", *(int *) c->var);
       break;
     case var_zuinteger_unlimited:
       {
 	if (*(int *) c->var == -1)
-	  stb.puts ("unlimited");
+	  stb->puts ("unlimited");
 	else
-	  stb.printf ("%d", *(int *) c->var);
+	  stb->printf ("%d", *(int *) c->var);
       }
       break;
     default:
       gdb_assert_not_reached ("bad var_type");
     }
+}
+
+/* Do a "show" command.  ARG is NULL if no argument, or the
+   text of the argument, and FROM_TTY is nonzero if this command is
+   being entered directly by the user (i.e. these are just like any
+   other command).  C is the command list element for the command.  */
+
+void
+do_show_command (const char *arg, int from_tty, struct cmd_list_element *c)
+{
+  struct ui_out *uiout = current_uiout;
+
+  gdb_assert (c->type == show_cmd);
+
+  string_file stb;
+
+  /* Possibly call the pre hook.  */
+  if (c->pre_show_hook)
+    (c->pre_show_hook) (c);
 
   return std::move (stb.string ());
 }
diff --git a/gdb/cli/cli-setshow.h b/gdb/cli/cli-setshow.h
index 8bfe7e89f0..bcd6e475cd 100644
--- a/gdb/cli/cli-setshow.h
+++ b/gdb/cli/cli-setshow.h
@@ -63,4 +63,9 @@ extern std::string get_setshow_command_value_string (cmd_list_element *c);
 extern void cmd_show_list (struct cmd_list_element *list, int from_tty,
 			   const char *prefix);
 
+/* Prints in STB the current value of the GDB setting shown by C.  */
+
+void
+do_print_setting (string_file *stb, struct cmd_list_element *c);
+
 #endif /* CLI_CLI_SETSHOW_H */
-- 
2.20.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFAv2 2/3] Test the convenience functions $_gdb_setting and $_gdb_int_setting.
  2019-07-05 19:58 [RFAv2 0/3] Convenience functions $_gdb_setting/$_gdb_int_setting Philippe Waroquiers
  2019-07-05 19:58 ` [RFAv2 1/3] Implement convenience functions to examine GDB settings Philippe Waroquiers
@ 2019-07-05 19:58 ` Philippe Waroquiers
  2019-07-05 19:58 ` [RFAv2 3/3] NEWS and documentation for " Philippe Waroquiers
  2 siblings, 0 replies; 7+ messages in thread
From: Philippe Waroquiers @ 2019-07-05 19:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

---
 gdb/testsuite/ChangeLog            |  4 ++++
 gdb/testsuite/gdb.base/default.exp |  2 ++
 gdb/testsuite/gdb.base/setshow.exp | 27 ++++++++++++++++++++++++++-
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 90b5f8ff8b..3ba2235c0d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -16466,3 +16466,7 @@ For older changes see ChangeLog-1993-2013.
     Copyright 2014-2019 Free Software Foundation, Inc.
   Copying and distribution of this file, with or without modification,
   are permitted provided the copyright notice and this notice are preserved.
+2019-04-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+	* gdb.base/setshow.exp: Test $_gdb_setting and $_gdb_int_setting.
+	* gdb.base/default.exp: Update show_conv_list.
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index 0325b8045d..8e79cbc85d 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -604,6 +604,8 @@ set show_conv_list \
 	{$_cimag = <internal function _cimag>} \
 	{$_creal = <internal function _creal>} \
 	{$_isvoid = <internal function _isvoid>} \
+	{$_gdb_int_setting = <internal function _gdb_int_setting>} \
+	{$_gdb_setting = <internal function _gdb_setting>} \
 	{$_gdb_major = 8} \
 	{$_gdb_minor = 4} \
 	{$_shell_exitsignal = void} \
diff --git a/gdb/testsuite/gdb.base/setshow.exp b/gdb/testsuite/gdb.base/setshow.exp
index d807d75a66..b78bea8e18 100644
--- a/gdb/testsuite/gdb.base/setshow.exp
+++ b/gdb/testsuite/gdb.base/setshow.exp
@@ -100,17 +100,23 @@ if { !$use_gdb_stub && ![target_info exists noargs] } {
     gdb_test "run" "Starting program:.*foo bar blup baz bubble.*" "passing args"
 }
 #test set check range on
-gdb_test "set check range on" ".*" "set check range on" 
+gdb_test "set check range on" ".*" "set check range on"
+gdb_test "p \$_gdb_setting(\"check range\")" ".*\"on\"" \
+    "_gdb_setting check range on"
 #test show check range on
 gdb_test "show check range" "Range checking is \"on\"\..*" "show check range (on)" 
 #test set check range off with trailing space
 gdb_test_no_output "set check range off " "set check range off" 
 #test show check range off
 gdb_test "show check range" "Range checking is \"off\"\..*" "show check range (off)" 
+gdb_test "p \$_gdb_setting(\"check range\")" ".*\"off\"" \
+    "_gdb_setting check range off"
 #test set check range auto
 gdb_test_no_output "set check range auto" "set check range auto" 
 #test show check range auto
 gdb_test "show check range" "Range checking is \"auto; currently .*" "show check range (auto)"
+gdb_test "p \$_gdb_setting(\"check range\")" ".*\"auto\"" \
+    "_gdb_setting check range auto"
 
 # Test set check type on
 gdb_test "set check type on" ".*" "set check type on"
@@ -118,9 +124,17 @@ gdb_test "set check type on" ".*" "set check type on"
 # Test show check type on
 gdb_test "show check type" "Strict type checking is on\..*" \
     "show check type (on)"
+gdb_test "p \$_gdb_setting(\"check type\")" ".*\"on\"" \
+    "_gdb_setting check type on"
+gdb_test "p \$_gdb_int_setting(\"check type\")" ".*= 1" \
+    "_gdb_setting check type on 1"
 
 # Test set check type off with trailing space
 gdb_test_no_output "set check type off " "set check type off"
+gdb_test "p \$_gdb_setting(\"check type\")" ".*\"off\"" \
+    "_gdb_setting check type off"
+gdb_test "p \$_gdb_int_setting(\"check type\")" ".*= 0" \
+    "_gdb_setting check type off 0"
 
 # Test show check type off
 gdb_test "show check type" "Strict type checking is off\..*" \
@@ -159,9 +173,17 @@ gdb_test "show environment FOOBARBAZ" "FOOBARBAZ = grbxgrbxgrbx.*"  "show enviro
 gdb_test_no_output "set height 100" "set height 100" 
 #test show height 100
 gdb_test "show height" "Number of lines gdb thinks are in a page is 100..*" "show height" 
+gdb_test "p \$_gdb_setting(\"height\")" ".*\"100\"" \
+    "_gdb_setting height 100"
+gdb_test "p \$_gdb_int_setting(\"height\")" ".*= 100" \
+    "_gdb_int_setting height 100"
 # Back to infinite height to avoid pagers.  While at it, check that
 # literal "unlimited" works just as well as 0.
 gdb_test_no_output "set height unlimited"
+gdb_test "p \$_gdb_setting(\"height\")" ".*\"unlimited\"" \
+    "_gdb_setting height unlimited"
+gdb_test "p \$_gdb_int_setting(\"height\")" ".*= 0" \
+    "_gdb_int_setting height unlimited"
 #test set history expansion on
 gdb_test_no_output "set history expansion on" "set history expansion on" 
 #test show history expansion on
@@ -182,6 +204,9 @@ gdb_test_no_output "set history filename ~/foobar.baz" \
 gdb_test "show history filename" \
     "The filename in which to record the command history is \"[string_to_regexp $HOME]/foobar.baz\"..*" \
     "show history filename (~/foobar.baz)"
+gdb_test "p \$_gdb_setting(\"history filename\")" \
+    ".*\"[string_to_regexp $HOME]/foobar.baz\"..*" \
+    "_gdb_setting history filename"
 #get current working directory
 set PWD ""
 set test "show working directory"
-- 
2.20.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFAv2 3/3] NEWS and documentation for $_gdb_setting and $_gdb_int_setting.
  2019-07-05 19:58 ` [RFAv2 3/3] NEWS and documentation for " Philippe Waroquiers
@ 2019-07-06  6:23   ` Eli Zaretskii
  2019-07-06 10:54     ` Philippe Waroquiers
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2019-07-06  6:23 UTC (permalink / raw)
  To: Philippe Waroquiers; +Cc: gdb-patches

> From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> Date: Fri,  5 Jul 2019 21:58:23 +0200
> 
> +@item $_gdb_setting (@var{setting})
> +@findex $_gdb_setting@r{, convenience function}
> +Return the value of the @value{GDBN} @var{setting} as a string.
> +@var{setting} is any setting that can be used in a @code{set} or
> +@code{show} command (@pxref{Controlling GDB}).

After reading the description of $_gdb_int_setting, a question I have
about this function is whether it works for settings whose values are
integers.  The examples answer that question, but I think the text
should be explicit about that.

> +@item $_gdb_int_setting (@var{setting})
> +@findex $_gdb_int_setting@r{, convenience function}
> +Return the value of the @value{GDBN} @var{setting} as an integer.
> +This only works for boolean, auto boolean and integer settings.
> +The boolean values @code{on} and @code{off} are converted to
> +the integer values @code{0} and @code{1}.

The correspondence of ON and OFF to zero and 1 respectively surprised
me.  Why not the other way around?

>                                             The value @code{auto} is
> +converted to the value  @code{2}.
> +Some integer settings accepts an @code{unlimited} value.
> +Depending on the setting, the unlimited value is converted to a @code{0}
> +or a @code{-1} value.

The last part begs a question how to know whether 'unlimited' will
yield zero or -1?  Can't we always return -1?

Markup-wise, please use @code{@minus{}1}, it will look better in print.

Btw, do we have a way of determining whether a given convenience
function exists in the current GDB?  For variables, one can use
$_isvoid, I think, but what about functions?

Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFAv2 3/3] NEWS and documentation for $_gdb_setting and $_gdb_int_setting.
  2019-07-06  6:23   ` Eli Zaretskii
@ 2019-07-06 10:54     ` Philippe Waroquiers
  2019-07-06 11:21       ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Philippe Waroquiers @ 2019-07-06 10:54 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Thanks for the comments, I have just sent a v3 that handles
them.

(note that v2 did not change anything compared to v1, as I forgot
to commit the changes before sending the mail).

Some more feedback below.


On Sat, 2019-07-06 at 09:23 +0300, Eli Zaretskii wrote:
> > From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> > Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> > Date: Fri,  5 Jul 2019 21:58:23 +0200
> > 
> > +@item $_gdb_setting (@var{setting})
> > +@findex $_gdb_setting@r{, convenience function}
> > +Return the value of the @value{GDBN} @var{setting} as a string.
> > +@var{setting} is any setting that can be used in a @code{set} or
> > +@code{show} command (@pxref{Controlling GDB}).
> 
> After reading the description of $_gdb_int_setting, a question I have
> about this function is whether it works for settings whose values are
> integers.  The examples answer that question, but I think the text
> should be explicit about that.
I have tried to clarify this in the description in RFAv3.

> 
> > +@item $_gdb_int_setting (@var{setting})
> > +@findex $_gdb_int_setting@r{, convenience function}
> > +Return the value of the @value{GDBN} @var{setting} as an integer.
> > +This only works for boolean, auto boolean and integer settings.
> > +The boolean values @code{on} and @code{off} are converted to
> > +the integer values @code{0} and @code{1}.
> 
> The correspondence of ON and OFF to zero and 1 respectively surprised
> me.  Why not the other way around?
That was an error in the doc, fixed in RFAv3.  It now describes
that 0 is off and 1 is on.

> 
> >                                             The value @code{auto} is
> > +converted to the value  @code{2}.
> > +Some integer settings accepts an @code{unlimited} value.
> > +Depending on the setting, the unlimited value is converted to a @code{0}
> > +or a @code{-1} value.
> 
> The last part begs a question how to know whether 'unlimited' will
> yield zero or -1?  Can't we always return -1?
I think it is better to keep the same convention as what is accepted
by the "set" command: some settings are using 0 to mean unlimited
and some are using -1.
I have tried to describe this in the doc RFAv3.

> 
> Markup-wise, please use @code{@minus{}1}, it will look better in print.
> 
> Btw, do we have a way of determining whether a given convenience
> function exists in the current GDB?  For variables, one can use
> $_isvoid, I think, but what about functions?

I do not know of any way to see if a user defined function or convenience
function is defined.
For the GDB convenience function, the GDB major/minor can be used to 
determine what is available.

Philippe


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFAv2 3/3] NEWS and documentation for $_gdb_setting and $_gdb_int_setting.
  2019-07-06 10:54     ` Philippe Waroquiers
@ 2019-07-06 11:21       ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2019-07-06 11:21 UTC (permalink / raw)
  To: Philippe Waroquiers; +Cc: gdb-patches

> From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
> Cc: gdb-patches@sourceware.org
> Date: Sat, 06 Jul 2019 12:54:39 +0200
> 
> > The last part begs a question how to know whether 'unlimited' will
> > yield zero or -1?  Can't we always return -1?
> I think it is better to keep the same convention as what is accepted
> by the "set" command: some settings are using 0 to mean unlimited
> and some are using -1.
> I have tried to describe this in the doc RFAv3.

The new text is OK, but I'd suggest to say in addition something like
"See the documentation of the corresponding @code{set} command for
the numerical value equivalent to @code{unlimited}."

> > Btw, do we have a way of determining whether a given convenience
> > function exists in the current GDB?  For variables, one can use
> > $_isvoid, I think, but what about functions?
> 
> I do not know of any way to see if a user defined function or convenience
> function is defined.
> For the GDB convenience function, the GDB major/minor can be used to 
> determine what is available.

OK, thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-07-06 11:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-05 19:58 [RFAv2 0/3] Convenience functions $_gdb_setting/$_gdb_int_setting Philippe Waroquiers
2019-07-05 19:58 ` [RFAv2 1/3] Implement convenience functions to examine GDB settings Philippe Waroquiers
2019-07-05 19:58 ` [RFAv2 2/3] Test the convenience functions $_gdb_setting and $_gdb_int_setting Philippe Waroquiers
2019-07-05 19:58 ` [RFAv2 3/3] NEWS and documentation for " Philippe Waroquiers
2019-07-06  6:23   ` Eli Zaretskii
2019-07-06 10:54     ` Philippe Waroquiers
2019-07-06 11:21       ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).