Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: tromey@redhat.com, aoliva@redhat.com, gdb-patches@sourceware.org
Subject: Re: [RFC][Python] Re: any expression to tell whether a variable 	was	optimized out?
Date: Thu, 26 Mar 2009 21:21:00 -0000	[thread overview]
Message-ID: <1238101576.25721.80.camel@localhost.localdomain> (raw)
In-Reply-To: <uljqwooil.fsf@gnu.org>

El lun, 23-03-2009 a las 06:24 +0200, Eli Zaretskii escribió:
> > From: Thiago Jung Bauermann <bauerman@br.ibm.com>
> > Cc: Alexandre Oliva <aoliva@redhat.com>, gdb-patches@sourceware.org
> > Date: Sun, 22 Mar 2009 22:31:02 -0300
> > 
> > +@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
> 
> This is OK, but please add a @cindex entry for this that starts with
> "optimized", so that readers will be able to find this easier.

Here's the @cindex entry I added:

+@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

I committed the following patch. Thanks for the review.
-- 
[]'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.

Index: src/gdb/python/python-value.c
===================================================================
--- src.orig/gdb/python/python-value.c	2009-03-21 00:06:27.000000000 -0300
+++ src/gdb/python/python-value.c	2009-03-26 17:48:45.000000000 -0300
@@ -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 */
Index: src/gdb/testsuite/gdb.python/python-value.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.python/python-value.exp	2009-02-04 19:49:10.000000000 -0200
+++ src/gdb/testsuite/gdb.python/python-value.exp	2009-03-26 17:48:45.000000000 -0300
@@ -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"
 }
 
 
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo	2009-03-25 17:54:17.000000000 -0300
+++ src/gdb/doc/gdb.texinfo	2009-03-26 17:49:33.000000000 -0300
@@ -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
 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



  reply	other threads:[~2009-03-26 21:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <orskllhfo3.fsf@oliva.athome.lsd.ic.unicamp.br>
     [not found] ` <20090310125945.GA4376@caradoc.them.org>
     [not found]   ` <1236700079.11106.1.camel@localhost.localdomain>
     [not found]     ` <orzlftfhu1.fsf@oliva.athome.lsd.ic.unicamp.br>
     [not found]       ` <1236710732.11106.30.camel@localhost.localdomain>
     [not found]         ` <m3hc1rluz1.fsf@fleche.redhat.com>
2009-03-23  2:09           ` Thiago Jung Bauermann
2009-03-23  4:24             ` Eli Zaretskii
2009-03-26 21:21               ` Thiago Jung Bauermann [this message]
2009-03-23 17:47             ` Tom Tromey
2009-03-28 21:38               ` [RFA][Python] Change gdb.Value.address from a method to an attribute Thiago Jung Bauermann
2009-03-29  4:21                 ` Eli Zaretskii
2009-03-29 18:12                   ` Tom Tromey
2009-03-29 18:56                     ` Eli Zaretskii
2009-03-29 21:22                       ` Thiago Jung Bauermann
2009-03-29 15:42                 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1238101576.25721.80.camel@localhost.localdomain \
    --to=bauerman@br.ibm.com \
    --cc=aoliva@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox