public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* [Pretty printers] Can the name or type of a child value change?
@ 2010-08-13  6:41 Elmenthaler, Jens
  2010-08-16 20:53 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Elmenthaler, Jens @ 2010-08-13  6:41 UTC (permalink / raw)
  To: gdb

Consider the following code example:

  struct JAny {
    union {
      char *text;
      int number;
    } val;

    // 1 -> text, 2 -> number
    int type;
  };

And the following pretty printer:
class AnyPrinter:
    class _iterator:
        def __init__ (self, name, value):
            self.count = 0
            self.name = name
            self.value = value

        def __iter__(self):
            return self

        def next(self):
            if self.count != 0:
                raise StopIteration
            
            self.count = self.count + 1
            return (self.name, self.value)    

    def __init__(self, val):
        self.type = val['type']
        
        if self.type == 1:
            self.value = val['val']['text']
            self.name = "text"
            
        if self.type == 2:
            self.value = val['val']['number']
            self.name = "number"
            
    def children(self):
        return self._iterator(self.name, self.value)

    def to_string(self):
        return "JAny"

When stepping in the debugger over a line that changes JAny.type, the name and the type of the child value returned by the pretty printer change.

Are the MI variable objects meant to handle this?

Greetings, Jens.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Pretty printers] Can the name or type of a child value change?
  2010-08-13  6:41 [Pretty printers] Can the name or type of a child value change? Elmenthaler, Jens
@ 2010-08-16 20:53 ` Tom Tromey
  2012-03-28  8:03   ` Elmenthaler, Jens
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2010-08-16 20:53 UTC (permalink / raw)
  To: Elmenthaler, Jens; +Cc: gdb

>>>>> "Jens" == Elmenthaler, Jens <jens.elmenthaler@verigy.com> writes:

Jens> Consider the following code example:
[...]

Jens> When stepping in the debugger over a line that changes JAny.type,
Jens> the name and the type of the child value returned by the pretty
Jens> printer change.

Jens> Are the MI variable objects meant to handle this?

Yes.  The MI consumer is expected to understand that dynamic varobjs are
dynamic: the number and names of children can change in arbitrary ways.
This is incompatible with previous expectations, which is why consumers
have to explicitly request this feature from gdb.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [Pretty printers] Can the name or type of a child value change?
  2010-08-16 20:53 ` Tom Tromey
@ 2012-03-28  8:03   ` Elmenthaler, Jens
  0 siblings, 0 replies; 3+ messages in thread
From: Elmenthaler, Jens @ 2012-03-28  8:03 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb

This actual is a return to a discussion that goes back to 1 1/2 years ago. The question was whether a pretty printer can change the name and type of the returned children when stepping. Tom's answer (see bottom this email) was yes.

I'm now using this feature, but stumble over a very basic question: if the name of a child changes, how does the MI variable object return this fact in -var-update? I don't see a tuple telling the frontend that this happened. It seems it should be the "exp" field that is returned by -var-list-children, but neither documentation nor gdb's code seems to consider it for -var-update.

Greetings, Jens.

p.s For references, here the original example:

Consider the following code example: 

  struct JAny { 
    union { 
      char *text; 
      int number; 
    } val; 

    // 1 -> text, 2 -> number 
    int type; 
  }; 

And the following pretty printer: 
class AnyPrinter: 
    class _iterator: 
        def __init__ (self, name, value): 
            self.count = 0 
            self.name = name 
            self.value = value 

        def __iter__(self): 
            return self 

        def next(self): 
            if self.count != 0: 
                raise StopIteration 
            
            self.count = self.count + 1 
            return (self.name, self.value)     

    def __init__(self, val): 
        self.type = val['type'] 
        
        if self.type == 1: 
            self.value = val['val']['text'] 
            self.name = "text" 
            
        if self.type == 2: 
            self.value = val['val']['number'] 
            self.name = "number" 
            
    def children(self): 
        return self._iterator(self.name, self.value) 

    def to_string(self): 
        return "JAny" 

When stepping in the debugger over a line that changes JAny.type, the name and the type of the child value returned by the pretty printer change. 

Are the MI variable objects meant to handle this? 


-----Original Message-----
From: Tom Tromey [mailto:tromey@redhat.com] 
Sent: Monday, August 16, 2010 10:54 PM
To: Elmenthaler, Jens
Cc: gdb@sourceware.org
Subject: Re: [Pretty printers] Can the name or type of a child value change?

>>>>> "Jens" == Elmenthaler, Jens <jens.elmenthaler@verigy.com> writes:

Jens> Consider the following code example:
[...]

Jens> When stepping in the debugger over a line that changes JAny.type, 
Jens> the name and the type of the child value returned by the pretty 
Jens> printer change.

Jens> Are the MI variable objects meant to handle this?

Yes.  The MI consumer is expected to understand that dynamic varobjs are
dynamic: the number and names of children can change in arbitrary ways.
This is incompatible with previous expectations, which is why consumers have to explicitly request this feature from gdb.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-03-28  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-13  6:41 [Pretty printers] Can the name or type of a child value change? Elmenthaler, Jens
2010-08-16 20:53 ` Tom Tromey
2012-03-28  8:03   ` Elmenthaler, Jens

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).