From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 2/5] Add Python Inferior object debug traces
Date: Mon, 23 Jan 2017 22:43:00 -0000 [thread overview]
Message-ID: <20170123224004.8893-3-simon.marchi@ericsson.com> (raw)
In-Reply-To: <20170123224004.8893-1-simon.marchi@ericsson.com>
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
prev parent reply other threads:[~2017-01-23 22:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-23 22:43 [PATCH 0/5] Improve Python Inferior reference handling + fix a bug Simon Marchi
2017-01-23 22:43 ` [PATCH 5/5] Add missing incref when creating Inferior Python object Simon Marchi
2017-02-25 18:41 ` Simon Marchi
2017-04-27 21:13 ` [pushed master+8.0] " Simon Marchi
2017-01-23 22:43 ` [PATCH 3/5] Make Python inferior-related internal functions return inferior_object* Simon Marchi
2017-01-24 0:03 ` Pedro Alves
2017-01-23 22:43 ` [PATCH 1/5] Introduce specialized versions of gdbpy_ref Simon Marchi
2017-01-24 15:54 ` Tom Tromey
2017-01-24 16:18 ` Simon Marchi
2017-02-09 11:58 ` Pedro Alves
2017-02-09 16:18 ` Simon Marchi
2017-01-23 22:43 ` [PATCH 4/5] Make Python inferior-related internal functions return a gdbpy_inf_ref Simon Marchi
2017-01-24 16:15 ` Simon Marchi
2017-02-09 12:30 ` Pedro Alves
2017-02-09 16:39 ` Simon Marchi
2017-01-23 22:43 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170123224004.8893-3-simon.marchi@ericsson.com \
--to=simon.marchi@ericsson.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).