diff options
author | Andrew Burgess <aburgess@redhat.com> | 2025-04-11 23:45:51 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2025-05-13 14:33:20 +0100 |
commit | 4b68d4ac98aec7cb73a4b276ac7dd38d112786b4 (patch) | |
tree | 185455c781e2cdc0984627c2c0b98c43e9f93701 /gdb/python/python.h | |
parent | 3e87f196c5c35e3e071ef0cdd14666d2c97d3f51 (diff) | |
download | binutils-4b68d4ac98aec7cb73a4b276ac7dd38d112786b4.zip binutils-4b68d4ac98aec7cb73a4b276ac7dd38d112786b4.tar.gz binutils-4b68d4ac98aec7cb73a4b276ac7dd38d112786b4.tar.bz2 |
gdb/python: allow empty gdb.Parameter.__doc__ string
I was recently attempting to create some parameters via the Python
API. I wanted these parameters to appear similar to how GDB handles
the existing 'style' parameters.
Specifically, I was interested in this behaviour:
(gdb) help show style filename foreground
Show the foreground color for this property.
(gdb) help set style filename foreground
Set the foreground color for this property.
(gdb)
Notice how each 'help' command only gets a single line of output.
I tried to reproduce this behaviour via the Python API and was unable.
The problem is that, in order to get just a single line of output like
this, the style parameters are registered with a call to
add_setshow_color_cmd with the 'help_doc' being passed as nullptr.
On the Python side, when parameters are created, the 'help_doc' is
obtained with a call to get_doc_string (python/py-param.c). This
function either returns the __doc__ string, or a default string: "This
command is not documented.".
To avoid returning the default we could try setting __doc__ to an
empty string, but setting this field to any string means that GDB
prints a line for that string, like this:
class test_param(gdb.Parameter):
__doc__ = ""
def __init__(self, name):
super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)
self.value = True
test_param('print test')
Then in GDB:
(gdb) help set print test
Set the current value of 'print test'.
(gdb)
The blank line is the problem I'd like to solve.
This commit makes a couple of changes to how parameter doc strings are
handled.
If the doc string is set to an empty string, then GDB now converts
this to nullptr, which removes the blank line problem, the new
behaviour in GDB (for the above `test_param`) is:
(gdb) help set print test
Set the current value of 'print test'.
(gdb)
Next, I noticed that if the set/show docs are set to empty strings,
then the results are less than ideal:
class test_param(gdb.Parameter):
set_doc = ""
def __init__(self, name):
super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)
self.value = True
test_param('print test')
And in GDB:
(gdb) help set print test
This command is not documented.
(gdb)
So, if the set/show docs are the empty string, GDB now forces these to
be the default string instead, the new behaviour in GDB is:
(gdb) help set print test
Set the current value of 'print test'.
This command is not documented.
(gdb)
I've added some additional asserts; the set/show docs should always be
non-empty strings, which I believe is the case after this commit. And
the 'doc' string returned from get_doc_string should never nullptr,
but could be empty.
There are new tests to cover all these changes.
Diffstat (limited to 'gdb/python/python.h')
0 files changed, 0 insertions, 0 deletions