From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5868 invoked by alias); 9 Mar 2011 00:43:39 -0000 Received: (qmail 5860 invoked by uid 22791); 9 Mar 2011 00:43:38 -0000 X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,BAYES_20,TVD_RCVD_IP X-Spam-Check-By: sourceware.org Received: from 186.162.232.72.static.reverse.ltdomains.com (HELO ado.is-a-geek.net) (72.232.162.186) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Mar 2011 00:43:31 +0000 Received: from moore.slainvet.net ([81.2.98.79] helo=ado-gentoo) by ado.is-a-geek.net with esmtpa (Exim 4.72) (envelope-from ) id 1Px8OA-0005h1-Ou for gdb@sourceware.org; Wed, 09 Mar 2011 01:40:35 +0000 Date: Wed, 09 Mar 2011 00:43:00 -0000 From: Andrew Oakley To: gdb@sourceware.org Subject: Python API - pretty printing complex types Message-ID: <20110309004619.7256b052@ado-gentoo> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-03/txt/msg00060.txt.bz2 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