This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Pretty printers] Can the name or type of a child value change?


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]