* [PATCH] Handle bool specially in gdb.set_parameter
@ 2022-06-12 17:38 Tom Tromey
2022-07-08 19:56 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-06-12 17:38 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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.
---
gdb/python/lib/gdb/__init__.py | 7 +++++++
gdb/testsuite/gdb.python/py-parameter.exp | 4 ++++
2 files changed, 11 insertions(+)
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index a52f6b46413..dbc219c7592 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -234,6 +234,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)
diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
index db158ddec26..d6db6ac3bb1 100644
--- a/gdb/testsuite/gdb.python/py-parameter.exp
+++ b/gdb/testsuite/gdb.python/py-parameter.exp
@@ -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" \
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Handle bool specially in gdb.set_parameter
2022-06-12 17:38 [PATCH] Handle bool specially in gdb.set_parameter Tom Tromey
@ 2022-07-08 19:56 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2022-07-08 19:56 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
Tom> PR python/29217 points out that gdb.parameter will return bool values,
Tom> but gdb.set_parameter will not properly accept them. This patch fixes
Tom> the problem by adding a special case to set_parameter.
Tom> I looked at a fix involving rewriting set_parameter in C++. However,
Tom> this one is simpler.
I'm checking this in.
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-08 19:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-12 17:38 [PATCH] Handle bool specially in gdb.set_parameter Tom Tromey
2022-07-08 19:56 ` Tom Tromey
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).