[PATCH 2/5] Add Python Inferior object debug traces
Simon Marchi
simon.marchi@ericsson.com
Mon Jan 23 22:43:00 GMT 2017
I added those printfs while trying to debug the refcount issue fixed by
a following patch. I thought it could be useful to have debug traces
for anything Python-related. I have only added prints to track Inferior
the lifetime of Inferior objects because that's all I needed, but we
might want to add the same for other types in the future.
While debugging, I also made some kind of "maint python refcounts" that
would print the refcounts of each known Inferior object. If you think
it could be useful I could dig it up.
gdb/ChangeLog:
* python/python-internal.h (debug_python): New variable
declaration.
* python/python.c (debug_python): New variable.
(_initialize_python): Add "set debug python" command.
* python/py-inferior.c (inferior_to_inferior_object): Add debug
print.
(infpy_dealloc): Likewise.
(py_free_inferior): Likewise.
---
gdb/python/py-inferior.c | 15 +++++++++++++++
gdb/python/python-internal.h | 4 ++++
gdb/python/python.c | 12 ++++++++++++
3 files changed, 31 insertions(+)
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index b2aaf25e8a..5c215fef44 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -215,6 +215,10 @@ inferior_to_inferior_object (struct inferior *inferior)
inf_obj = (inferior_object *) inferior_data (inferior, infpy_inf_data_key);
if (!inf_obj)
{
+ if (debug_python)
+ printf_filtered ("Creating Python Inferior object inf = %d\n",
+ inferior->num);
+
inf_obj = PyObject_New (inferior_object, &inferior_object_type);
if (!inf_obj)
return NULL;
@@ -758,6 +762,14 @@ infpy_dealloc (PyObject *obj)
inferior_object *inf_obj = (inferior_object *) obj;
struct inferior *inf = inf_obj->inferior;
+ if (debug_python)
+ {
+ if (inf != NULL)
+ printf_filtered ("infpy_dealloc inf = %d\n", inf->num);
+ else
+ printf_filtered ("infpy_dealloc inf = <unknown>\n");
+ }
+
if (! inf)
return;
@@ -777,6 +789,9 @@ py_free_inferior (struct inferior *inf, void *datum)
gdbpy_enter enter_py (python_gdbarch, python_language);
+ if (debug_python)
+ printf_filtered ("py_free_inferior inf = %d\n", inf->num);
+
inf_obj->inferior = NULL;
/* Deallocate threads list. */
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index e2ebc1b8a2..ac98f12ab3 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -240,6 +240,10 @@ struct inferior;
extern int gdb_python_initialized;
+/* True if debug output about Python features is enabled. */
+
+extern int debug_python;
+
extern PyObject *gdb_module;
extern PyObject *gdb_python_module;
extern PyTypeObject value_object_type
diff --git a/gdb/python/python.c b/gdb/python/python.c
index ab5a6a416d..dc0fa25054 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -106,6 +106,10 @@ const struct extension_language_defn extension_language_python =
int gdb_python_initialized;
+/* See python-internal.h */
+
+int debug_python = 0;
+
extern PyMethodDef python_GdbMethods[];
#ifdef IS_PY3K
@@ -1605,6 +1609,14 @@ message == an error message without a stack will be printed."),
&user_set_python_list,
&user_show_python_list);
+ add_setshow_boolean_cmd ("python", class_maintenance,
+ &debug_python, _("\
+Set Python debug output."), _("\
+Show Python debug output."), _("\
+When on, debugging output for Python-related features is displayed."),
+ NULL, NULL,
+ &setdebuglist, &showdebuglist);
+
#ifdef HAVE_PYTHON
#ifdef WITH_PYTHON_PATH
/* Work around problem where python gets confused about where it is,
--
2.11.0
More information about the Gdb-patches
mailing list