diff options
author | Tom Tromey <tromey@redhat.com> | 2012-02-07 19:47:16 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2012-02-07 19:47:16 +0000 |
commit | f0823d2ce8e4cb8b64176872a372d8147804fb10 (patch) | |
tree | fb7552f824929309c2b65a6b54b656e90066885a /gdb/python | |
parent | 64e7d9dddc00228cdbcecdd4c053cf83cf6608b7 (diff) | |
download | gdb-f0823d2ce8e4cb8b64176872a372d8147804fb10.zip gdb-f0823d2ce8e4cb8b64176872a372d8147804fb10.tar.gz gdb-f0823d2ce8e4cb8b64176872a372d8147804fb10.tar.bz2 |
PR python/12027:
* python/python-internal.h (frame_object_type): Declare.
* python/py-symbol.c (sympy_needs_frame): New function.
(sympy_value): New function.
(symbol_object_getset): Add "needs_frame".
(symbol_object_methods): Add "value".
* python/py-frame.c (frame_object_type): No longer static.
gdb/doc
* gdb.texinfo (Symbols In Python): Document Symbol.needs_frame and
Symbol.value.
gdb/testsuite
* gdb.python/py-symbol.exp: Test Symbol.needs_frame and
Symbol.value.
* gdb.python/py-symbol.c (qq): Set default value.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-frame.c | 4 | ||||
-rw-r--r-- | gdb/python/py-symbol.c | 75 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 1 |
3 files changed, 77 insertions, 3 deletions
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 12cedc3..12a54e8 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -54,8 +54,6 @@ typedef struct { error (_("Frame is invalid.")); \ } while (0) -static PyTypeObject frame_object_type; - /* Returns the frame_info object corresponding to the given Python Frame object. If the frame doesn't exist anymore (the frame id doesn't correspond to any frame in the inferior), returns NULL. */ @@ -663,7 +661,7 @@ Return the value of the variable in this frame." }, {NULL} /* Sentinel */ }; -static PyTypeObject frame_object_type = { +PyTypeObject frame_object_type = { PyObject_HEAD_INIT (NULL) 0, /* ob_size */ "gdb.Frame", /* tp_name */ diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index d44014c..1c00b48 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -183,6 +183,29 @@ sympy_is_variable (PyObject *self, void *closure) || class == LOC_OPTIMIZED_OUT)); } +/* Implementation of gdb.Symbol.needs_frame -> Boolean. + Returns true iff the symbol needs a frame for evaluation. */ + +static PyObject * +sympy_needs_frame (PyObject *self, void *closure) +{ + struct symbol *symbol = NULL; + volatile struct gdb_exception except; + int result = 0; + + SYMPY_REQUIRE_VALID (self, symbol); + + TRY_CATCH (except, RETURN_MASK_ALL) + { + result = symbol_read_needs_frame (symbol); + } + GDB_PY_HANDLE_EXCEPTION (except); + + if (result) + Py_RETURN_TRUE; + Py_RETURN_FALSE; +} + /* Implementation of gdb.Symbol.line -> int. Returns the line number at which the symbol was defined. */ @@ -211,6 +234,53 @@ sympy_is_valid (PyObject *self, PyObject *args) Py_RETURN_TRUE; } +/* Implementation of gdb.Symbol.value (self[, frame]) -> gdb.Value. Returns + the value of the symbol, or an error in various circumstances. */ + +static PyObject * +sympy_value (PyObject *self, PyObject *args) +{ + struct symbol *symbol = NULL; + struct frame_info *frame_info = NULL; + PyObject *frame_obj = NULL; + struct value *value = NULL; + volatile struct gdb_exception except; + + if (!PyArg_ParseTuple (args, "|O", &frame_obj)) + return NULL; + + if (frame_obj != NULL && !PyObject_TypeCheck (frame_obj, &frame_object_type)) + { + PyErr_SetString (PyExc_TypeError, "argument is not a frame"); + return NULL; + } + + SYMPY_REQUIRE_VALID (self, symbol); + if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF) + { + PyErr_SetString (PyExc_TypeError, "cannot get the value of a typedef"); + return NULL; + } + + TRY_CATCH (except, RETURN_MASK_ALL) + { + if (frame_obj != NULL) + { + frame_info = frame_object_to_frame_info (frame_obj); + if (frame_info == NULL) + error ("invalid frame"); + } + + if (symbol_read_needs_frame (symbol) && frame_info == NULL) + error ("symbol requires a frame to compute its value"); + + value = read_var_value (symbol, frame_info); + } + GDB_PY_HANDLE_EXCEPTION (except); + + return value_to_value_object (value); +} + /* Given a symbol, and a symbol_object that has previously been allocated and initialized, populate the symbol_object with the struct symbol data. Also, register the symbol_object life-cycle @@ -473,6 +543,8 @@ to display demangled or mangled names.", NULL }, "True if the symbol is a function or method." }, { "is_variable", sympy_is_variable, NULL, "True if the symbol is a variable." }, + { "needs_frame", sympy_needs_frame, NULL, + "True if the symbol requires a frame for evaluation." }, { "line", sympy_line, NULL, "The source line number at which the symbol was defined." }, { NULL } /* Sentinel */ @@ -482,6 +554,9 @@ static PyMethodDef symbol_object_methods[] = { { "is_valid", sympy_is_valid, METH_NOARGS, "is_valid () -> Boolean.\n\ Return true if this symbol is valid, false if not." }, + { "value", sympy_value, METH_VARARGS, + "value ([frame]) -> gdb.Value\n\ +Return the value of the symbol." }, {NULL} /* Sentinel */ }; diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 22e6b41..1d6247d 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -121,6 +121,7 @@ extern PyTypeObject event_object_type; extern PyTypeObject events_object_type; extern PyTypeObject stop_event_object_type; extern PyTypeObject breakpoint_object_type; +extern PyTypeObject frame_object_type; typedef struct breakpoint_object { |