+2013-05-20 Tom Tromey <tromey@redhat.com>
+
+ * mi/mi-main.c: Include python-internal.h.
+ (mi_cmd_list_features): Check gdb_python_initialized.
+ * python/py-inferior.c (python_on_normal_stop, python_on_resume)
+ (python_inferior_exit, python_new_objfile, add_thread_object)
+ (delete_thread_object, py_free_inferior): Check
+ gdb_python_initialized.
+ * python/py-prettyprint.c (apply_val_pretty_printer): Check
+ gdb_python_initialized.
+ * python/py-type.c (save_objfile_types): Check
+ gdb_python_initialized.
+ * python/python-internal.h (gdb_python_initialized): Declare.
+ * python/python.c (ensure_python_env): Throw exception if
+ Python not initialized.
+ (before_prompt_hook, source_python_script_for_objfile)
+ (start_type_printers, apply_type_printers,
+ free_type_printers): Check gdb_python_initialized.
+ * varobj.c (varobj_get_display_hint)
+ (dynamic_varobj_has_child_method, update_dynamic_varobj_children)
+ (install_new_value_visualizer, varobj_set_visualizer)
+ (value_get_print_value): Check gdb_python_initialized.
+
2013-05-20 Tom Tromey <tromey@redhat.com>
* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
struct cleanup *cleanup;
enum gdb_signal stop_signal;
+ if (!gdb_python_initialized)
+ return;
+
if (!find_thread_ptid (inferior_ptid))
return;
{
struct cleanup *cleanup;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (target_gdbarch (), current_language);
if (emit_continue_event (ptid) < 0)
struct cleanup *cleanup;
const LONGEST *exit_code = NULL;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (target_gdbarch (), current_language);
if (inf->has_exit_code)
if (objfile == NULL)
return;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (get_objfile_arch (objfile), current_language);
if (emit_new_objfile_event (objfile) < 0)
inferior_object *inf_obj;
struct threadlist_entry *entry;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (python_gdbarch, python_language);
thread_obj = create_thread_object (tp);
inferior_object *inf_obj;
struct threadlist_entry **entry, *tmp;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (python_gdbarch, python_language);
inf_obj = (inferior_object *) find_inferior_object (PIDGET(tp->ptid));
inferior_object *inf_obj = datum;
struct threadlist_entry *th_entry, *th_tmp;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (python_gdbarch, python_language);
inf_obj->inferior = NULL;
{
struct python_env *env = xmalloc (sizeof *env);
+ /* We should not ever enter Python unless initialized. */
+ if (!gdb_python_initialized)
+ error (_("Python not initialized"));
+
env->state = PyGILState_Ensure ();
env->gdbarch = python_gdbarch;
env->language = python_language;
struct cleanup *cleanup;
char *prompt = NULL;
+ if (!gdb_python_initialized)
+ return;
+
cleanup = ensure_python_env (get_current_arch (), current_language);
if (gdb_python_module
{
struct cleanup *cleanups;
+ if (!gdb_python_initialized)
+ return;
+
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
gdbpy_current_objfile = objfile;
struct cleanup *cleanups;
PyObject *type_module, *func, *result_obj = NULL;
+ if (!gdb_python_initialized)
+ return NULL;
+
cleanups = ensure_python_env (get_current_arch (), current_language);
type_module = PyImport_ImportModule ("gdb.types");
if (printers_obj == NULL)
return NULL;
+ if (!gdb_python_initialized)
+ return NULL;
+
cleanups = ensure_python_env (get_current_arch (), current_language);
type_obj = type_to_type_object (type);
if (printers == NULL)
return;
+ if (!gdb_python_initialized)
+ return;
+
cleanups = ensure_python_env (get_current_arch (), current_language);
Py_DECREF (printers);
do_cleanups (cleanups);
char *result = NULL;
#if HAVE_PYTHON
- struct cleanup *back_to = varobj_ensure_python_env (var);
+ struct cleanup *back_to;
+
+ if (!gdb_python_initialized)
+ return NULL;
+
+ back_to = varobj_ensure_python_env (var);
if (var->pretty_printer)
result = gdbpy_get_display_hint (var->pretty_printer);
PyObject *printer = var->pretty_printer;
int result;
+ if (!gdb_python_initialized)
+ return 0;
+
back_to = varobj_ensure_python_env (var);
result = PyObject_HasAttr (printer, gdbpy_children_cst);
do_cleanups (back_to);
int i;
PyObject *printer = var->pretty_printer;
+ if (!gdb_python_initialized)
+ return 0;
+
back_to = varobj_ensure_python_env (var);
*cchanged = 0;
#if HAVE_PYTHON
/* If the constructor is None, then we want the raw value. If VAR
does not have a value, just skip this. */
+ if (!gdb_python_initialized)
+ return;
+
if (var->constructor != Py_None && var->value)
{
struct cleanup *cleanup;
PyObject *mainmod, *globals, *constructor;
struct cleanup *back_to;
+ if (!gdb_python_initialized)
+ return;
+
back_to = varobj_ensure_python_env (var);
mainmod = PyImport_AddModule ("__main__");
gdbarch = get_type_arch (value_type (value));
#if HAVE_PYTHON
- {
- PyObject *value_formatter = var->pretty_printer;
+ if (gdb_python_initialized)
+ {
+ PyObject *value_formatter = var->pretty_printer;
- varobj_ensure_python_env (var);
+ varobj_ensure_python_env (var);
- if (value_formatter)
- {
- /* First check to see if we have any children at all. If so,
- we simply return {...}. */
- if (dynamic_varobj_has_child_method (var))
- {
- do_cleanups (old_chain);
- return xstrdup ("{...}");
- }
+ if (value_formatter)
+ {
+ /* First check to see if we have any children at all. If so,
+ we simply return {...}. */
+ if (dynamic_varobj_has_child_method (var))
+ {
+ do_cleanups (old_chain);
+ return xstrdup ("{...}");
+ }
- if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
- {
- struct value *replacement;
- PyObject *output = NULL;
+ if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
+ {
+ struct value *replacement;
+ PyObject *output = NULL;
- output = apply_varobj_pretty_printer (value_formatter,
- &replacement,
- stb);
+ output = apply_varobj_pretty_printer (value_formatter,
+ &replacement,
+ stb);
- /* If we have string like output ... */
- if (output)
- {
- make_cleanup_py_decref (output);
-
- /* If this is a lazy string, extract it. For lazy
- strings we always print as a string, so set
- string_print. */
- if (gdbpy_is_lazy_string (output))
- {
- gdbpy_extract_lazy_string (output, &str_addr, &type,
- &len, &encoding);
- make_cleanup (free_current_contents, &encoding);
- string_print = 1;
- }
- else
- {
- /* If it is a regular (non-lazy) string, extract
- it and copy the contents into THEVALUE. If the
- hint says to print it as a string, set
- string_print. Otherwise just return the extracted
- string as a value. */
-
- char *s = python_string_to_target_string (output);
-
- if (s)
- {
- char *hint;
-
- hint = gdbpy_get_display_hint (value_formatter);
- if (hint)
- {
- if (!strcmp (hint, "string"))
- string_print = 1;
- xfree (hint);
- }
-
- len = strlen (s);
- thevalue = xmemdup (s, len + 1, len + 1);
- type = builtin_type (gdbarch)->builtin_char;
- xfree (s);
-
- if (!string_print)
- {
- do_cleanups (old_chain);
- return thevalue;
- }
-
- make_cleanup (xfree, thevalue);
- }
- else
- gdbpy_print_stack ();
- }
- }
- /* If the printer returned a replacement value, set VALUE
- to REPLACEMENT. If there is not a replacement value,
- just use the value passed to this function. */
- if (replacement)
- value = replacement;
- }
- }
- }
+ /* If we have string like output ... */
+ if (output)
+ {
+ make_cleanup_py_decref (output);
+
+ /* If this is a lazy string, extract it. For lazy
+ strings we always print as a string, so set
+ string_print. */
+ if (gdbpy_is_lazy_string (output))
+ {
+ gdbpy_extract_lazy_string (output, &str_addr, &type,
+ &len, &encoding);
+ make_cleanup (free_current_contents, &encoding);
+ string_print = 1;
+ }
+ else
+ {
+ /* If it is a regular (non-lazy) string, extract
+ it and copy the contents into THEVALUE. If the
+ hint says to print it as a string, set
+ string_print. Otherwise just return the extracted
+ string as a value. */
+
+ char *s = python_string_to_target_string (output);
+
+ if (s)
+ {
+ char *hint;
+
+ hint = gdbpy_get_display_hint (value_formatter);
+ if (hint)
+ {
+ if (!strcmp (hint, "string"))
+ string_print = 1;
+ xfree (hint);
+ }
+
+ len = strlen (s);
+ thevalue = xmemdup (s, len + 1, len + 1);
+ type = builtin_type (gdbarch)->builtin_char;
+ xfree (s);
+
+ if (!string_print)
+ {
+ do_cleanups (old_chain);
+ return thevalue;
+ }
+
+ make_cleanup (xfree, thevalue);
+ }
+ else
+ gdbpy_print_stack ();
+ }
+ }
+ /* If the printer returned a replacement value, set VALUE
+ to REPLACEMENT. If there is not a replacement value,
+ just use the value passed to this function. */
+ if (replacement)
+ value = replacement;
+ }
+ }
+ }
#endif
get_formatted_print_options (&opts, format_code[(int) format]);