This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFC: Python gdb.Type method returning optimized out gdb.Value
- From: Doug Evans <dje at google dot com>
- To: Alexander Smundak <asmundak at google dot com>
- Cc: gdb-patches <gdb-patches at sourceware dot org>
- Date: Sun, 12 Apr 2015 09:47:57 -0700
- Subject: Re: RFC: Python gdb.Type method returning optimized out gdb.Value
- Authentication-results: sourceware.org; auth=none
- References: <CAHQ51u5OUcPBm3D7GokB-U3hsfpzHTj+DDAWGiw35nh-AkyY1w at mail dot gmail dot com> <21796 dot 6013 dot 264282 dot 101943 at ruffy2 dot mtv dot corp dot google dot com> <CAHQ51u5PUkcWPV0TfGG2EL9vuLhpbVjDnFUwXjhd76d2f-Gs0Q at mail dot gmail dot com>
On Tue, Apr 7, 2015 at 2:23 PM, Alexander Smundak <asmundak@google.com> wrote:
> Thank you for the quick review.
> Edited NEWS, renamed `create_optimized_out' to `optimized_out',
> elided 'unavailable' from description, added blank line.
> PTAL.
>
> gdb/doc/ChangeLog:
>
> 2015-04-07 Sasha Smundak <asmundak@google.com>
>
> * python.texi: New method documented.
>
> gdb/ChangeLog:
>
> 2015-04-07 Sasha Smundak <asmundak@google.com>
>
> * NEWS: Mention gdb.Type.optimized_out method.
> * python/py-type.c (typy_optimized_out): New function.
>
> gdb/testsuite/ChangeLog:
>
> 2015-04-07 Sasha Smundak <asmundak@google.com>
>
> * gdb.python/py-type.exp: New test.
LGTM with one nit below.
[no need to resubmit another patch]
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 884c381..ebb573a 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -37,6 +37,8 @@
> which is the name of the objfile as specified by the user,
> without, for example, resolving symlinks.
> ** You can now write frame unwinders in Python.
> + ** gdb.Type objects have a new method "optimized_out",
> + returning optimized out gdb.Value instance of this type.
>
> * New commands
>
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index 098d718..091521c6 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.optimized_out ()
> +Return @code{gdb.Value} instance of this type whose value is optimized
> +out. This allows a frame decorator to indicate that the value of an
> +argument or a local variable is not known.
> +@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..0461b26 100644
> --- a/gdb/python/py-type.c
> +++ b/gdb/python/py-type.c
> @@ -1181,6 +1181,15 @@ typy_nonzero (PyObject *self)
> return 1;
> }
>
> +/* Return optimized out value of this type. */
> +
> +static PyObject *
> +typy_optimized_out (PyObject *self, PyObject *args)
> +{
> + struct type *type = ((type_object *) self)->type;
Style rules require a blank line here.
Sorry for not catching this earlier.
> + 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 +1502,8 @@ They are first class values." },
> { "const", typy_const, METH_NOARGS,
> "const () -> Type\n\
> Return a const variant of this type." },
> + { "optimized_out", typy_optimized_out, METH_NOARGS,
> +"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..2edbfe3 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').optimized_out()" \
> + "<optimized out>"
> +
> with_test_prefix "lang_c" {
> runto_bp "break to inspect struct and array."
> test_fields "c"
>