From: Thiago Jung Bauermann Date: Thu, 26 Mar 2009 20:58:11 +0000 (+0000) Subject: gdb/ X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=def2b0009c101b13fad1105c2c10424b35b3117b;p=binutils-gdb.git gdb/ Add gdb.Value.is_optimized_out attribute. * python/python-value.c (valpy_get_is_optimized_out): New function. (value_object_getset): New variable. (value_object_type): Initialize tp_getset element. gdb/doc/ * gdb.texinfo (Values From Inferior): Document is_optimized_out attribute. gdb/testsuite/ * gdb.python/python-value.exp (test_value_in_inferior): Test gdb.Value.is_optimized_out attribute. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fd87425469b..055cc9697a9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2009-03-26 Thiago Jung Bauermann + + Add gdb.Value.is_optimized_out attribute. + * python/python-value.c (valpy_get_is_optimized_out): New + function. + (value_object_getset): New variable. + (value_object_type): Initialize tp_getset element. + 2009-03-26 Joel Brobecker Recognize missing DW_AT_location as . diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 2c4b291a5b3..beca8460823 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2009-03-26 Thiago Jung Bauermann + + * gdb.texinfo (Values From Inferior): Document is_optimized_out + attribute. + 2009-03-25 Pedro Alves * observer.texi (thread_exit): Add "silent" parameter. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 134919d7236..8db567964f2 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18325,13 +18325,23 @@ bar = some_val['foo'] Again, @code{bar} will also be a @code{gdb.Value} object. -For pointer data types, @code{gdb.Value} provides a method for -dereferencing the pointer to obtain the object it points to. +The following attribute is provided: +@table @code +@cindex optimized out value in Python +@defmethod Value is_optimized_out +This read-only boolean attribute is true if the compiler optimized out +this value, thus it is not available for fetching from the inferior. +@end defmethod +@end table + +The following methods are provided: + +@table @code @defmethod Value dereference -This method returns a new @code{gdb.Value} object whose contents is -the object pointed to by the pointer. For example, if @code{foo} is -a C pointer to an @code{int}, declared in your C program as +For pointer data types, this method returns a new @code{gdb.Value} object +whose contents is the object pointed to by the pointer. For example, if +@code{foo} is a C pointer to an @code{int}, declared in your C program as @smallexample int *foo; @@ -18375,6 +18385,7 @@ will be used, if the current language is able to supply one. The optional @var{errors} argument is the same as the corresponding argument to Python's @code{string.decode} method. @end defmethod +@end table @node Commands In Python @subsubsection Commands In Python diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c index cbc481fa982..bf07dc43d19 100644 --- a/gdb/python/python-value.c +++ b/gdb/python/python-value.c @@ -272,6 +272,18 @@ valpy_str (PyObject *self) return result; } +/* Implements gdb.Value.is_optimized_out. */ +static PyObject * +valpy_get_is_optimized_out (PyObject *self, void *closure) +{ + struct value *value = ((value_object *) self)->value; + + if (value_optimized_out (value)) + Py_RETURN_TRUE; + + Py_RETURN_FALSE; +} + enum valpy_opcode { VALPY_ADD, @@ -825,6 +837,13 @@ gdbpy_initialize_values (void) values_in_python = NULL; } +static PyGetSetDef value_object_getset[] = { + { "is_optimized_out", valpy_get_is_optimized_out, NULL, + "Boolean telling whether the value is optimized out (i.e., not available).", + NULL }, + {NULL} /* Sentinel */ +}; + static PyMethodDef value_object_methods[] = { { "address", valpy_address, METH_NOARGS, "Return the address of the value." }, { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." }, @@ -897,7 +916,7 @@ PyTypeObject value_object_type = { 0, /* tp_iternext */ value_object_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + value_object_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 7f68b9212db..599ba76fd71 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-03-26 Thiago Jung Bauermann + + * gdb.python/python-value.exp (test_value_in_inferior): Test + gdb.Value.is_optimized_out attribute. + 2009-03-26 Jan Kratochvil * gdb.dwarf2/dw2-noloc-main.c: New file. diff --git a/gdb/testsuite/gdb.python/python-value.exp b/gdb/testsuite/gdb.python/python-value.exp index 8f5e0ab53fd..2d1ece6cec7 100644 --- a/gdb/testsuite/gdb.python/python-value.exp +++ b/gdb/testsuite/gdb.python/python-value.exp @@ -225,6 +225,9 @@ proc test_value_in_inferior {} { # Check that the dereferenced value is sane gdb_test "python print arg0" "0x.*$testfile\"" "verify dereferenced value" + + # Smoke-test is_optimized_out attribute + gdb_test "python print 'result =', arg0.is_optimized_out" "= False" "Test is_optimized_out attribute" }