[RFAv6,0/3] Convenience functions $_gdb_setting/$_gdb_setting_str

Message ID 20191030224424.9288-1-philippe.waroquiers@skynet.be
State New
Headers show

Commit Message

Philippe Waroquiers Oct. 30, 2019, 10:44 p.m.
This is v6.
Compared to v5, it does the minor modifications suggested by Pedro
and adds the missing doc for  $_gdb_maint_setting, $_gdb_maint_setting_str
in gdb.texinfo.
To make the re-review easier, I have appended the delta between v5 and v6
at the end of this cover note.

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.
4 functions are provided:
  * $_gdb_setting_str returning a string value of the setting.
  * $_gdb_setting, returning an integer or string value of a setting,
    depending on the setting type.
    For integer/boolean/auto boolean settings, this is easier to use
    than the string version.
  * $_gdb_maint_setting, $_gdb_maint_setting_str : same as above, but
    for maintenance settings.

Some notes:
In settings.exp show_setting, I have not added a check that RESET_VALUE
differs from the expected value: this means to add a specific reset_value
to a lot of show_setting calls.  As enough different values are verified,
this seems not necessary.

For what concerns ptype $_gdb_setting("something") always giving type int:
This is "normal".  For example, "ptype $_as_string(123)" similarly gives int.

The reason: ptype evaluates the given expression, but in a way that avoids
side effects.  This then leads to eval_call in eval.c, that does:
  ...
  if (noside == EVAL_AVOID_SIDE_EFFECTS)
    {
      ...

      if (TYPE_CODE (ftype) == TYPE_CODE_INTERNAL_FUNCTION)
	{
	  /* We don't know anything about what the internal
	     function might return, but we have to return
	     something.  */
	  return value_zero (builtin_type (exp->gdbarch)->builtin_int,
			     not_lval);

and so any internal GDB function will always have the "type int".
Wondering if it would not be better to report an error such as
("No type information for GDB functions") rather than lie.


Delta between v5 and v6:

Comments

Pedro Alves Oct. 30, 2019, 10:51 p.m. | #1
On 10/30/19 10:44 PM, Philippe Waroquiers wrote:
> This is v6.

> Compared to v5, it does the minor modifications suggested by Pedro

> and adds the missing doc for  $_gdb_maint_setting, $_gdb_maint_setting_str

> in gdb.texinfo.

> To make the re-review easier, I have appended the delta between v5 and v6

> at the end of this cover note.


Thanks, those changes look good to me.

Thanks,
Pedro Alves
Eli Zaretskii Oct. 31, 2019, 2:07 p.m. | #2
> From: Philippe Waroquiers <philippe.waroquiers@skynet.be>

> Date: Wed, 30 Oct 2019 23:44:21 +0100

> 

> This is v6.

> Compared to v5, it does the minor modifications suggested by Pedro

> and adds the missing doc for  $_gdb_maint_setting, $_gdb_maint_setting_str

> in gdb.texinfo.


Thanks, the documentation parts are OK.

Patch

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index ed699894f5..4e58ddc6d6 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -2253,8 +2253,8 @@  Usage: $_gdb_setting_str (setting)\n\
 \n\
 auto-boolean values are \"off\", \"on\", \"auto\".\n\
 boolean values are \"off\", \"on\".\n\
-The unlimited value for integer, uinteger, zuinteger-unlimited\n\
-settings is represented as \"unlimited\"."),
+Some integer settings accept an unlimited value, returned\n\
+as \"unlimited\"."),
 			 gdb_setting_str_internal_fn, NULL);
 
   add_internal_function ("_gdb_setting", _("\
@@ -2262,8 +2262,8 @@  $_gdb_setting - returns the value of a GDB setting.\n\
 Usage: $_gdb_setting (setting)\n\
 auto-boolean values are \"off\", \"on\", \"auto\".\n\
 boolean values are \"off\", \"on\".\n\
-The unlimited value for integer, uinteger settings is 0.\n\
-The unlimited value for zuinteger-unlimited is -1."),
+Some integer settings accept an unlimited value, returned\n\
+as 0 or -1 depending on the setting."),
 			 gdb_setting_internal_fn, NULL);
 
   add_internal_function ("_gdb_maint_setting_str", _("\
@@ -2272,8 +2272,8 @@  Usage: $_gdb_maint_setting_str (setting)\n\
 \n\
 auto-boolean values are \"off\", \"on\", \"auto\".\n\
 boolean values are \"off\", \"on\".\n\
-The unlimited value for integer, uinteger, zuinteger-unlimited\n\
-settings is represented as \"unlimited\"."),
+Some integer settings accept an unlimited value, returned\n\
+as \"unlimited\"."),
 			 gdb_maint_setting_str_internal_fn, NULL);
 
   add_internal_function ("_gdb_maint_setting", _("\
@@ -2281,8 +2281,8 @@  $_gdb_maint_setting - returns the value of a GDB maintenance setting.\n\
 Usage: $_gdb_maint_setting (setting)\n\
 auto-boolean values are \"off\", \"on\", \"auto\".\n\
 boolean values are \"off\", \"on\".\n\
-The unlimited value for integer, uinteger settings is 0.\n\
-The unlimited value for zuinteger-unlimited is -1."),
+Some integer settings accept an unlimited value, returned\n\
+as 0 or -1 depending on the setting."),
 			 gdb_maint_setting_internal_fn, NULL);
 
   add_cmd ("commands", no_set_class, show_commands, _("\
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index e3c9a98b68..7cf4141d20 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -12065,6 +12065,17 @@  $8 = -1
 Other setting types (enum, filename, optional filename, string, string noescape)
 are returned as string values.
 
+
+@item $_gdb_maint_setting_str (@var{setting})
+@findex $_gdb_maint_setting_str@r{, convenience function}
+Like the @code{$_gdb_setting_str} function, but works with
+@code{maintenance set} variables.
+
+@item $_gdb_maint_setting (@var{setting})
+@findex $_gdb_maint_setting@r{, convenience function}
+Like the @code{$_gdb_setting} function, but works with
+@code{maintenance set} variables.
+
 @end table
 
 The following functions require @value{GDBN} to be configured with
diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp
index 3cb6e63efe..40a30387c3 100644
--- a/gdb/testsuite/gdb.base/settings.exp
+++ b/gdb/testsuite/gdb.base/settings.exp
@@ -108,6 +108,13 @@  proc check_type {setting expected} {
     with_test_prefix "check_type $setting $expected" {
 	gdb_test "print \$_gdb_maint_setting(\"$setting\")"
 	gdb_test "ptype $" "$expected"
+
+	# Currently, GDB ptype <internal function> always tells it is type int.
+	# ptype should better report an error such as:
+	#   "No type information for GDB functions"
+	# Test 'type int', so as to make it fail if ptype is changed.
+	gdb_test "ptype \$_gdb_maint_setting(\"$setting\")" \
+            "type = int"
     }
 }