From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 80509 invoked by alias); 5 Feb 2016 12:12:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 80496 invoked by uid 89); 5 Feb 2016 12:12:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=exc X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 05 Feb 2016 12:12:26 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id E7F34804E3; Fri, 5 Feb 2016 12:12:24 +0000 (UTC) Received: from [10.36.112.51] (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u15CCNjg022371; Fri, 5 Feb 2016 07:12:24 -0500 Subject: Re: [PATCH 2/7] py-value: properly handle unsigned and pointer types To: jeffm@suse.com, gdb-patches@sourceware.org References: <1454606973-31017-1-git-send-email-jeffm@suse.com> <1454606973-31017-3-git-send-email-jeffm@suse.com> From: Phil Muldoon Message-ID: <56B491A7.1050905@redhat.com> Date: Fri, 05 Feb 2016 12:12:00 -0000 MIME-Version: 1.0 In-Reply-To: <1454606973-31017-3-git-send-email-jeffm@suse.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-02/txt/msg00138.txt.bz2 On 04/02/16 17:29, jeffm@suse.com wrote: > From: Jeff Mahoney > > GDB passes signed long values into python whether they're signed or > not. This results in a situation where the caller needs to convert > it back to an unsigned value, which requires knowledge of the underlying > size of the value. The information to do that is available in the API, > but it's unnecessary. We know it's an unsigned value so pass it as > an unsigned value. > --- > gdb/python/py-value.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c > index 140aaf5..c557d95 100644 > --- a/gdb/python/py-value.c > +++ b/gdb/python/py-value.c > @@ -1475,6 +1475,7 @@ valpy_int (PyObject *self) > { > struct value *value = ((value_object *) self)->value; > struct type *type = value_type (value); > + int is_unsigned = 0; > LONGEST l >> >> jeff >> > = 0; > > TRY > @@ -1482,6 +1483,9 @@ valpy_int (PyObject *self) > if (!is_integral_type (type)) > error (_("Cannot convert value to int.")); > > + if (TYPE_CODE (type) == TYPE_CODE_PTR || > + TYPE_UNSIGNED(type)) Nit, space after the macro/function name and before (. > + is_unsigned = 1; > l = value_as_long (value); > } > CATCH (exc >> >> jeff >> > ept, RETURN_MASK_ALL) > @@ -1490,6 +1494,8 @@ valpy_int (PyObject *self) > } > END_CATCH > > + if (is_unsigned) > + return gdb_py_object_from_ulongest ((ULONGEST)l); > return gdb_py_object_from_longest (l); > } > #endif > @@ -1500,6 +1506,7 @@ valpy_long (PyObject *self) > { > struct value *value = ((value_object *) self)->value; > struct type *type = value_type (value); > + int is_unsigned = 0; > LONGEST l = 0; > > TRY > @@ -1510,6 +1517,9 @@ valpy_long (PyObject *self) > && TYPE_CODE (type) != TYPE_CODE_PTR) > error (_("Cannot convert value to long.")); > > + if (TYPE_CODE (type) == TYPE_CODE_PTR || > + TYPE_UNSIGNED(type)) Nit, space after the macro/function name and before (. > + is_unsigned = 1; > l = value_as_long (value); > } > CATCH (except, RETURN_MASK_ALL) > @@ -1518,6 +1528,8 @@ valpy_long (PyObject *self) > } > END_CATCH > > + if (is_unsigned) > + return gdb_py_long_from_ulongest ((ULONGEST)l); > return gdb_py_long_from_longest (l); > } > Thanks. This needs tests and documentation changes for the changes in functionality. Cheers Phil