From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1160 invoked by alias); 29 Jun 2009 00:47:44 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 1149 invoked by uid 22791); 29 Jun 2009 00:47:43 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_43,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Roland McGrath To: Project Archer Subject: inferior calls from python? Message-Id: <20090629004733.B4729420F6@magilla.sf.frob.com> Date: Mon, 29 Jun 2009 00:47:00 -0000 X-SW-Source: 2009-q2/txt/msg00196.txt.bz2 I wanted to try hacking a pretty-printer that uses an inferior call. (I know well the reasons why that is a bad way for them to be. This is a quick hack to reduce typing in my current debugging scenario, not a fancy set of pretty-printers to publish.) The basic idea is I am writing a pretty printer for type T1 where printing "x" of type T1 would do like: printf "T1 id %#x\n", x.id() but rather than just use "define p_T1" that does this, I want to do it in python so that std::list prints elements this way, etc. So in a pretty-printer, I have a gdb.Value object. I don't see how to do this with it. Two possible approaches occur to me for this. One is to have a python method to make the inferior call as a fine-grained operation. Then it would do: def to_string(self): return 'T1 id ' + self.val['id'].call(self.val).to_string () In the general case, 'call' would take a variable number of gdb.Value arguments to pass the inferior (or perhaps allow literal numbers and strings too), and return a gdb.Value of the inferior call's return value. (Here I assume that ['id'] yields a gdb.Value of "pointer to member function" type with no remaining internal pointer to self.val, so call() has to be given the implicit "this" argument explicitly. Perhaps C++ method calls would be handled some other way that is more convenient to use, but equivalent to this.) The other method is to punt an arbitrary amount of work like the field selection and inferior calls to the expression parser. Then it would do: def to_string(self): return 'T1 id ' + parse_and_eval('$a1.id()', self.val).to_string () In the general case, parse_and_eval takes a variable number of gdb.Value arguments that are each bound to a different $something that the expression can refer to. (Perhaps pass one $name->gdb.Value dictionary instead of variable arguments.) Am I missing an existing way this can be done? (I'm using gdb-6.8.50.20090302-27.fc11.x86_64.) Thanks, Roland