From patchwork Tue Apr 7 21:23:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Smundak X-Patchwork-Id: 6078 Received: (qmail 46678 invoked by alias); 7 Apr 2015 21:23:50 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 46665 invoked by uid 89); 7 Apr 2015 21:23:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ig0-f172.google.com Received: from mail-ig0-f172.google.com (HELO mail-ig0-f172.google.com) (209.85.213.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 07 Apr 2015 21:23:47 +0000 Received: by igbqf9 with SMTP id qf9so23391273igb.1 for ; Tue, 07 Apr 2015 14:23:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=EYegwD72PfgFW//H2VUjJaVovKuJUQ7GkAMeftBmquU=; b=WZ5KFMHxw92cPY2NLczt0ek7Fu3MVobYv60RITVxq6nw+k0COGKXYOTLZ7DrimkXq7 1+kMmhf964C4RkgGzKGOM2q/a/CSVaK7BWk9LEN0QNqBtHI40ve3S+9NM0YIznQZWMf9 B+UyilAAw4r9zk9fdgGl59+iN/jWAP2FLxMiOQ5Cxw0BEhCp2ncopoK5Kc3rYd38xLTC +PMQ9nG7FDoLTTwbfdOj81gfYVusuABniwvnb+wEO/x6m95Kuiu6rjgIdnNyOb1ioPnv bap+XG49igAO47k/BgUIbw8g2YoWPTQqc7TiVNd4WMQzCiaSH7spIoi4tsNPoq8b8TKM 8w2Q== X-Gm-Message-State: ALoCoQnX7Ze4u4Ii+22XpARDVhOFz/ec492RoU1cxdvQ+cyo79/ncFnLITgeFMCc9iK1zqY0AAs5 MIME-Version: 1.0 X-Received: by 10.50.143.42 with SMTP id sb10mr6892805igb.49.1428441824892; Tue, 07 Apr 2015 14:23:44 -0700 (PDT) Received: by 10.64.27.6 with HTTP; Tue, 7 Apr 2015 14:23:44 -0700 (PDT) In-Reply-To: <21796.6013.264282.101943@ruffy2.mtv.corp.google.com> References: <21796.6013.264282.101943@ruffy2.mtv.corp.google.com> Date: Tue, 7 Apr 2015 14:23:44 -0700 Message-ID: Subject: Re: RFC: Python gdb.Type method returning optimized out gdb.Value From: Alexander Smundak To: Doug Evans Cc: gdb-patches 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 * python.texi: New method documented. gdb/ChangeLog: 2015-04-07 Sasha Smundak * NEWS: Mention gdb.Type.optimized_out method. * python/py-type.c (typy_optimized_out): New function. gdb/testsuite/ChangeLog: 2015-04-07 Sasha Smundak * gdb.python/py-type.exp: New test. test_fields "c" On Tue, Apr 7, 2015 at 10:44 AM, Doug Evans wrote: > 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 > > > > * python.texi:New method documented. > > > > gdb/ChangeLog: > > > > 2015-04-03 Sasha Smundak > > > > * python/py-type.c (typy_create_optimized_out): New function. > > > > testsuite/ChangeLog: > > > > 2015-04-03 Sasha Smundak > > > > * 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()" \ > > + "" > > + > > with_test_prefix "lang_c" { > > runto_bp "break to inspect struct and array." > > test_fields "c" > > -- > /dje 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; + 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()" \ + "" + with_test_prefix "lang_c" { runto_bp "break to inspect struct and array."