From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2000 invoked by alias); 11 Jan 2010 15:40:19 -0000 Received: (qmail 1987 invoked by uid 22791); 11 Jan 2010 15:40:18 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS 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; Mon, 11 Jan 2010 15:40:09 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0BFe02F001790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 Jan 2010 10:40:00 -0500 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0BFdx07009211; Mon, 11 Jan 2010 10:39:59 -0500 Message-ID: <4B4B464F.1060405@redhat.com> Date: Mon, 11 Jan 2010 15:40:00 -0000 From: Phil Muldoon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20091209 Fedora/3.0-4.fc12 Lightning/1.0pre Thunderbird/3.0 MIME-Version: 1.0 To: Eli Zaretskii CC: gdb-patches@sourceware.org Subject: Re: [patch][python] Implement Python lazy strings (PR 10705) References: <4B4746A7.90309@redhat.com> <83vdfca7im.fsf@gnu.org> In-Reply-To: <83vdfca7im.fsf@gnu.org> 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-01/txt/msg00251.txt.bz2 On 01/08/2010 04:25 PM, Eli Zaretskii wrote: >> Date: Fri, 08 Jan 2010 14:52:23 +0000 >> From: Phil Muldoon >> >> This patch implements Python lazy strings, and also alters the Python >> pretty-printing process to handle them accordingly. > > Thanks. Thanks for the review. I've updated the patch in accordance with your requests. How does this look? For brevity this time I just included the patch against gdb.texinfo. Cheers, Phil -- Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.656 diff -u -r1.656 gdb.texinfo --- doc/gdb.texinfo 6 Jan 2010 20:31:28 -0000 1.656 +++ doc/gdb.texinfo 11 Jan 2010 15:34:10 -0000 @@ -19416,6 +19416,7 @@ * Functions In Python:: Writing new convenience functions. * Objfiles In Python:: Object files. * Frames In Python:: Acessing inferior stack frames from Python. +* Lazy Strings In Python:: Python representation of lazy strings. @end menu @node Basic Python @@ -19690,6 +19691,30 @@ If the optional @var{length} argument is given, the string will be fetched and converted to the given length. @end defmethod + +@defmethod Value lazy_string @r{[}encoding@r{]} @r{[}length@r{]} +If this @code{gdb.Value} represents a string, then this method +converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings +In Python}). Otherwise, this method will throw an exception. + +If the optional @var{encoding} argument is given, it must be a string +naming the encoding of the @code{gdb.LazyString}. Some examples are: +@samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the +@var{encoding} argument is an encoding that @value{GDBN} does +recognize, @value{GDBN} will raise an error. + +When a lazy string is printed, the @value{GDBN} encoding machinery is +used to convert the string during printing. If the optional +@var{encoding} argument is not provided, or is an empty string, +@value{GDBN} will automatically select the encoding most suitable for +the string type. For further information on encoding in @value{GDBN} +please see: @pxref{Character Sets}. + +If the optional @var{length} argument is given, the string will be +fetched and encoded to the length of characters specified. If +the @var{length} argument is not provided, the string will be fetched +and encoded until a null of appropriate width is found. +@end defmethod @end table @node Types In Python @@ -20627,6 +20652,60 @@ @end defmethod @end table +@node Lazy Strings In Python +@subsubsection Python representation of lazy strings. + +@cindex lazy strings in python +@tindex gdb.LazyString + +A @dfn{lazy string} is a string whose contents is not retrieved or +encoded until it is needed. + +A @code{gdb.LazyString} is represented in @value{GDBN} as an +@code{address} that points to a region of memory, an @code{encoding} +that will be used to encode that region of memory, and a @code{length} +to delimit the region of memory that represents the string. The +difference between a @code{gdb.LazyString} and a string wrapped within +a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated +differently by @value{GDBN} when printing. A @code{gdb.LazyString} is +retrieved and encoded during printing, while a @code{gdb.Value} +wrapping a string is immediately retrieved and encoded on creation. + +A @code{gdb.LazyString} object has the following functions: + +@defmethod LazyString value +Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value +will point to the string in memory, but will lose all the delayed +retrieval, encoding and handling that @value{GDBN} applies to a +@code{gdb.LazyString}. +@end defmethod + +@defivar LazyString address +This attribute holds the address of the string. This attribute is not +writable. +@end defivar + +@defivar LazyString length +This attribute holds the length of the string in characters. If the +length is -1, then the string will be fetched and encoded up to the +first null of appropriate width. This attribute is not writable. +@end defivar + +@defivar LazyString encoding +This attribute holds the encoding that will be applied to the string +when the string is printed by @value{GDBN}. If the encoding is not +set, or contains an empty string, then @value{GDBN} will select the +most appropriate encoding when the string is printed. This attribute +is not writable. +@end defivar + +@defivar LazyString type +This attribute holds the type that is represented by the lazy string's +type. For a lazy string this will always be a pointer type. To resolve this +to the lazy string's character type, use the type's @code{target} method. +@pxref{Types In Python}. This attribute is not writable. +@end defivar + @node Interpreters @chapter Command Interpreters @cindex command interpreters