public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Oliver Buchtala <oliver.buchtala@googlemail.com>
To: gdb@sourceware.org
Subject: Re: Inconsistency between results of pretty-printing children
Date: Fri, 20 Jul 2012 12:42:00 -0000	[thread overview]
Message-ID: <50095229.3030400@googlemail.com> (raw)
In-Reply-To: <50092D6B.3040103@googlemail.com>

On 20.07.2012 12:05, Oliver Buchtala wrote:
> Hi,
>
> I am facing a problem with the python API for implemenation of 
> Printer.children().
>
> In working examples the metod of a pretty printer looks like that:
>
>    def children():
>       return [("key", 1)]
>
> Usually one returns an iterable here.
>
> The point is, that it returns tuples with key and value.
> This works fine with existing IDEs using the MI interface (kdevelop, 
> eclipse cdt, nemiver).
>
> In the API documentation it is described, that this method should 
> return alternating keys and values.
> And that is exactly what is expected by gdb's print command when 
> printing pretty.
> To work with gdb's print method, I would adapt my printer to flatten 
> the whole list so that keys and values are iterated in an alternating 
> manner.
>
> This way it happens, that my pretty printer can not be used in IDEs 
> and with gdb's print simultanously.
> Am I doing something wrong?
>
> Regards,
> Oliver
>

I have created an iterator that would show the correct result in gdb's 
print for a children method return (key,value) tuples:

class AlternateKeyValueIterator():

   def __init__(self, iterable):
     self.it = iterable.__iter__()
     self._next = None

   def __iter__(self):
     return self

   def next(self):
     if self._next == None:
       key, value = self.it.next()
       self._next = value
       return ("", key)
     else:
       value = self._next
       self._next = None
       return ("", value)

It needs also to return tuples of (str, gdb.Value) but only the value is 
used for printing, where as this value must be set to key and value in 
an alternating manner.

Any hints?
Or is it a bug?

Regards,
Oliver

  reply	other threads:[~2012-07-20 12:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-20 10:05 Oliver Buchtala
2012-07-20 12:42 ` Oliver Buchtala [this message]
2012-07-20 19:49   ` Tom Tromey
2012-07-20 20:11     ` Oliver Buchtala
2012-07-20 19:48 ` Tom Tromey
     [not found]   ` <5009B73B.2030702@googlemail.com>
2012-07-20 20:14     ` Tom Tromey
2012-07-20 20:20       ` Oliver Buchtala
2012-07-20 20:36       ` Oliver Buchtala
2012-07-20 20:58         ` Oliver Buchtala
2012-07-20 21:20       ` Oliver Buchtala
2012-07-21  0:12       ` Oliver Buchtala

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=50095229.3030400@googlemail.com \
    --to=oliver.buchtala@googlemail.com \
    --cc=gdb@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).