From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9283 invoked by alias); 11 Dec 2013 17:07:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 9192 invoked by uid 89); 11 Dec 2013 17:07:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Dec 2013 17:07:13 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBBH74Mp007671 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Dec 2013 12:07:04 -0500 Received: from barimba (ovpn-113-93.phx2.redhat.com [10.3.113.93]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rBBGU7Uv007631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 11 Dec 2013 11:30:13 -0500 From: Tom Tromey To: Hui Zhu Cc: gdb-patches ml Subject: Re: [PATCH] Make "backtrace" doesn't print python stack if init python dir get fail References: <52974146.70805@mentor.com> <8761r7w85h.fsf@fleche.redhat.com> <529D8865.80503@mentor.com> <87li01smua.fsf@fleche.redhat.com> <529EDCA7.1090903@mentor.com> Date: Wed, 11 Dec 2013 17:07:00 -0000 In-Reply-To: <529EDCA7.1090903@mentor.com> (Hui Zhu's message of "Wed, 4 Dec 2013 15:41:27 +0800") Message-ID: <87eh5j2vw0.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-12/txt/msg00441.txt.bz2 >>>>> "Hui" == Hui Zhu 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 + + * 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 * 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 */