From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5392 invoked by alias); 10 Mar 2009 18:45:47 -0000 Received: (qmail 5383 invoked by uid 22791); 10 Mar 2009 18:45:47 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from e24smtp02.br.ibm.com (HELO e24smtp02.br.ibm.com) (32.104.18.86) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Mar 2009 18:45:38 +0000 Received: from d24relay01.br.ibm.com (d24relay01.br.ibm.com [9.8.31.16]) by e24smtp02.br.ibm.com (8.13.1/8.13.1) with ESMTP id n2AIwEN0008852 for ; Tue, 10 Mar 2009 15:58:14 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46]) by d24relay01.br.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n2AJiv2Z3809420 for ; Tue, 10 Mar 2009 16:44:57 -0300 Received: from d24av01.br.ibm.com (loopback [127.0.0.1]) by d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n2AIjYEj001868 for ; Tue, 10 Mar 2009 15:45:34 -0300 Received: from [9.18.198.63] ([9.18.198.63]) by d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n2AIjYA9001843; Tue, 10 Mar 2009 15:45:34 -0300 Subject: Re: any expression to tell whether a variable was optimized out? From: Thiago Jung Bauermann To: Alexandre Oliva Cc: Daniel Jacobowitz , gdb@sourceware.org In-Reply-To: References: <20090310125945.GA4376@caradoc.them.org> <1236700079.11106.1.camel@localhost.localdomain> Content-Type: text/plain; charset=utf-8 Date: Tue, 10 Mar 2009 18:45:00 -0000 Message-Id: <1236710732.11106.30.camel@localhost.localdomain> Mime-Version: 1.0 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: 2009-03/txt/msg00081.txt.bz2 El mar, 10-03-2009 a las 13:44 -0300, Alexandre Oliva escribió: > On Mar 10, 2009, Thiago Jung Bauermann wrote: > > It would be easy enough to add a method to the gdb.Value Python class > > exposing this boolean. Would it help you? > > Maybe. I was hoping for something already widely deployed, but > failing that, I guess it's ok to rely on future features ;-) > > As for whether it would help, I can only assume it would, but I'm not > quite up to speed on how to use such Python interfaces. If the feature > can be exercised from the GDB textual interactive interface, as part of > normal expression evaluation, it will indeed help. Otherwise, I may > have to look into it further to tell whether it will help. Not everything you would need is committed upstream yet, but it's very close. With the convenience function patch here: http://sourceware.org/ml/gdb-patches/2009-03/msg00066.html Plus the frame api patch here: http://sourceware.org/ml/gdb-patches/2009-03/msg00143.html Plus the patch at the end of this message, you can create the following convenience function: import gdb class IsOptimizedOut (gdb.Function): def __init__ (self): super (IsOptimizedOut, self).__init__ ("is_optimized_out") def invoke (self, value): return value.is_optimized_out () IsOptimizedOut () Then you can use it in an expression in the GDB command line: (gdb) print $is_optimized_out ($some_var) $1 = 1 You can also do the above by checking out the archer-tromey-python branch, and applying the patch below. I didn't commit this yet because I don't know if it would be better to have is_optimized_out function as a method or attribute of gdb.Value... -- []'s Thiago Jung Bauermann IBM Linux Technology Center diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c index 2507fcd..debd136 100644 --- a/gdb/python/python-value.c +++ b/gdb/python/python-value.c @@ -312,6 +312,18 @@ valpy_str (PyObject *self) return result; } +/* Implements gdb.Value.is_optimized_out () -> Boolean. */ +static PyObject * +valpy_is_optimized_out (PyObject *self, PyObject *args) +{ + struct value *value = ((value_object *) self)->value; + + if (value_optimized_out (value)) + Py_RETURN_TRUE; + + Py_RETURN_FALSE; +} + enum valpy_opcode { VALPY_ADD, @@ -921,6 +933,9 @@ static PyMethodDef value_object_methods[] = { { "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS, "string ([encoding] [, errors]) -> string\n\ Return Unicode string representation of the value." }, + { "is_optimized_out", valpy_is_optimized_out, METH_NOARGS, + "is_optimized_out () -> Boolean\n\ +Whether this value is optimized out." }, {NULL} /* Sentinel */ };