From patchwork Sat Oct 29 13:53:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 59619 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3277538582A2 for ; Sat, 29 Oct 2022 13:53:37 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 1931638582A8 for ; Sat, 29 Oct 2022 13:53:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1931638582A8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42f.google.com with SMTP id bk15so9902374wrb.13 for ; Sat, 29 Oct 2022 06:53:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kqW2hQ2bbjChPYywa5668+lWEn0za7ub9UDHBLoY3uE=; b=ctfTEhikfJMw6+7OmE2xF+27L4dHjkbmPrjkLAcNBZ5EiJl41wRyM5xXkwMrys7YnP NviJRcPhfJinqNSY2xyWrlh9j/nLtfPjtKIDvDrVU0nf0OVslDEnyAn3XaW9r2s6lQh/ TGK+82Ptxh8NVtQ5hAZbjy5jg2bt3h9rbLjksuXSZ2SnDhvLP6y5pke8k1IUCYNYcNuW f3RrKXXITnjIZ+s5GLaYt/KQpE2jlHTVl5I/aFgMCDPeP8UlJ4a02cZic2+V4zAsmiGx ctQ7ksJN0IiTiljCBLu+UBs342q2cG4+8gPlk+MxxRx125Yw6GMC+00B5sATnGitvdIX S2lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kqW2hQ2bbjChPYywa5668+lWEn0za7ub9UDHBLoY3uE=; b=U7uh5nK9rTRx2Xe937vDFWlxN1mGFgfC7U3fDACJrCnwlcLsRWLkrtvu9acPrEj06j vAg4QdbJs9I+rGV60sHA6ru1PCquIWo07qM+tdCUT6+XPMyabU0+yR49W1KymU8x4KEr PwKEgC7QVhd+a9FESXjWpNpNy8M8YpBmu3/782GQ/zFNSvuy4YObl7C+XwrYSQNFdP95 5ij9SpVWMoCHyob/HdbKFyvyu9Oo/fXfHiqF9Kbw6SxWNE5kwI/j52MFMVXuNYt+yXKz GLj2YAReI/69iUEzFTb1P4JLDOcBQwJmAG0zYHTkRcd/ytouhiihRAAFo8feaJVMDfdX zayw== X-Gm-Message-State: ACrzQf3LCkTUPxkJUhPR9XpXoYoPlg0v3xTADY4Khz0Nh1G6M4raEOqp k+Ql0IBv35gin20dETZbJCWkEXSBvcb550rV X-Google-Smtp-Source: AMsMyM6AwLH2we/yc52emy0rfs2HaeaF7Ez4C6G0vAiGbIwwCkr/FO+2kfG4IdbnG/wibk7QO7EVCw== X-Received: by 2002:adf:e804:0:b0:236:657e:756e with SMTP id o4-20020adfe804000000b00236657e756emr2477099wrm.452.1667051599892; Sat, 29 Oct 2022 06:53:19 -0700 (PDT) Received: from tpp.orcam.me.uk (tpp.orcam.me.uk. [2001:8b0:154:0:ea6a:64ff:fe24:f2fc]) by smtp.gmail.com with ESMTPSA id p1-20020a05600c358100b003c6237e867esm2053030wmq.0.2022.10.29.06.53.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Oct 2022 06:53:19 -0700 (PDT) Date: Sat, 29 Oct 2022 14:53:18 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org Subject: [PATCH v7 1/4] GDB/Python: Use None for `var_zuinteger_unlimited' value set to `unlimited' In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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: , Cc: Simon Sobisch , Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Consistently with parameters of the PARAM_UINTEGER and PARAM_INTEGER types, return the special value of `None' for a PARAM_ZUINTEGER_UNLIMITED parameter set to `unlimited', fixing an inconsistency introduced with commit 0489430a0e1a ("Handle var_zuinteger and var_zuinteger_unlimited from Python"); cf. PR python/20084. Adjust the testsuite accordingly. This makes all the three parameter types consistent with each other as far as the use of `None' is concerned, and similar to the Guile/Scheme interface where the `#:unlimited' keyword is likewise used. We have a precedent already documented for a similar API correction: -- Function: gdb.breakpoints () Return a sequence holding all of GDB's breakpoints. *Note Breakpoints In Python::, for more information. In GDB version 7.11 and earlier, this function returned 'None' if there were no breakpoints. This peculiarity was subsequently fixed, and now 'gdb.breakpoints' returns an empty sequence in this case. made in the past. And then we have documentation not matching the interface as far as the value of `None' already returned for parameters of the PARAM_UINTEGER and PARAM_INTEGER types is concerned, and the case of an incorrect assertion for PARAM_UINTEGER and PARAM_ZUINTEGER_UNLIMITED parameters in the sibling Guile/Scheme module making such parameters unusable that has never been reported, both indicating that these features may indeed not be heavily used, and therefore that the risk from such an API change is likely lower than the long-term burden of the inconsistency. And where the value read from a parameter is only used for presentation purposes, then such a change is expected to be transparent. --- Changes from v6: - Add a comma in the first sentence of the change description. Changes from v5: - Refer to Python parameter types in the change description rather than underlying GDB variable types in preparation for breaking the tight coupling between the two later in this series. - Document existing and updated semantics in the GDB manual. - Update the testsuite adjustment to fit in the now expanded test case. - Add a NEWS entry. No change from v4. New change in v4. --- gdb/NEWS | 7 +++++++ gdb/doc/python.texi | 30 +++++++++++++++++++----------- gdb/python/python.c | 10 +++++++++- gdb/testsuite/gdb.python/py-parameter.exp | 16 +++++----------- 4 files changed, 40 insertions(+), 23 deletions(-) gdb-python-var-zuinteger-unlimited-none.diff Index: src/gdb/NEWS =================================================================== --- src.orig/gdb/NEWS +++ src/gdb/NEWS @@ -216,6 +216,13 @@ GNU/Linux/CSKY (gdbserver) csky*-*linux* must start with a character in the set [a-zA-Z], every subsequent character of a window's name must be in the set [-_.a-zA-Z0-9]. + ** Parameters of gdb.PARAM_ZUINTEGER_UNLIMITED type now return the + value of None for the 'unlimited' setting, consistently with + parameters of gdb.PARAM_UINTEGER and gdb.PARAM_INTEGER types. + Parameters of all the three types now accept the value of None + to mean 'unlimited'. The use of internal integer representation + for the 'unlimited' setting is now deprecated. + * New features in the GDB remote stub, GDBserver ** GDBserver is now supported on LoongArch GNU/Linux. Index: src/gdb/doc/python.texi =================================================================== --- src.orig/gdb/doc/python.texi +++ src/gdb/doc/python.texi @@ -4598,14 +4598,16 @@ Python, true and false are represented u @findex PARAM_UINTEGER @findex gdb.PARAM_UINTEGER @item gdb.PARAM_UINTEGER -The value is an unsigned integer. The value of 0 should be -interpreted to mean ``unlimited''. +The value is an unsigned integer. The value of @code{None} should be +interpreted to mean ``unlimited'', and the value of 0 is reserved and +should not be used. @findex PARAM_INTEGER @findex gdb.PARAM_INTEGER @item gdb.PARAM_INTEGER -The value is a signed integer. The value of 0 should be interpreted -to mean ``unlimited''. +The value is a signed integer. The value of @code{None} should be +interpreted to mean ``unlimited'', and the value of 0 is reserved and +should not be used. @findex PARAM_STRING @findex gdb.PARAM_STRING @@ -4635,21 +4637,27 @@ The value is a filename. This is just l @findex PARAM_ZINTEGER @findex gdb.PARAM_ZINTEGER @item gdb.PARAM_ZINTEGER -The value is an integer. This is like @code{PARAM_INTEGER}, except 0 -is interpreted as itself. +The value is a signed integer. This is like @code{PARAM_INTEGER}, +except that 0 is allowed and the value of @code{None} is not supported. @findex PARAM_ZUINTEGER @findex gdb.PARAM_ZUINTEGER @item gdb.PARAM_ZUINTEGER -The value is an unsigned integer. This is like @code{PARAM_INTEGER}, -except 0 is interpreted as itself, and the value cannot be negative. +The value is an unsigned integer. This is like @code{PARAM_UINTEGER}, +except that 0 is allowed and the value of @code{None} is not supported. @findex PARAM_ZUINTEGER_UNLIMITED @findex gdb.PARAM_ZUINTEGER_UNLIMITED @item gdb.PARAM_ZUINTEGER_UNLIMITED -The value is a signed integer. This is like @code{PARAM_ZUINTEGER}, -except the special value -1 should be interpreted to mean -``unlimited''. Other negative values are not allowed. +The value is a signed integer. This is like @code{PARAM_INTEGER} +including that the value of @code{None} should be interpreted to mean +``unlimited'', except that 0 is allowed, and the value cannot be negative. + +In GDB version 12 and earlier, a parameter of this type when read would +return -1 rather than @code{None} for the setting of ``unlimited''. +This peculiarity was subsequently fixed, for consistency with parameters +of @code{PARAM_UINTEGER} and @code{PARAM_INTEGER} types, so that all the +three types return the value of @code{None} for ``unlimited''. @findex PARAM_ENUM @findex gdb.PARAM_ENUM Index: src/gdb/python/python.c =================================================================== --- src.orig/gdb/python/python.c +++ src/gdb/python/python.c @@ -509,9 +509,17 @@ gdbpy_parameter_value (const setting &va Py_RETURN_NONE; /* Fall through. */ case var_zinteger: - case var_zuinteger_unlimited: return gdb_py_object_from_longest (var.get ()).release (); + case var_zuinteger_unlimited: + { + int val = var.get (); + + if (val == -1) + Py_RETURN_NONE; + return gdb_py_object_from_longest (val).release (); + } + case var_uinteger: { unsigned int val = var.get (); Index: src/gdb/testsuite/gdb.python/py-parameter.exp =================================================================== --- src.orig/gdb/testsuite/gdb.python/py-parameter.exp +++ src/gdb/testsuite/gdb.python/py-parameter.exp @@ -346,22 +346,16 @@ proc_with_prefix test_gdb_parameter { } "listsize" { set param_get_zero None set param_get_minus_one -1 - set param_get_none None - set param_get_unlimited None set param_set_minus_one "" } "print elements" { set param_get_zero None set param_get_minus_one None - set param_get_none None - set param_get_unlimited None set param_set_minus_one $param_range_error } "max-completions" { set param_get_zero 0 - set param_get_minus_one -1 - set param_get_none -1 - set param_get_unlimited -1 + set param_get_minus_one None set param_set_minus_one "" } default { @@ -392,13 +386,13 @@ proc_with_prefix test_gdb_parameter { } "test set to None" gdb_test "python print(gdb.parameter('$param'))" \ - $param_get_none "test value of None" + None "test value of None" gdb_test_no_output "python gdb.set_parameter('$param', 'unlimited')" \ "test set to 'unlimited'" gdb_test "python print(gdb.parameter('$param'))" \ - $param_get_unlimited "test value of 'unlimited'" + None "test value of 'unlimited'" } clean_restart @@ -468,9 +462,9 @@ proc_with_prefix test_integer_parameter } PARAM_ZUINTEGER_UNLIMITED { set param_get_zero 0 - set param_get_minus_one -1 + set param_get_minus_one None set param_get_minus_five 1 - set param_get_none -1 + set param_get_none None set param_set_minus_one "" set param_set_minus_five $param_range_error set param_set_none ""