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
This commit is contained in:
Tom Tromey
2022-06-12 11:36:08 -06:00
parent 57f8fe908b
commit fa17a68141
2 changed files with 11 additions and 0 deletions

View File

@ -239,6 +239,13 @@ def find_pc_line(pc):
def set_parameter(name, value):
"""Set the GDB parameter NAME to VALUE."""
# Handle the specific case of booleans here, because gdb.parameter
# can return them, but they can't be passed to 'set' this way.
if isinstance(value, bool):
if value:
value = 'on'
else:
value = 'off'
execute("set " + name + " " + str(value), to_string=True)

View File

@ -126,6 +126,10 @@ proc_with_prefix test_boolean_parameter { } {
"The state of the Test Parameter is off.*" "show parameter off"
gdb_test "python print (test_param.value)" "False" \
"test boolean parameter value is False"
gdb_test_no_output "python gdb.set_parameter('print test-param', True)" \
"set boolean parameter using set_parameter"
gdb_test "python print(gdb.parameter('print test-param'))" "True" \
"get boolean parameter using gdb.parameter"
gdb_test "help show print test-param" \
[multi_line \
"Show the state of the boolean test-param" \