This is the mail archive of the archer@sourceware.org mailing list for the Archer 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]

[python] Add gdb.Value.is_optimized_out attribute.


Hi,

I'm pushing this patch to the Python branch. It adds an attribute to
gdb.Value which helps Alexandre Oliva implement a solution to the
question he posted to the gdb mailing list.
-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center


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/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 382f0c1..7c01732 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18390,6 +18390,15 @@ bar = some_val['foo']
 
 Again, @code{bar} will also be a @code{gdb.Value} object.
 
+The following attribute is provided:
+
+@table @code
+@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
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 2507fcd..5d4f596 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.  */
+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,
@@ -913,6 +925,13 @@ gdbpy_initialize_values (void)
 
 
 
+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." },
   { "cast", valpy_cast, METH_VARARGS, "Cast the value to the supplied type." },
@@ -987,7 +1006,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/gdb.python/python-value.exp b/gdb/testsuite/gdb.python/python-value.exp
index 4abbfbd..8a5c8d8 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" 
 }
 
 proc test_value_after_death {} {



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