From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19429 invoked by alias); 13 Dec 2013 11:49:23 -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 19420 invoked by uid 89); 13 Dec 2013 11:49:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Dec 2013 11:49:21 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1VrRF8-0002qV-7R from Hui_Zhu@mentor.com ; Fri, 13 Dec 2013 03:49:18 -0800 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 13 Dec 2013 03:49:18 -0800 Received: from [127.0.0.1] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Fri, 13 Dec 2013 03:49:17 -0800 Message-ID: <52AAF43B.5060603@mentor.com> Date: Fri, 13 Dec 2013 11:49:00 -0000 From: Hui Zhu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: Tom Tromey 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> <87eh5j2vw0.fsf@fleche.redhat.com> In-Reply-To: <87eh5j2vw0.fsf@fleche.redhat.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2013-12/txt/msg00527.txt.bz2 On 12/12/13 00:30, Tom Tromey wrote: >>>>>> "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? Hi Tom, With this patch, GDB will output a lot of "Python not initialized" that output by function "ensure_python_env". For example: (gdb) start Temporary breakpoint 1 at 0x400507: file 2.c, line 4. Starting program: /home/teawater/tmp/2 Python not initialized (gdb) bt #0 main (argc=1, argv=0x7fffffffe138, envp=0x7fffffffe148) at 2.c:4 (gdb) quit A debugging session is active. Inferior 1 [process 31052] will be killed. Quit anyway? (y or n) y Python not initialized Thanks, Hui > > 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 */ >