Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: Vladimir Prus <vladimir@codesourcery.com>
Cc: gdb@sources.redhat.com
Subject: Re: Robustifying pretty-printers
Date: Mon, 15 Jun 2009 12:28:00 -0000	[thread overview]
Message-ID: <4A363E6F.6020005@redhat.com> (raw)
In-Reply-To: <200906131421.24719.vladimir@codesourcery.com>


> 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


  reply	other threads:[~2009-06-15 12:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-13 10:11 Vladimir Prus
2009-06-13 10:21 ` Vladimir Prus
2009-06-15 12:28   ` Phil Muldoon [this message]
2009-06-15 12:39     ` Vladimir Prus
2009-06-15 12:55       ` Daniel Jacobowitz
2009-06-15 13:25         ` Vladimir Prus
2009-06-16  7:22           ` André Pönitz
2009-06-15 20:01 ` Tom Tromey
2009-06-16  8:22   ` Vladimir Prus
2009-07-07 21:48     ` Tom Tromey
2009-07-09 17:20       ` Vladimir Prus
2009-07-09 19:14         ` Tom Tromey
2009-07-10  6:13           ` Vladimir Prus
2009-07-10 16:25             ` Tom Tromey
2009-07-10 16:40               ` Vladimir Prus
2009-07-10 16:48                 ` Tom Tromey
2009-07-10 18:46                   ` Vladimir Prus
2009-07-10 18:52                     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A363E6F.6020005@redhat.com \
    --to=pmuldoon@redhat.com \
    --cc=gdb@sources.redhat.com \
    --cc=vladimir@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox