It's long bothered me that setting a Python parameter from the CLI
will print the "set" help text by default. I think usually "set"
commands should be silent. And, while you can modify this behavior a
bit by providing a "get_set_string" method, if this method returns an
empty string, a blank line will be printed.
This patch removes the "help" behavior and changes the get_set_string
behavior to avoid printing a blank line. The code has a comment about
preserving API behavior, but I don't think this is truly important;
and in any case the workaround -- implementing get_set_string -- is
trivial.
Regression tested on x86-64 Fedora 26.
2018-04-26 Tom Tromey <tom@tromey.com>
* NEWS: Mention new "set" behavior.
* python/py-param.c (get_set_value): Don't print an empty string.
Don't call get_doc_string.
gdb/doc/ChangeLog
2018-04-26 Tom Tromey <tom@tromey.com>
* python.texi (Parameters In Python): Update get_set_string
documentation.
gdb.set_convenience_variable can be used to get and set the value
of convenience variables.
gdb.set_convenience_variable can be used to get and set the value
of convenience variables.
+ ** A gdb.Parameter will no longer print the "set" help text on an
+ ordinary "set"; instead by default a "set" will be silent unless
+ the get_set_string method returns a non-empty string.
+
* New targets
RiscV ELF riscv*-*-elf
* New targets
RiscV ELF riscv*-*-elf
attribute. @value{GDBN} does validation when assignments are made.
@end defvar
attribute. @value{GDBN} does validation when assignments are made.
@end defvar
-There are two methods that should be implemented in any
-@code{Parameter} class. These are:
+There are two methods that may be implemented in any @code{Parameter}
+class. These are:
@defun Parameter.get_set_string (self)
@defun Parameter.get_set_string (self)
-@value{GDBN} will call this method when a @var{parameter}'s value has
-been changed via the @code{set} API (for example, @kbd{set foo off}).
-The @code{value} attribute has already been populated with the new
-value and may be used in output. This method must return a string.
+If this method exists, @value{GDBN} will call it when a
+@var{parameter}'s value has been changed via the @code{set} API (for
+example, @kbd{set foo off}). The @code{value} attribute has already
+been populated with the new value and may be used in output. This
+method must return a string. If the returned string is not empty,
+@value{GDBN} will present it to the user.
@end defun
@defun Parameter.get_show_string (self, svalue)
@end defun
@defun Parameter.get_show_string (self, svalue)
- else
- {
- /* We have to preserve the existing < GDB 7.3 API. If a
- callback function does not exist, then attempt to read the
- set_doc attribute. */
- set_doc_string = get_doc_string (obj, set_doc_cst);
- }
- fprintf_filtered (gdb_stdout, "%s\n", set_doc_string.get ());
+ const char *str = set_doc_string.get ();
+ if (str != nullptr && str[0] != '\0')
+ fprintf_filtered (gdb_stdout, "%s\n", str);
}
/* A callback function that is registered against the respective
}
/* A callback function that is registered against the respective
"end"
gdb_test "show print test-nodoc-param" "This command is not documented.*" "show parameter on"
"end"
gdb_test "show print test-nodoc-param" "This command is not documented.*" "show parameter on"
-gdb_test "set print test-nodoc-param off" "This command is not documented.*" "turn off parameter"
+gdb_test_no_output "set print test-nodoc-param off" "turn off parameter"
gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "show parameter off"
gdb_test "python print (test_nodoc_param.value)" "False" "test parameter value"
gdb_test "help show print test-nodoc-param" "This command is not documented.*" "test show help"
gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "show parameter off"
gdb_test "python print (test_nodoc_param.value)" "False" "test parameter value"
gdb_test "help show print test-nodoc-param" "This command is not documented.*" "test show help"
gdb_test "python print (test_param.value)" "True" "test parameter value"
gdb_test "show print test-param" "State of the Test Parameter on.*" "show parameter on"
gdb_test "python print (test_param.value)" "True" "test parameter value"
gdb_test "show print test-param" "State of the Test Parameter on.*" "show parameter on"
-gdb_test "set print test-param off" "Set the state of the Test Parameter.*" "turn off parameter"
+gdb_test_no_output "set print test-param off" "turn off parameter"
gdb_test "show print test-param" "State of the Test Parameter off.*" "show parameter off"
gdb_test "python print (test_param.value)" "False" "test parameter value"
gdb_test "help show print test-param" "State of the Test Parameter.*" "test show help"
gdb_test "show print test-param" "State of the Test Parameter off.*" "show parameter off"
gdb_test "python print (test_param.value)" "False" "test parameter value"
gdb_test "help show print test-param" "State of the Test Parameter.*" "test show help"