From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy4-pub.mail.unifiedlayer.com (gproxy4-pub.mail.unifiedlayer.com [69.89.23.142]) by sourceware.org (Postfix) with ESMTPS id 1C7E23857374 for ; Sun, 12 Jun 2022 17:38:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C7E23857374 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway6.mail.pro1.eigbox.com (Postfix) with ESMTP id 7AD3F10047D6D for ; Sun, 12 Jun 2022 17:38:15 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 0RXSol6PBrOQ90RXTorUaw; Sun, 12 Jun 2022 17:38:15 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=CpF6zl0D c=1 sm=1 tr=0 ts=62a62487 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=JPEYwPQDsx4A:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=_zpKcILrj0L7qUQh5ckA:9 a=0bXxn9q0MV6snEgNplNhOjQmxlI=:19 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=NiDQeq5wUuipWZWKh9uD9jz6rDOYTw9Lq602JzV25X4=; b=ocOEz0767OmNebSnng50K4pzw6 ZIuXl+Nd/O2TWNC2oLzTckacrjFw2Rh36R4V+NaYdaaC+1dIQmN1CCKAPA95R7vyHoDJMa7cLK819 op7l69xGowatIUqDDYd8qR/Fb; Received: from 71-211-171-143.hlrn.qwest.net ([71.211.171.143]:45656 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1o0RXS-002ro5-Ie; Sun, 12 Jun 2022 11:38:14 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Handle bool specially in gdb.set_parameter Date: Sun, 12 Jun 2022 11:38:12 -0600 Message-Id: <20220612173812.1470729-1-tom@tromey.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.171.143 X-Source-L: No X-Exim-ID: 1o0RXS-002ro5-Ie X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-171-143.hlrn.qwest.net (prentzel.Home) [71.211.171.143]:45656 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3029.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jun 2022 17:38:17 -0000 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