From patchwork Wed Mar 30 06:57:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 11557 Received: (qmail 116773 invoked by alias); 30 Mar 2016 06:57:24 -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 116760 invoked by uid 89); 30 Mar 2016 06:57:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1970, H*r:209.85.220 X-HELO: mail-pa0-f74.google.com Received: from mail-pa0-f74.google.com (HELO mail-pa0-f74.google.com) (209.85.220.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 30 Mar 2016 06:57:21 +0000 Received: by mail-pa0-f74.google.com with SMTP id q6so1709985pav.1 for ; Tue, 29 Mar 2016 23:57:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to; bh=B35ShElxyoDHhfq5Pfv+xd5jwO3TBp9xyr7jSgqxgtM=; b=jWkVU393axpFytGNkTVGVCTarb6IVHv9Jky17uJDySvkstiKlGfVNXLO+IHCwHJijr sea1FqnAHEmh1/tj2ZpQ+1++dpeELMcHObSBO0/6WvCVEifhR3lhxTbmgYffPGaCX+oR 3/JGJGlM6MrO4kvzHy7T+oPccMrqB0iBsbxrn2uj5d8r8fhsCC5qE2Y5AfGbkdBGqva0 Rx9bLUV0bbKFKH+UI0pNOJi0oOPGUYGQCIj8ptyVbLfZfYqfstWNwtZwx83v/GjYZtGA wn6UYy/Cc5NDJkYO1Hy8mv6+kyBnQfV0+T5cTF62Q7YhsZEO1utSXKg2u/LZWHW/SbuY mY0A== X-Gm-Message-State: AD7BkJKUwpgHVP3w+RzonE2UOwOGQMaujMbZ+NpN8VEPb3poYa+Jdga3N9iuRoTcvPLYLHs9thWtrUGrD+muVwaSm6GO38SA3dN2aWJM77ulzeeyl0zQG/CrRATximsYRq62u/cv5vRegr0L1LehNyD5H2lBq3Mf1MHLcecymCar1xrlgCALrQ== MIME-Version: 1.0 X-Received: by 10.98.12.66 with SMTP id u63mr3843111pfi.12.1459321039839; Tue, 29 Mar 2016 23:57:19 -0700 (PDT) Message-ID: <001a114592c831ba11052f3ea8b0@google.com> Date: Wed, 30 Mar 2016 06:57:19 +0000 Subject: [PATCH] Fix gdb.Value->python conversion for large unsigned ints From: Doug Evans To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi. I was seeing this in gdb: (gdb) py print long(gdb.Value(18446744071563607160)) -2145944456 whereas with plain python: (gdb) py print long(18446744071563607160) 18446744071563607160 2016-03-29 Doug Evans * python/py-value.c (valpy_long): Handle unsigned values. testsuite/ * gdb.python/py-value.exp (test_value_creation): Add test for large unsigned 64-bit value. gdb_test "python print (a.__class__)" "<(type| class) 'gdb.Value'>" "verify type of 8-bit string" + if { $gdb_py_is_py3k == 0 } { gdb_py_test_silent_cmd "python a = gdb.Value (u'unicode test')" "create unicode value" 1 gdb_test "python print (a)" "\"unicode test\"" "print Unicode string" diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 7dba0ad..09e8055 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1518,7 +1518,10 @@ valpy_long (PyObject *self) } END_CATCH - return gdb_py_long_from_longest (l); + if (TYPE_UNSIGNED (type)) + return gdb_py_long_from_ulongest (l); + else + return gdb_py_long_from_longest (l); } /* Implements conversion to float. */ diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index a9dbe97..ca2dc08 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -54,10 +54,15 @@ proc test_value_creation {} { if { $gdb_py_is_py3k == 0 } { gdb_py_test_silent_cmd "python i = gdb.Value (5L)" "create long value" 1 } + + gdb_py_test_silent_cmd "python l = gdb.Value(0xffffffff12345678)" "create large unsigned 64-bit value" 1 + gdb_test "python print long(l)" "18446744069720004216" "large unsigned 64-bit int conversion to python" + gdb_py_test_silent_cmd "python f = gdb.Value (1.25)" "create double value" 1 gdb_py_test_silent_cmd "python a = gdb.Value ('string test')" "create 8-bit string value" 1 gdb_test "python print (a)" "\"string test\"" "print 8-bit string"