GDB Python pretty-printer not indenting substructures

309 views Asked by At

I have implemented a GDB pretty-printer in Python for my custom type. It does print the values as I expect but it doesn't indent the substructures "correctly" when set print pretty is in effect.

E.g. given

typedef Type struct {
    int child1;
    struct {
      int grandchild1;
    } grand;
}

GDB itself, without my pretty-printer, displays this as

$4 = {
    child1 = 42,
    grand = {
        grandchild1 = 1
    }
}

However, with my pretty-printer it displays as

$5 = {
    child1 = 42,
    grand = {
    grandchild1 = 1
}
}

Forgetting to indent the data for the sub structure 'grand'.

My pretty-printer basically does this:

def __init__(self, val):
    self.val = val

def to_string(self):
    return None

def children(self):
    for field in self.val.type.fields():
       yeild field.name, str(self.val[field.name])

as described here: Make debugging easier with custom pretty-printers.

How come this difference?

1

There are 1 answers

0
Tom Tromey On

Based on what you've said, it sounds like a plain old bug. A full reproducer would be nice, though.