Bug 29217

Summary: gdb.set_parameter doesn't accept a bool where gdb.parameter returns one
Product: gdb Reporter: Dennis Lubert <plasmahh>
Component: pythonAssignee: Tom Tromey <tromey>
Status: RESOLVED FIXED    
Severity: normal CC: tromey
Priority: P2    
Version: HEAD   
Target Milestone: 13.1   
Host: Target:
Build: Last reconfirmed: 2022-06-05 00:00:00

Description Dennis Lubert 2022-06-01 12:11:46 UTC
bool settings return bools in python:

> python print(type(gdb.parameter("may-interrupt")))
<class 'bool'>


but do not accept them:

> python gdb.set_parameter("may-interrupt",False)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/plasmahh/opt/gdb/share/gdb/python/gdb/__init__.py", line 237, in set_parameter
    execute("set " + name + " " + str(value), to_string=True)
gdb.error: "on" or "off" expected.
Error while executing Python code.


which paticularily also breaks gdb.with_parameter() for bool values.


While something like if( isinstance(gdb.parameter(name),bool) ): value = { True:"on",False:"off"}[value]
will fix this particular case, it might make more sense to enhance the gdb core functionality to accept "True" (and maybe "true") too since despite the message, 1, "yes" and "enable" are already accepted.
Comment 1 Tom Tromey 2022-06-05 23:07:50 UTC
I have a patch for this.
Comment 2 Sourceware Commits 2022-07-08 20:07:31 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fa17a6814113ac22d8059d61514aa2c6e29b0aae

commit fa17a6814113ac22d8059d61514aa2c6e29b0aae
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Jun 12 11:36:08 2022 -0600

    Handle bool specially in gdb.set_parameter
    
    PR python/29217 points out that gdb.parameter will return bool values,
    but gdb.set_parameter will not properly accept them.  This patch fixes
    the problem by adding a special case to set_parameter.
    
    I looked at a fix involving rewriting set_parameter in C++.  However,
    this one is simpler.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29217
Comment 3 Tom Tromey 2022-07-08 20:09:25 UTC
Fixed.
Comment 4 Sourceware Commits 2022-10-21 07:56:27 UTC
The master branch has been updated by Maciej W. Rozycki <macro@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c506be7d9be55721a44d38782309d8f7fcd5e99e

commit c506be7d9be55721a44d38782309d8f7fcd5e99e
Author: Maciej W. Rozycki <macro@embecosm.com>
Date:   Fri Oct 21 08:54:18 2022 +0100

    GDB/Python: Make `None' stand for `unlimited' in setting integer parameters
    
    Similarly to booleans and following the fix for PR python/29217 make
    `gdb.parameter' accept `None' for `unlimited' with parameters of the
    PARAM_UINTEGER, PARAM_INTEGER, and PARAM_ZUINTEGER_UNLIMITED types, as
    `None' is already returned by parameters of the two former types, so
    one might expect to be able to feed it back.  It also makes it possible
    to avoid the need to know what the internal integer representation is
    for the special setting of `unlimited'.
    
    Expand the testsuite accordingly.
    
    Approved-By: Simon Marchi <simon.marchi@polymtl.ca>