From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24974 invoked by alias); 11 Mar 2011 07:41:40 -0000 Received: (qmail 24958 invoked by uid 22791); 11 Mar 2011 07:41:38 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from atlantis.wh2.tu-dresden.de (HELO atlantis.wh2.tu-dresden.de) (141.30.228.39) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Mar 2011 07:41:32 +0000 Received: from [141.30.223.201] (x0862b.wh5.tu-dresden.de [141.30.223.201]) by atlantis.wh2.tu-dresden.de (Postfix) with ESMTPSA id 3ED0F83D0A2 for ; Fri, 11 Mar 2011 08:41:30 +0100 (CET) Message-ID: <4D79D24F.4040107@wh2.tu-dresden.de> Date: Fri, 11 Mar 2011 07:41:00 -0000 From: Joachim Protze Reply-To: gdb@sourceware.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: gdb@sourceware.org Subject: Re: Python API - pretty printing complex types References: <20110309004619.7256b052@ado-gentoo> <201103090954.49355.andre.poenitz@nokia.com> <20110309193051.6c757cf5@ado-gentoo> <201103101007.21382.andre.poenitz@nokia.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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/msg00084.txt.bz2 On 10.03.2011 22:25, Tom Tromey wrote: > André> It would be perfect if the pretty-printers-can-return-pretty-printers > André> approach would also allow to (easily) feed the pretty printers with > André> per-value individual data. I found this pretty useful for "patchwork" > André> applications, that cannot easily use global settings for everything. > André> [In some cases you would like to do things like "display char * as > André> Latin1, but in some cases it's UTF-8, sometimes it's a \0-separated and > André> \0\0-terminated 'list' of strings, and sometimes really only a pointer > André> to a single char". Or you have some numerical data in an array that you'd > André> like to run through xplot as "pretty printer", but you don't want to > André> invoke that on every value of type std::vector. Things like that.] > > varobj lets you assign a printer to a specific varobj, but I'm not sure > if anything uses this, and it probably only makes sense if there is > prior coordination with the front end. > > Handling this via sub-pretty-printers for (e.g.) specific fields in > known structures seems reasonable. But I don't know a fully general way > to handle this, like if the user wants "print some_global_string" to > automatically know to use a different encoding. In my case, i can derive context knowledge for a pointer/array by the usage in source code. The structure behind the pointer is a quite irregular tree structure (alternating datatypes). While printing a node of the tree, i have knowledge where to find the children of the node, how do walk down the tree and how to display leafs. For the inner nodes and leafs i cannot derive this context knowledge direct from source code, since just the roots address is found there. Atm i just can return the address of the node in pretty-printers children function. But at the same time i call the childs pretty-printer with context knowledge and store the pp-object in a dict of (address, pretty-printer) and get them if my pp-lookup-function gets a request for one of the addresses in the dict. My preferred way would be, to return the pretty-printer for the child in the children()-method. Another nice feature would be a self defined Command, that acts like a pretty-printer namely returns (string,pp-object/value) and gdb manages formated output. This way you could define own commands to create various formats of output or to do non-standard typecasts. In my case the datatype is stored in a structure and i would like to do something like: myprint (datatypestructure)address The output would be the same as if my pretty-printer derives the connection of datatypestructure + address from sourcecode. - Joachim