From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 8789338582BE; Fri, 8 Jul 2022 20:07:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8789338582BE Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Handle bool specially in gdb.set_parameter X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 57f8fe908bec51c40ec686294460ec979b140843 X-Git-Newrev: fa17a6814113ac22d8059d61514aa2c6e29b0aae Message-Id: <20220708200730.8789338582BE@sourceware.org> Date: Fri, 8 Jul 2022 20:07:30 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2022 20:07:30 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfa17a6814113= ac22d8059d61514aa2c6e29b0aae commit fa17a6814113ac22d8059d61514aa2c6e29b0aae Author: Tom Tromey Date: Sun Jun 12 11:36:08 2022 -0600 Handle bool specially in gdb.set_parameter =20 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. =20 I looked at a fix involving rewriting set_parameter in C++. However, this one is simpler. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29217 Diff: --- 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 17ee6a19e14..9e9978ef30e 100644 --- a/gdb/python/lib/gdb/__init__.py +++ b/gdb/python/lib/gdb/__init__.py @@ -239,6 +239,13 @@ def find_pc_line(pc): =20 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 =3D 'on' + else: + value =3D 'off' execute("set " + name + " " + str(value), to_string=3DTrue) =20 =20 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" \