This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: any expression to tell whether a variable was optimized out?


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 */
 };
 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]