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]

Python API - pretty printing complex types


I'm having difficulty writing pretty printers for some more complex
types and was wondering if anybody had any suggestions.  I think an
example is the easiest way of describing my problem.

I've got some C code that looks something like the following:

struct value_type { ... };

struct container {
        int interesting_field1;
        int interesting_field2;

        size_t values_length1;
        struct value_type * values1;

        size_t values_length2;
        struct value_type * values2;
};

I have a pretty printer for 'struct value_type' already.  I want to
write a pretty printer for 'struct container.  This struct contains two
lists of 'struct value_type', however the fact that there are two
lists is an implementation detail that we rarely care about.

Ideally my pretty printer would output something like this:

container = {
  interesting_field1 = 42,
  interesting_field2 = 0,
  members = {
        { value1 },
        { value2 },
        { value3 }
  }
}

The displayhint for container is 'map' and has fields called
'interesting_field1', 'interesting_field2' and 'members'.  The value
for 'members' is something that has a displayhint of 'array'.

The problem is that I don't know how to get 'members' printed
correctly.  It looks like the children member of the pretty printer for
'struct container' must return (string, gdb.Value) tuples, but I don't
have a unique type to return that gdb can use to find the next
pretty printer.  

For the simpler case of only having a single list of value I considered
returning a value of type 'struct value_type[length]', however there
does not seem to be any way to construct this type or any way to get
the length of the array type if we did manage to construct it.  Perhaps
these are worth adding to the API as gdb does seem to handle these
types internally.

If API improvements are needed to do this I can have a go at writing
the code (the current src/gdb/python code seems fairly easy to
understand).

-- 
Andrew Oakley


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