From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: Alexandre Oliva <aoliva@redhat.com>
Cc: Daniel Jacobowitz <drow@false.org>, gdb@sourceware.org
Subject: Re: any expression to tell whether a variable was optimized out?
Date: Tue, 10 Mar 2009 18:45:00 -0000 [thread overview]
Message-ID: <1236710732.11106.30.camel@localhost.localdomain> (raw)
In-Reply-To: <orzlftfhu1.fsf@oliva.athome.lsd.ic.unicamp.br>
El mar, 10-03-2009 a las 13:44 -0300, Alexandre Oliva escribió:
> On Mar 10, 2009, Thiago Jung Bauermann <bauerman@br.ibm.com> wrote:
> > It would be easy enough to add a method to the gdb.Value Python class
> > exposing this boolean. Would it help you?
>
> Maybe. I was hoping for something already widely deployed, but
> failing that, I guess it's ok to rely on future features ;-)
>
> As for whether it would help, I can only assume it would, but I'm not
> quite up to speed on how to use such Python interfaces. If the feature
> can be exercised from the GDB textual interactive interface, as part of
> normal expression evaluation, it will indeed help. Otherwise, I may
> have to look into it further to tell whether it will help.
Not everything you would need is committed upstream yet, but it's very
close. With the convenience function patch here:
http://sourceware.org/ml/gdb-patches/2009-03/msg00066.html
Plus the frame api patch here:
http://sourceware.org/ml/gdb-patches/2009-03/msg00143.html
Plus the patch at the end of this message, you can create the following
convenience function:
import gdb
class IsOptimizedOut (gdb.Function):
def __init__ (self):
super (IsOptimizedOut, self).__init__ ("is_optimized_out")
def invoke (self, value):
return value.is_optimized_out ()
IsOptimizedOut ()
Then you can use it in an expression in the GDB command line:
(gdb) print $is_optimized_out ($some_var)
$1 = 1
You can also do the above by checking out the archer-tromey-python
branch, and applying the patch below. I didn't commit this yet because I
don't know if it would be better to have is_optimized_out function as a
method or attribute of gdb.Value...
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 2507fcd..debd136 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 () -> Boolean. */
+static PyObject *
+valpy_is_optimized_out (PyObject *self, PyObject *args)
+{
+ struct value *value = ((value_object *) self)->value;
+
+ if (value_optimized_out (value))
+ Py_RETURN_TRUE;
+
+ Py_RETURN_FALSE;
+}
+
enum valpy_opcode
{
VALPY_ADD,
@@ -921,6 +933,9 @@ static PyMethodDef value_object_methods[] = {
{ "string", (PyCFunction) valpy_string, METH_VARARGS | METH_KEYWORDS,
"string ([encoding] [, errors]) -> string\n\
Return Unicode string representation of the value." },
+ { "is_optimized_out", valpy_is_optimized_out, METH_NOARGS,
+ "is_optimized_out () -> Boolean\n\
+Whether this value is optimized out." },
{NULL} /* Sentinel */
};
next prev parent reply other threads:[~2009-03-10 18:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-10 9:48 Alexandre Oliva
2009-03-10 12:59 ` Daniel Jacobowitz
2009-03-10 15:48 ` Thiago Jung Bauermann
2009-03-10 16:45 ` Alexandre Oliva
2009-03-10 18:45 ` Thiago Jung Bauermann [this message]
2009-03-10 18:48 ` Thiago Jung Bauermann
2009-03-17 21:07 ` 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=1236710732.11106.30.camel@localhost.localdomain \
--to=bauerman@br.ibm.com \
--cc=aoliva@redhat.com \
--cc=drow@false.org \
--cc=gdb@sourceware.org \
/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