RFC: Python gdb.Type method returning optimized out gdb.Value

Message ID CAHQ51u5OUcPBm3D7GokB-U3hsfpzHTj+DDAWGiw35nh-AkyY1w@mail.gmail.com
State New, archived
Headers

Commit Message

Alexander Smundak April 3, 2015, 8:33 p.m. UTC
  Provide the ability for a a Python frame decorator to indicate that
a value is not available.

doc/ChangeLog:

2015-04-03  Sasha Smundak  <asmundak@google.com>

    * python.texi:New method documented.

gdb/ChangeLog:

2015-04-03  Sasha Smundak  <asmundak@google.com>

   * python/py-type.c (typy_create_optimized_out): New function.

testsuite/ChangeLog:

2015-04-03  Sasha Smundak  <asmundak@google.com>

   * gdb.python/py-type.exp: New test.

     test_fields "c"
  

Comments

Doug Evans April 7, 2015, 5:44 p.m. UTC | #1
Alexander Smundak writes:
 > Provide the ability for a a Python frame decorator to indicate that
 > a value is not available.
 > 
 > doc/ChangeLog:
 > 
 > 2015-04-03  Sasha Smundak  <asmundak@google.com>
 > 
 >     * python.texi:New method documented.
 > 
 > gdb/ChangeLog:
 > 
 > 2015-04-03  Sasha Smundak  <asmundak@google.com>
 > 
 >    * python/py-type.c (typy_create_optimized_out): New function.
 > 
 > testsuite/ChangeLog:
 > 
 > 2015-04-03  Sasha Smundak  <asmundak@google.com>
 > 
 >    * gdb.python/py-type.exp: New test.

Hi.
A few of nits.

The terms "unavailable" and "optimized out" have different meanings
in gdb.  See their definitions at the top of value.h.
Also see the comments for struct value.{unavailable,optimized_out}
in value.c.  I don't know if python frame decorators would want to specify
a value as being unavailable (in gdb parlance), but don't use "unavailable"
in the documentation of "optimized out".

The "create_" in "create_optimized_out" is incongruous with the
rest of gdb.Type methods.  E.g., we have "array" not "create_array",
"vector" not "create_vector", "const" not "create_const", and so on.
Does "optimized_out" read well to you?

A NEWS entry is needed.

 > 
 > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
 > index 098d718..7c2d0bc 100644
 > --- a/gdb/doc/python.texi
 > +++ b/gdb/doc/python.texi
 > @@ -1060,6 +1060,11 @@ If @var{block} is given, then @var{name} is
 > looked up in that scope.
 >  Otherwise, it is searched for globally.
 >  @end defun
 > 
 > +@defun Type.create_optimized_out ()
 > +Return @code{gdb.Value} instance of this type whose value is optimized
 > +out.  Allows a frame decorator to indicate that an argument or local
 > +variable value is unavailable.
 > +@end defun
 > 
 >  Each type has a code, which indicates what category this type falls
 >  into.  The available type categories are represented by constants
 > diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
 > index 39376a1..186cc19 100644
 > --- a/gdb/python/py-type.c
 > +++ b/gdb/python/py-type.c
 > @@ -1181,6 +1181,14 @@ typy_nonzero (PyObject *self)
 >    return 1;
 >  }
 > 
 > +/* Return optimized out value of this type.  */

blank line

 > +static PyObject *
 > +typy_create_optimized_out (PyObject *self, PyObject *args)
 > +{
 > +  struct type *type = ((type_object *) self)->type;
 > +  return value_to_value_object (allocate_optimized_out_value (type));
 > +}
 > +
 >  /* Return a gdb.Field object for the field named by the argument.  */
 > 
 >  static PyObject *
 > @@ -1493,6 +1501,8 @@ They are first class values." },
 >    { "const", typy_const, METH_NOARGS,
 >      "const () -> Type\n\
 >  Return a const variant of this type." },
 > +  { "create_optimized_out", typy_create_optimized_out, METH_NOARGS,
 > +"create_optimized_out() -> Value\nReturn optimized out value of this type." },
 >    { "fields", typy_fields, METH_NOARGS,
 >      "fields () -> list\n\
 >  Return a list holding all the fields of this type.\n\
 > diff --git a/gdb/testsuite/gdb.python/py-type.exp
 > b/gdb/testsuite/gdb.python/py-type.exp
 > index c4c8d9f..c73f831 100644
 > --- a/gdb/testsuite/gdb.python/py-type.exp
 > +++ b/gdb/testsuite/gdb.python/py-type.exp
 > @@ -253,6 +253,9 @@ gdb_test "python print
 > gdb.lookup_type('char').array(1, 0)" \
 >  gdb_test "python print gdb.lookup_type('char').array(1, -1)" \
 >      "Array length must not be negative.*"
 > 
 > +gdb_test "python print gdb.lookup_type('int').create_optimized_out()" \
 > +    "<optimized out>"
 > +
 >  with_test_prefix "lang_c" {
 >      runto_bp "break to inspect struct and array."
 >      test_fields "c"
  

Patch

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 098d718..7c2d0bc 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -1060,6 +1060,11 @@  If @var{block} is given, then @var{name} is
looked up in that scope.
 Otherwise, it is searched for globally.
 @end defun

+@defun Type.create_optimized_out ()
+Return @code{gdb.Value} instance of this type whose value is optimized
+out.  Allows a frame decorator to indicate that an argument or local
+variable value is unavailable.
+@end defun

 Each type has a code, which indicates what category this type falls
 into.  The available type categories are represented by constants
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 39376a1..186cc19 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1181,6 +1181,14 @@  typy_nonzero (PyObject *self)
   return 1;
 }

+/* Return optimized out value of this type.  */
+static PyObject *
+typy_create_optimized_out (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  return value_to_value_object (allocate_optimized_out_value (type));
+}
+
 /* Return a gdb.Field object for the field named by the argument.  */

 static PyObject *
@@ -1493,6 +1501,8 @@  They are first class values." },
   { "const", typy_const, METH_NOARGS,
     "const () -> Type\n\
 Return a const variant of this type." },
+  { "create_optimized_out", typy_create_optimized_out, METH_NOARGS,
+"create_optimized_out() -> Value\nReturn optimized out value of this type." },
   { "fields", typy_fields, METH_NOARGS,
     "fields () -> list\n\
 Return a list holding all the fields of this type.\n\
diff --git a/gdb/testsuite/gdb.python/py-type.exp
b/gdb/testsuite/gdb.python/py-type.exp
index c4c8d9f..c73f831 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -253,6 +253,9 @@  gdb_test "python print
gdb.lookup_type('char').array(1, 0)" \
 gdb_test "python print gdb.lookup_type('char').array(1, -1)" \
     "Array length must not be negative.*"

+gdb_test "python print gdb.lookup_type('int').create_optimized_out()" \
+    "<optimized out>"
+
 with_test_prefix "lang_c" {
     runto_bp "break to inspect struct and array."