From: Andrew Oakley <andrew@ado.is-a-geek.net>
To: gdb@sourceware.org
Subject: Python API - pretty printing complex types
Date: Wed, 09 Mar 2011 00:43:00 -0000 [thread overview]
Message-ID: <20110309004619.7256b052@ado-gentoo> (raw)
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
next reply other threads:[~2011-03-09 0:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-09 0:43 Andrew Oakley [this message]
2011-03-09 8:06 ` Joachim Protze
2011-03-10 21:08 ` Tom Tromey
[not found] ` <201103090954.49355.andre.poenitz@nokia.com>
2011-03-09 19:28 ` Andrew Oakley
2011-03-10 9:07 ` André Pönitz
2011-03-10 21:25 ` Tom Tromey
2011-03-11 7:41 ` Joachim Protze
2011-03-11 11:25 ` André Pönitz
2011-03-10 21:11 ` Tom Tromey
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=20110309004619.7256b052@ado-gentoo \
--to=andrew@ado.is-a-geek.net \
--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