Introduce gdbpy_enter_varobj and use it
This introduces gdbpy_enter_varobj, a subclass of gdbpy_enter; then changes one function in py-varobj.c to use it. gdbpy_enter_varobj takes a varobj as an argument, similar to varobj_ensure_python_env. 2017-01-10 Tom Tromey <tom@tromey.com> * varobj.c (gdbpy_enter_varobj): New constructor. * python/python-internal.h (gdbpy_enter_varobj): New class. * python/py-varobj.c (py_varobj_get_iterator): Use gdbpy_enter_varobj.
This commit is contained in:
parent
14b122bf1c
commit
6cd67beaae
4 changed files with 33 additions and 13 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2017-01-10 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* varobj.c (gdbpy_enter_varobj): New constructor.
|
||||||
|
* python/python-internal.h (gdbpy_enter_varobj): New class.
|
||||||
|
* python/py-varobj.c (py_varobj_get_iterator): Use
|
||||||
|
gdbpy_enter_varobj.
|
||||||
|
|
||||||
2017-01-10 Tom Tromey <tom@tromey.com>
|
2017-01-10 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* python/py-xmethods.c (gdbpy_get_xmethod_result_type): Use
|
* python/py-xmethods.c (gdbpy_get_xmethod_result_type): Use
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "python-internal.h"
|
#include "python-internal.h"
|
||||||
#include "varobj.h"
|
#include "varobj.h"
|
||||||
#include "varobj-iter.h"
|
#include "varobj-iter.h"
|
||||||
|
#include "py-ref.h"
|
||||||
|
|
||||||
/* A dynamic varobj iterator "class" for python pretty-printed
|
/* A dynamic varobj iterator "class" for python pretty-printed
|
||||||
varobjs. This inherits struct varobj_iter. */
|
varobjs. This inherits struct varobj_iter. */
|
||||||
|
@ -167,28 +168,23 @@ py_varobj_iter_new (struct varobj *var, PyObject *pyiter)
|
||||||
struct varobj_iter *
|
struct varobj_iter *
|
||||||
py_varobj_get_iterator (struct varobj *var, PyObject *printer)
|
py_varobj_get_iterator (struct varobj *var, PyObject *printer)
|
||||||
{
|
{
|
||||||
PyObject *children;
|
|
||||||
PyObject *iter;
|
PyObject *iter;
|
||||||
struct py_varobj_iter *py_iter;
|
struct py_varobj_iter *py_iter;
|
||||||
struct cleanup *back_to = varobj_ensure_python_env (var);
|
|
||||||
|
gdbpy_enter_varobj enter_py (var);
|
||||||
|
|
||||||
if (!PyObject_HasAttr (printer, gdbpy_children_cst))
|
if (!PyObject_HasAttr (printer, gdbpy_children_cst))
|
||||||
{
|
return NULL;
|
||||||
do_cleanups (back_to);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
|
gdbpy_ref children (PyObject_CallMethodObjArgs (printer, gdbpy_children_cst,
|
||||||
NULL);
|
NULL));
|
||||||
if (children == NULL)
|
if (children == NULL)
|
||||||
{
|
{
|
||||||
gdbpy_print_stack ();
|
gdbpy_print_stack ();
|
||||||
error (_("Null value returned for children"));
|
error (_("Null value returned for children"));
|
||||||
}
|
}
|
||||||
|
|
||||||
make_cleanup_py_decref (children);
|
iter = PyObject_GetIter (children.get ());
|
||||||
|
|
||||||
iter = PyObject_GetIter (children);
|
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
{
|
{
|
||||||
gdbpy_print_stack ();
|
gdbpy_print_stack ();
|
||||||
|
@ -197,7 +193,5 @@ py_varobj_get_iterator (struct varobj *var, PyObject *printer)
|
||||||
|
|
||||||
py_iter = py_varobj_iter_new (var, iter);
|
py_iter = py_varobj_iter_new (var, iter);
|
||||||
|
|
||||||
do_cleanups (back_to);
|
|
||||||
|
|
||||||
return &py_iter->base;
|
return &py_iter->base;
|
||||||
}
|
}
|
||||||
|
|
|
@ -526,6 +526,18 @@ class gdbpy_enter
|
||||||
PyObject *m_error_type, *m_error_value, *m_error_traceback;
|
PyObject *m_error_type, *m_error_value, *m_error_traceback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Like gdbpy_enter, but takes a varobj. This is a subclass just to
|
||||||
|
make constructor delegation a little nicer. */
|
||||||
|
class gdbpy_enter_varobj : public gdbpy_enter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/* This is defined in varobj.c, where it can access varobj
|
||||||
|
internals. */
|
||||||
|
gdbpy_enter_varobj (const struct varobj *var);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
|
struct cleanup *ensure_python_env (struct gdbarch *gdbarch,
|
||||||
const struct language_defn *language);
|
const struct language_defn *language);
|
||||||
|
|
||||||
|
|
|
@ -233,6 +233,13 @@ varobj_ensure_python_env (const struct varobj *var)
|
||||||
return ensure_python_env (var->root->exp->gdbarch,
|
return ensure_python_env (var->root->exp->gdbarch,
|
||||||
var->root->exp->language_defn);
|
var->root->exp->language_defn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* See python-internal.h. */
|
||||||
|
gdbpy_enter_varobj::gdbpy_enter_varobj (const struct varobj *var)
|
||||||
|
: gdbpy_enter (var->root->exp->gdbarch, var->root->exp->language_defn)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Return the full FRAME which corresponds to the given CORE_ADDR
|
/* Return the full FRAME which corresponds to the given CORE_ADDR
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue