aboutsummaryrefslogtreecommitdiff
path: root/gdb/varobj.c
diff options
context:
space:
mode:
authorUlrich Weigand <uweigand@de.ibm.com>2009-07-02 17:04:23 +0000
committerUlrich Weigand <uweigand@de.ibm.com>2009-07-02 17:04:23 +0000
commitd452c4bcefbbe7b2305a5ce26469e06d940a690c (patch)
tree467cff4f090cda97377cf4c6dacbe93000870661 /gdb/varobj.c
parente17c207e88cbd63e9dc9dce1f3458a8ced4ff566 (diff)
downloadgdb-d452c4bcefbbe7b2305a5ce26469e06d940a690c.zip
gdb-d452c4bcefbbe7b2305a5ce26469e06d940a690c.tar.gz
gdb-d452c4bcefbbe7b2305a5ce26469e06d940a690c.tar.bz2
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise. (ensure_python_env): Add prototype. (make_cleanup_py_restore_gil): Remove prototype. * python/python.c: Include "arch-utils.h", "value.h" and "language.h". (python_gdbarch, python_language): New global variables. (struct python_env): New data type. (ensure_python_env, restore_python_env): New functions. (eval_python_from_control_command): Call ensure_python_env to install current architecture and language. (python_command, gdbpy_new_objfile): Likewise. * python/python-cmd.c: Include "arch-utils.h" and "language.h". (cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call ensure_python_env. * python/python-type.c (clean_up_objfile_types): Likewise. * python/python-objfile.c: Include "language.h". (clean_up_objfile): Call ensure_python_env. * python/python-prettyprint.c (apply_val_pretty_printer): Likewise. (apply_varobj_pretty_printer): Do not call PyGILState_Ensure. * varobj.c (varobj_ensure_python_env): New helper function. (varobj_get_display_hint, update_dynamic_varobj_children, install_default_visualizer, varobj_set_visualizer, free_variable, value_get_print_value): Call it. (value_get_print_value): Add varobj argument instead of pretty printer argument. Update all callers. * python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil): Remove. * value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument. (call_internal_function): Likewise. * value.c (call_internal_function): Likewise. Pass to handler. * eval.c (evaluate_subexp_standard): Update call. * python/python-function.c: Include "language.h". (fnpy_call): Add GDBARCH and LANGAUAGE arguments and call make_cleanup_python_env. * python/python-value.c (builtin_type_pyint, builtin_type_pyfloat, builtin_type_pylong, builtin_type_pybool, builtin_type_pychar, valpy_str): Use python_gdbarch and python_language instead of current_gdbarch and current_language. * python/python-type.c (typy_lookup_typename): Likewise.
Diffstat (limited to 'gdb/varobj.c')
-rw-r--r--gdb/varobj.c68
1 files changed, 37 insertions, 31 deletions
diff --git a/gdb/varobj.c b/gdb/varobj.c
index e6cae7f..db27a4b 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -258,7 +258,7 @@ static char *my_value_of_variable (struct varobj *var,
static char *value_get_print_value (struct value *value,
enum varobj_display_formats format,
- PyObject *value_formatter);
+ struct varobj *var);
static int varobj_value_is_changeable_p (struct varobj *var);
@@ -446,6 +446,17 @@ is_root_p (struct varobj *var)
return (var->root->rootvar == var);
}
+#ifdef HAVE_PYTHON
+/* Helper function to install a Python environment suitable for
+ use during operations on VAR. */
+struct cleanup *
+varobj_ensure_python_env (struct varobj *var)
+{
+ return ensure_python_env (var->root->exp->gdbarch,
+ var->root->exp->language_defn);
+}
+#endif
+
/* Creates a varobj (not its children) */
/* Return the full FRAME which corresponds to the given CORE_ADDR
@@ -765,8 +776,7 @@ varobj_set_display_format (struct varobj *var,
&& var->value && !value_lazy (var->value))
{
xfree (var->print_value);
- var->print_value = value_get_print_value (var->value, var->format,
- var->pretty_printer);
+ var->print_value = value_get_print_value (var->value, var->format, var);
}
return var->format;
@@ -784,10 +794,12 @@ varobj_get_display_hint (struct varobj *var)
char *result = NULL;
#if HAVE_PYTHON
- PyGILState_STATE state = PyGILState_Ensure ();
+ struct cleanup *back_to = varobj_ensure_python_env (var);
+
if (var->pretty_printer)
result = gdbpy_get_display_hint (var->pretty_printer);
- PyGILState_Release (state);
+
+ do_cleanups (back_to);
#endif
return result;
@@ -842,10 +854,8 @@ update_dynamic_varobj_children (struct varobj *var,
int i;
int children_changed = 0;
PyObject *printer = var->pretty_printer;
- PyGILState_STATE state;
- state = PyGILState_Ensure ();
- back_to = make_cleanup_py_restore_gil (&state);
+ back_to = varobj_ensure_python_env (var);
*cchanged = 0;
if (!PyObject_HasAttr (printer, gdbpy_children_cst))
@@ -1282,8 +1292,7 @@ install_new_value (struct varobj *var, struct value *value, int initial)
lazy -- if it is, the code above has decided that the value
should not be fetched. */
if (value && !value_lazy (value))
- print_value = value_get_print_value (value, var->format,
- var->pretty_printer);
+ print_value = value_get_print_value (value, var->format, var);
/* If the type is changeable, compare the old and the new values.
If this is the initial assignment, we don't have any old value
@@ -1386,11 +1395,9 @@ install_default_visualizer (struct varobj *var)
{
#if HAVE_PYTHON
struct cleanup *cleanup;
- PyGILState_STATE state;
PyObject *pretty_printer = NULL;
- state = PyGILState_Ensure ();
- cleanup = make_cleanup_py_restore_gil (&state);
+ cleanup = varobj_ensure_python_env (var);
if (var->value)
{
@@ -1421,11 +1428,8 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
#if HAVE_PYTHON
PyObject *mainmod, *globals, *pretty_printer, *constructor;
struct cleanup *back_to, *value;
- PyGILState_STATE state;
-
- state = PyGILState_Ensure ();
- back_to = make_cleanup_py_restore_gil (&state);
+ back_to = varobj_ensure_python_env (var);
mainmod = PyImport_AddModule ("__main__");
globals = PyModule_GetDict (mainmod);
@@ -1921,6 +1925,15 @@ new_root_variable (void)
static void
free_variable (struct varobj *var)
{
+#if HAVE_PYTHON
+ if (var->pretty_printer)
+ {
+ struct cleanup *cleanup = varobj_ensure_python_env (var);
+ Py_DECREF (var->pretty_printer);
+ do_cleanups (cleanup);
+ }
+#endif
+
value_free (var->value);
/* Free the expression if this is a root variable. */
@@ -1930,14 +1943,6 @@ free_variable (struct varobj *var)
xfree (var->root);
}
-#if HAVE_PYTHON
- {
- PyGILState_STATE state = PyGILState_Ensure ();
- Py_XDECREF (var->pretty_printer);
- PyGILState_Release (state);
- }
-#endif
-
xfree (var->name);
xfree (var->obj_name);
xfree (var->print_value);
@@ -2212,7 +2217,7 @@ my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
static char *
value_get_print_value (struct value *value, enum varobj_display_formats format,
- PyObject *value_formatter)
+ struct varobj *var)
{
long dummy;
struct ui_file *stb;
@@ -2225,7 +2230,9 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
#if HAVE_PYTHON
{
- PyGILState_STATE state = PyGILState_Ensure ();
+ struct cleanup *back_to = varobj_ensure_python_env (var);
+ PyObject *value_formatter = var->pretty_printer;
+
if (value_formatter && PyObject_HasAttr (value_formatter,
gdbpy_to_string_cst))
{
@@ -2245,13 +2252,13 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
&replacement);
if (thevalue && !string_print)
{
- PyGILState_Release (state);
+ do_cleanups (back_to);
return thevalue;
}
if (replacement)
value = replacement;
}
- PyGILState_Release (state);
+ do_cleanups (back_to);
}
#endif
@@ -2774,8 +2781,7 @@ c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
if (format == var->format)
return xstrdup (var->print_value);
else
- return value_get_print_value (var->value, format,
- var->pretty_printer);
+ return value_get_print_value (var->value, format, var);
}
}
}