* [RFA] Fix "set" handling of Python parameters
@ 2018-04-26 22:51 Tom Tromey
2018-04-27 6:42 ` Eli Zaretskii
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Tom Tromey @ 2018-04-26 22:51 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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.
gdb/ChangeLog
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/ChangeLog | 6 ++++++
gdb/NEWS | 6 ++++++
gdb/doc/ChangeLog | 5 +++++
gdb/doc/python.texi | 14 ++++++++------
gdb/python/py-param.c | 11 +++--------
gdb/testsuite/gdb.python/py-parameter.exp | 4 ++--
6 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index 63fe30d175..c992048634 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -24,6 +24,12 @@ set|show record btrace cpu
Controls the processor to be used for enabling errata workarounds for
branch trace decode.
+* Python API
+
+ ** 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
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ebd48fffe7..7bbfb09d04 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3722,14 +3722,16 @@ parameter. It can be read and assigned to just as any other
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)
-@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)
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 0f8d9b6b42..77311ad1bd 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -381,15 +381,10 @@ get_set_value (const char *args, int from_tty,
return;
}
}
- 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
diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
index 3cd1198462..f52d737dbc 100644
--- a/gdb/testsuite/gdb.python/py-parameter.exp
+++ b/gdb/testsuite/gdb.python/py-parameter.exp
@@ -151,7 +151,7 @@ gdb_py_test_multiple "Simple gdb booleanparameter" \
"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"
@@ -173,7 +173,7 @@ gdb_py_test_multiple "Simple gdb booleanparameter" \
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"
--
2.13.6
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] Fix "set" handling of Python parameters
2018-04-26 22:51 [RFA] Fix "set" handling of Python parameters Tom Tromey
@ 2018-04-27 6:42 ` Eli Zaretskii
2018-04-30 13:01 ` Phil Muldoon
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2018-04-27 6:42 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>
> Date: Thu, 26 Apr 2018 16:51:40 -0600
>
> +* Python API
> +
> + ** 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.
The code mentions compatibility with GDB < 7.3, so shouldn't NEWS at
least indicate that this breaks that compatibility?
> +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.
So there's no way for a Python extension to display an empty string,
even if it wants to do that?
Anyway, the documentation parts are approved. Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] Fix "set" handling of Python parameters
2018-04-26 22:51 [RFA] Fix "set" handling of Python parameters Tom Tromey
2018-04-27 6:42 ` Eli Zaretskii
@ 2018-04-30 13:01 ` Phil Muldoon
2018-05-25 17:34 ` Tom Tromey
2018-05-30 23:16 ` Joel Brobecker
3 siblings, 0 replies; 5+ messages in thread
From: Phil Muldoon @ 2018-04-30 13:01 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 26/04/18 23:51, Tom Tromey wrote:
> diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
> index 0f8d9b6b42..77311ad1bd 100644
> --- a/gdb/python/py-param.c
> +++ b/gdb/python/py-param.c
> @@ -381,15 +381,10 @@ get_set_value (const char *args, int from_tty,
> return;
> }
> }
> - 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
> diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
> index 3cd1198462..f52d737dbc 100644
> --- a/gdb/testsuite/gdb.python/py-parameter.exp
> +++ b/gdb/testsuite/gdb.python/py-parameter.exp
> @@ -151,7 +151,7 @@ gdb_py_test_multiple "Simple gdb booleanparameter" \
> "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"
> @@ -173,7 +173,7 @@ gdb_py_test_multiple "Simple gdb booleanparameter" \
>
> 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"
I have no comments other than I read the patch and it LGTM.
Cheers
Phil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] Fix "set" handling of Python parameters
2018-04-26 22:51 [RFA] Fix "set" handling of Python parameters Tom Tromey
2018-04-27 6:42 ` Eli Zaretskii
2018-04-30 13:01 ` Phil Muldoon
@ 2018-05-25 17:34 ` Tom Tromey
2018-05-30 23:16 ` Joel Brobecker
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2018-05-25 17:34 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
Tom> It's long bothered me that setting a Python parameter from the CLI
Tom> will print the "set" help text by default. I think usually "set"
Tom> commands should be silent. And, while you can modify this behavior a
Tom> bit by providing a "get_set_string" method, if this method returns an
Tom> empty string, a blank line will be printed.
Tom> This patch removes the "help" behavior and changes the get_set_string
Tom> behavior to avoid printing a blank line. The code has a comment about
Tom> preserving API behavior, but I don't think this is truly important;
Tom> and in any case the workaround -- implementing get_set_string -- is
Tom> trivial.
Tom> Regression tested on x86-64 Fedora 26.
Ping.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFA] Fix "set" handling of Python parameters
2018-04-26 22:51 [RFA] Fix "set" handling of Python parameters Tom Tromey
` (2 preceding siblings ...)
2018-05-25 17:34 ` Tom Tromey
@ 2018-05-30 23:16 ` Joel Brobecker
3 siblings, 0 replies; 5+ messages in thread
From: Joel Brobecker @ 2018-05-30 23:16 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Hi Tom,
> gdb/ChangeLog
> 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.
So sorry again for the long delay in getting this patch reviewed.
Looks good!
--
Joel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-05-30 23:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-26 22:51 [RFA] Fix "set" handling of Python parameters Tom Tromey
2018-04-27 6:42 ` Eli Zaretskii
2018-04-30 13:01 ` Phil Muldoon
2018-05-25 17:34 ` Tom Tromey
2018-05-30 23:16 ` Joel Brobecker
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).