From patchwork Sat Sep 15 07:24:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29389 Received: (qmail 29855 invoked by alias); 15 Sep 2018 07:25:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 29465 invoked by uid 89); 15 Sep 2018 07:25:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1, 2, 3 X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.233) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Sep 2018 07:25:05 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 8FD286D67 for ; Sat, 15 Sep 2018 02:25:03 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 14wxgQW9zbXuJ14wxgj23w; Sat, 15 Sep 2018 02:25:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=K+Bkpor1zHMELEPe2i8IT/954ENbkWNbA6x5/wQQiDI=; b=UOUksD9ixHfXGy215YAtCvJMkM LseV/HELWtHUyXQH9vzftqGSWXMOEZujLG27dOuvWRtWghoTMeVkxs914yc6Ymj5Q0lazXseGC+y1 JqX0Ihu3VtypxqWGRxbtSRVMR; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:41846 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g14wx-00253W-CN; Sat, 15 Sep 2018 02:25:03 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/7] Preserve sign when converting gdb.Value to Python int Date: Sat, 15 Sep 2018 01:24:54 -0600 Message-Id: <20180915072459.14934-3-tom@tromey.com> In-Reply-To: <20180915072459.14934-1-tom@tromey.com> References: <20180915072459.14934-1-tom@tromey.com> PR python/20126 points out that sometimes the conversion of a gdb.Value can result in a negative Python integer. This happens because valpy_int does not examine the signedness of the value's type. gdb/ChangeLog 2018-09-14 Tom Tromey PR python/20126: * python/py-value.c (valpy_int): Respect type sign. gdb/testsuite/ChangeLog 2018-09-14 Tom Tromey PR python/20126: * gdb.python/py-value.exp (test_value_numeric_ops): Add signed-ness conversion tests. --- gdb/ChangeLog | 5 +++++ gdb/python/py-value.c | 5 ++++- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-value.exp | 5 +++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 9abcf9212e6..5c6792f85fc 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1514,7 +1514,10 @@ valpy_int (PyObject *self) } END_CATCH - return gdb_py_object_from_longest (l); + if (TYPE_UNSIGNED (type)) + return gdb_py_object_from_ulongest (l); + else + return gdb_py_object_from_longest (l); } #endif diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 9e8fa15c28e..aed50d1c8cf 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -140,6 +140,11 @@ proc test_value_numeric_ops {} { gdb_test "python print ('result = ' + str(\[1,2,3\]\[gdb.Value(0)\]))" \ "result = 1" "use value as array index" + gdb_test "python print('%x' % int(gdb.parse_and_eval('-1ull')))" \ + "f+" "int conversion respect type sign" + gdb_test "python print('%x' % long(gdb.parse_and_eval('-1ull')))" \ + "f+" "long conversion respect type sign" + # Test some invalid operations. gdb_test_multiple "python print ('result = ' + str(i+'foo'))" "catch error in python type conversion" {