From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2900 invoked by alias); 15 Jun 2009 12:28:51 -0000 Received: (qmail 2885 invoked by uid 22791); 15 Jun 2009 12:28:51 -0000 X-SWARE-Spam-Status: No, hits=-0.7 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_36,J_CHICKENPOX_43,J_CHICKENPOX_44,J_CHICKENPOX_46,J_CHICKENPOX_48,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 15 Jun 2009 12:28:37 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n5FCSX7U016552 for ; Mon, 15 Jun 2009 08:28:33 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5FCSXIu030502 for ; Mon, 15 Jun 2009 08:28:33 -0400 Received: from localhost.localdomain (vpn-6-43.fab.redhat.com [10.33.6.43]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5FCSWWD014447; Mon, 15 Jun 2009 08:28:32 -0400 Message-ID: <4A363E6F.6020005@redhat.com> Date: Mon, 15 Jun 2009 12:28:00 -0000 From: Phil Muldoon User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: Vladimir Prus CC: gdb@sources.redhat.com Subject: Re: Robustifying pretty-printers References: <200906131411.34204.vladimir@codesourcery.com> <200906131421.24719.vladimir@codesourcery.com> In-Reply-To: <200906131421.24719.vladimir@codesourcery.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-06/txt/msg00140.txt.bz2 > In fact, there's yet another case: > > class StdStringPrinter: > "Print a std::basic_string of some kind" > > def __init__(self, encoding, val): > self.encoding = encoding > self.val = val > > def to_string(self): > # Look up the target encoding as late as possible. > encoding = self.encoding > if encoding == 0: > encoding = gdb.parameter('target-charset') > elif encoding == 1: > encoding = gdb.parameter('target-wide-charset') > elif isinstance(encoding, WideEncoding): > encoding = encoding.value > return self.val['_M_dataplus']['_M_p'].string(encoding) > > I am not quite sure where the 'string' method is defined, so the > question is -- assuming I know the expected size of the string. > How do I make the 'string' method not to fetch more than that? > I'll answer a particular question in your email: counted string support should hopefully arrive soon. This comprises of two patches currently working through the review process over on the archer mailing list. The approved first part is here: http://sourceware.org/ml/archer/2009-q2/msg00017.html The second part is more to do with null character preservation and emission, but has some counted string dependencies. It is currently going through review here: http://sourceware.org/ml/archer/2009-q2/msg00111.html When these have been accepted there, I'll submit them to the gdb-patches for additional review, and then hopefully into GDB head pretty soon. In the std:string example, it would be modified to use counted strings like so: diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py index 2bd2593..6bf4f3b 100644 --- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py +++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py @@ -468,7 +468,17 @@ class StdStringPrinter: encoding = gdb.parameter('target-charset') elif isinstance(encoding, WideEncoding): encoding = encoding.value - return self.val['_M_dataplus']['_M_p'].string(encoding) + type = self.val.type + if type.code == gdb.TYPE_CODE_REF: + type = type.target () + + ptr = self.val ['_M_dataplus']['_M_p'] + realtype = type.unqualified ().strip_typedefs () + reptype = gdb.lookup_type (str (realtype) + '::_Rep').pointer () + header = ptr.cast(reptype) - 1 + len = header.dereference ()['_M_length'] + + return self.val['_M_dataplus']['_M_p'].string (encoding, length = len) But the optional string length parameter could be used in other examples, too. Regards Phil