* any expression to tell whether a variable was optimized out? @ 2009-03-10 9:48 Alexandre Oliva 2009-03-10 12:59 ` Daniel Jacobowitz 0 siblings, 1 reply; 7+ messages in thread From: Alexandre Oliva @ 2009-03-10 9:48 UTC (permalink / raw) To: gdb Hi, I'm working on a debug info quality testsuite for GCC, and I've been having some trouble telling, in gdb macros, a variable for which no location expression is available at a certain point in the program (but for which we do have locations at other points), from one that evaluates to zero (lifetime constant, or stored in register or memory). Consider: (gdb) p x $1 = <value optimized out> (gdb) p y $2 = 0 (gdb) p x == y 1 (gdb) p &x Can't take address of "x" which isn't an lvalue. (gdb) p &y Address requested for identifier "y" which is in register $r12 (gdb) set $temp1 = x (gdb) set $temp2 = y (gdb) set z = $temp1 == $temp2 (gdb) p z 1 (gdb) set $temp1 = x + 1 (gdb) set $temp2 = y + 1 (gdb) set z = $temp1 == $temp2 (gdb) p z 1 Is there really no way to set a gdb variable to something equivalent to the boolean result of valprint.c:value_optimized_out()? Any reason for that, other than that nobody needed it before? Thanks in advance, -- Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/ You must be the change you wish to see in the world. -- Gandhi Be Free! -- http://FSFLA.org/ FSF Latin America board member Free Software Evangelist Red Hat Brazil Compiler Engineer ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: any expression to tell whether a variable was optimized out? 2009-03-10 9:48 any expression to tell whether a variable was optimized out? Alexandre Oliva @ 2009-03-10 12:59 ` Daniel Jacobowitz 2009-03-10 15:48 ` Thiago Jung Bauermann 0 siblings, 1 reply; 7+ messages in thread From: Daniel Jacobowitz @ 2009-03-10 12:59 UTC (permalink / raw) To: gdb On Tue, Mar 10, 2009 at 06:48:28AM -0300, Alexandre Oliva wrote: > Is there really no way to set a gdb variable to something equivalent to > the boolean result of valprint.c:value_optimized_out()? Any reason for > that, other than that nobody needed it before? Nope, there's no way to do it. Really, unavailable ought to propogate through the expression evaluator, and give errors at some points, I expect... -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: any expression to tell whether a variable was optimized out? 2009-03-10 12:59 ` Daniel Jacobowitz @ 2009-03-10 15:48 ` Thiago Jung Bauermann 2009-03-10 16:45 ` Alexandre Oliva 0 siblings, 1 reply; 7+ messages in thread From: Thiago Jung Bauermann @ 2009-03-10 15:48 UTC (permalink / raw) To: Daniel Jacobowitz; +Cc: gdb, Alexandre Oliva El mar, 10-03-2009 a las 08:59 -0400, Daniel Jacobowitz escribió: > On Tue, Mar 10, 2009 at 06:48:28AM -0300, Alexandre Oliva wrote: > > Is there really no way to set a gdb variable to something equivalent to > > the boolean result of valprint.c:value_optimized_out()? Any reason for > > that, other than that nobody needed it before? > > Nope, there's no way to do it. Really, unavailable ought to propogate > through the expression evaluator, and give errors at some points, I > expect... It would be easy enough to add a method to the gdb.Value Python class exposing this boolean. Would it help you? -- []'s Thiago Jung Bauermann IBM Linux Technology Center ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: any expression to tell whether a variable was optimized out? 2009-03-10 15:48 ` Thiago Jung Bauermann @ 2009-03-10 16:45 ` Alexandre Oliva 2009-03-10 18:45 ` Thiago Jung Bauermann 0 siblings, 1 reply; 7+ messages in thread From: Alexandre Oliva @ 2009-03-10 16:45 UTC (permalink / raw) To: Thiago Jung Bauermann; +Cc: Daniel Jacobowitz, gdb On Mar 10, 2009, Thiago Jung Bauermann <bauerman@br.ibm.com> wrote: > El mar, 10-03-2009 a las 08:59 -0400, Daniel Jacobowitz escribió: >> On Tue, Mar 10, 2009 at 06:48:28AM -0300, Alexandre Oliva wrote: >> > Is there really no way to set a gdb variable to something equivalent to >> > the boolean result of valprint.c:value_optimized_out()? Any reason for >> > that, other than that nobody needed it before? >> >> Nope, there's no way to do it. Really, unavailable ought to propogate >> through the expression evaluator, and give errors at some points, I >> expect... > 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. Thanks, -- Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/ You must be the change you wish to see in the world. -- Gandhi Be Free! -- http://FSFLA.org/ FSF Latin America board member Free Software Evangelist Red Hat Brazil Compiler Engineer ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: any expression to tell whether a variable was optimized out? 2009-03-10 16:45 ` Alexandre Oliva @ 2009-03-10 18:45 ` Thiago Jung Bauermann 2009-03-10 18:48 ` Thiago Jung Bauermann 2009-03-17 21:07 ` Tom Tromey 0 siblings, 2 replies; 7+ messages in thread From: Thiago Jung Bauermann @ 2009-03-10 18:45 UTC (permalink / raw) To: Alexandre Oliva; +Cc: Daniel Jacobowitz, gdb El mar, 10-03-2009 a las 13:44 -0300, Alexandre Oliva escribió: > On Mar 10, 2009, Thiago Jung Bauermann <bauerman@br.ibm.com> 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 */ }; ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: any expression to tell whether a variable was optimized out? 2009-03-10 18:45 ` Thiago Jung Bauermann @ 2009-03-10 18:48 ` Thiago Jung Bauermann 2009-03-17 21:07 ` Tom Tromey 1 sibling, 0 replies; 7+ messages in thread From: Thiago Jung Bauermann @ 2009-03-10 18:48 UTC (permalink / raw) To: Alexandre Oliva; +Cc: Daniel Jacobowitz, gdb El mar, 10-03-2009 a las 15:45 -0300, Thiago Jung Bauermann escribió: > Plus the frame api patch here: > > http://sourceware.org/ml/gdb-patches/2009-03/msg00143.html > Sorry, you don't need this one. -- []'s Thiago Jung Bauermann IBM Linux Technology Center ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: any expression to tell whether a variable was optimized out? 2009-03-10 18:45 ` Thiago Jung Bauermann 2009-03-10 18:48 ` Thiago Jung Bauermann @ 2009-03-17 21:07 ` Tom Tromey 1 sibling, 0 replies; 7+ messages in thread From: Tom Tromey @ 2009-03-17 21:07 UTC (permalink / raw) To: Thiago Jung Bauermann; +Cc: Alexandre Oliva, Daniel Jacobowitz, gdb >>>>> "Thiago" == Thiago Jung Bauermann <bauerman@br.ibm.com> writes: Thiago> You can also do the above by checking out the archer-tromey-python Thiago> branch, and applying the patch below. I didn't commit this yet because I Thiago> don't know if it would be better to have is_optimized_out function as a Thiago> method or attribute of gdb.Value... I think attribute, because (AFAIK) it is immutable. I'm a little surprised that this is an attribute of values at all. Doesn't that seem weird? Is there anything useful that can be done with a value like this? Perhaps just fetching its type? Tom ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-03-17 21:07 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-03-10 9:48 any expression to tell whether a variable was optimized out? Alexandre Oliva 2009-03-10 12:59 ` Daniel Jacobowitz 2009-03-10 15:48 ` Thiago Jung Bauermann 2009-03-10 16:45 ` Alexandre Oliva 2009-03-10 18:45 ` Thiago Jung Bauermann 2009-03-10 18:48 ` Thiago Jung Bauermann 2009-03-17 21:07 ` Tom Tromey
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox