Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Hui Zhu <hui_zhu@mentor.com>
Cc: gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Make "backtrace" doesn't print python stack if init python dir get fail
Date: Wed, 11 Dec 2013 17:07:00 -0000	[thread overview]
Message-ID: <87eh5j2vw0.fsf@fleche.redhat.com> (raw)
In-Reply-To: <529EDCA7.1090903@mentor.com> (Hui Zhu's message of "Wed, 4 Dec	2013 15:41:27 +0800")

>>>>> "Hui" == Hui Zhu <hui_zhu@mentor.com> writes:

>> Two other approaches are possible here instead.  One, change
>> finish_python_initialization to do the needed bit of locking by handy,
>> not using ensure_python_env.  Or, two, don't release the GIL until
>> somewhere in finish_python_initialization, and then it doesn't need
>> to call ensure_python_env at all.

Hui> I think the first way is better than second way because
Hui> ensure_python_env has relationship with current_arch and
Hui> current_language.  So I make a patch according the first way.

After seeing the patch I think it is probably preferable to do the
second route -- move the GIL releasing to finish_python_initialization.

Can you try the appended?

Tom

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 35a1d73..6554be2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2013-12-11  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (_initialize_python): Don't release the GIL or
+	set gdb_python_initialized.
+	(release_gil): New function.
+	(finish_python_initialization): Use release_gil.  Don't call
+	ensure_python_env.  Set gdb_python_initialized.
+
 2013-12-11  Sergio Durigan Junior  <sergiodj@redhat.com>
 
 	* break-catch-throw.c (fetch_probe_arguments): Pass selected frame
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 1873936..ddf8a1a 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1711,18 +1711,12 @@ message == an error message without a stack will be printed."),
   if (gdbpy_value_cst == NULL)
     goto fail;
 
-  /* Release the GIL while gdb runs.  */
-  PyThreadState_Swap (NULL);
-  PyEval_ReleaseLock ();
-
   make_final_cleanup (finalize_python, NULL);
 
-  gdb_python_initialized = 1;
   return;
 
  fail:
   gdbpy_print_stack ();
-  /* Do not set 'gdb_python_initialized'.  */
   return;
 
 #endif /* HAVE_PYTHON */
@@ -1730,6 +1724,15 @@ message == an error message without a stack will be printed."),
 
 #ifdef HAVE_PYTHON
 
+/* A cleanup function that releases the GIL.  */
+
+static void
+release_gil (void *ignore)
+{
+  PyThreadState_Swap (NULL);
+  PyEval_ReleaseLock ();
+}
+
 /* Perform the remaining python initializations.
    These must be done after GDB is at least mostly initialized.
    E.g., The "info pretty-printer" command needs the "info" prefix
@@ -1743,7 +1746,8 @@ finish_python_initialization (void)
   PyObject *sys_path;
   struct cleanup *cleanup;
 
-  cleanup = ensure_python_env (get_current_arch (), current_language);
+  /* Release the GIL while gdb runs.  */
+  cleanup = make_cleanup (release_gil, NULL);
 
   /* Add the initial data-directory to sys.path.  */
 
@@ -1807,12 +1811,16 @@ finish_python_initialization (void)
      variable.  */
 
   do_cleanups (cleanup);
+
+  gdb_python_initialized = 1;
+
   return;
 
  fail:
   gdbpy_print_stack ();
   warning (_("internal error: Unhandled Python exception"));
   do_cleanups (cleanup);
+  /* Do not set 'gdb_python_initialized'.  */
 }
 
 #endif /* HAVE_PYTHON */


  reply	other threads:[~2013-12-11 17:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-28 17:35 Hui Zhu
2013-12-02 16:05 ` Tom Tromey
2013-12-03  7:30   ` Hui Zhu
2013-12-03 20:27     ` Tom Tromey
2013-12-04  7:41       ` Hui Zhu
2013-12-11 17:07         ` Tom Tromey [this message]
2013-12-13 11:49           ` Hui Zhu
2014-01-14 16:09             ` Tom Tromey
2014-01-14 17:41               ` Tom Tromey
2014-01-14 21:32                 ` Phil Muldoon
2014-01-15 20:06                   ` Tom Tromey

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=87eh5j2vw0.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=hui_zhu@mentor.com \
    /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