From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24590 invoked by alias); 31 Mar 2010 10:07:24 -0000 Received: (qmail 24580 invoked by uid 22791); 31 Mar 2010 10:07:23 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 31 Mar 2010 10:07:12 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2VA7Aci010887 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 31 Mar 2010 06:07:10 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2VA79gE008616; Wed, 31 Mar 2010 06:07:09 -0400 Message-ID: <4BB31ECC.10104@redhat.com> Date: Wed, 31 Mar 2010 10:07:00 -0000 From: Phil Muldoon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.8) Gecko/20100301 Fedora/3.0.3-1.fc12 Lightning/1.0b2pre Thunderbird/3.0.3 MIME-Version: 1.0 To: tromey@redhat.com CC: gdb-patches ml Subject: Re: [patch] PR 11417 References: <4BB20EC0.10500@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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 X-SW-Source: 2010-03/txt/msg01109.txt.bz2 On 03/30/2010 07:05 PM, Tom Tromey wrote: >>>>>> "Phil" == Phil Muldoon writes: > > Phil> - if (address == 0) > Phil> - { > Phil> - PyErr_SetString (PyExc_MemoryError, > Phil> - "Cannot create a lazy string from a GDB-side string."); > Phil> - return NULL; > Phil> - } > > I agree that we should change lazy_string to be like string here. > However, I think we should only allow a NULL lazy_string with length==0. > Other situations don't really make sense. > > This also needs a test case. Ok, makes sense. Here is an updated patch. Cheers, Phil -- 2010-03-31 Phil Muldoon PR python/11417 * python/py-lazy-string.c (stpy_convert_to_value): Check for a NULL address. (gdbpy_create_lazy_string_object): Allow strings with a NULL address and a zero length. 2010-03-31 Phil Muldoon * gdb.python/py-value: Add null string variable. (test_lazy_string): Test zero length, NULL address lazy strings. -- diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c index 8309527..a2faa0e 100644 --- a/gdb/python/py-lazy-string.c +++ b/gdb/python/py-lazy-string.c @@ -94,6 +94,13 @@ stpy_convert_to_value (PyObject *self, PyObject *args) lazy_string_object *self_string = (lazy_string_object *) self; struct value *val; + if (self_string->address == 0) + { + PyErr_SetString (PyExc_MemoryError, + "Cannot create a value from NULL"); + return NULL; + } + val = value_at_lazy (self_string->type, self_string->address); return value_to_value_object (val); } @@ -111,10 +118,11 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length, { lazy_string_object *str_obj = NULL; - if (address == 0) + if (address == 0 && length != 0) { PyErr_SetString (PyExc_MemoryError, - "Cannot create a lazy string from a GDB-side string."); + _("Cannot create a lazy string with address 0x0, " \ + "and a non-zero length.")); return NULL; } diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c index 80bc1e9..be933b3 100644 --- a/gdb/testsuite/gdb.python/py-value.c +++ b/gdb/testsuite/gdb.python/py-value.c @@ -59,7 +59,7 @@ main (int argc, char *argv[]) int *p = a; int i = 2; int *ptr_i = &i; - + const char *sn = 0; s.a = 3; s.b = 5; u.a = 7; diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 2b18e02..3bfa173 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -267,6 +267,12 @@ proc test_lazy_strings {} { gdb_py_test_silent_cmd "python lstr = sptr.lazy_string()" "Aquire lazy string" 1 gdb_test "python print lstr.type" "const char \*." "Test type name equality" gdb_test "python print sptr.type" "const char \*." "Test type name equality" + gdb_test "print sn" "0x0" + gdb_py_test_silent_cmd "python snptr = gdb.history (0)" "Get value from history" 1 + gdb_test "python snstr = snptr.lazy_string(length=5)" ".*Cannot create a lazy string with address.*" "Test lazy string" + gdb_py_test_silent_cmd "python snstr = snptr.lazy_string(length=0)" "Succesfully create a lazy string" 1 + gdb_test "python print snstr.length" "0" "Test lazy string length" + gdb_test "python print snstr.address" "0" "Test lazy string address" }