From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18223 invoked by alias); 4 Dec 2013 07:41:48 -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 18213 invoked by uid 89); 4 Dec 2013 07:41:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL,BAYES_50,RDNS_NONE,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Dec 2013 07:41:46 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1Vo75O-0001Ql-7j from Hui_Zhu@mentor.com ; Tue, 03 Dec 2013 23:41:30 -0800 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 3 Dec 2013 23:41:30 -0800 Received: from [127.0.0.1] (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.2.247.3; Tue, 3 Dec 2013 23:41:29 -0800 Message-ID: <529EDCA7.1090903@mentor.com> Date: Wed, 04 Dec 2013 07:41: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> In-Reply-To: <87li01smua.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/msg00116.txt.bz2 On 12/04/13 04:26, Tom Tromey wrote: >>>>>> "Hui" == Hui Zhu writes: > > Hui> I got a issue is ensure_python_env check gdb_python_initialized and > Hui> throw error if it is 0. So gdb_python_initialized to 0 will make > Hui> some commands throw error when python dir has something error. I > Hui> removed this check in the patch. > > I think that's a useful consistency check, so better left in place. > > 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. > > Tom > Hi Tom, I think the first way is better than second way because ensure_python_env has relationship with current_arch and current_language. So I make a patch according the first way. It extends gdb_python_initialized to a flags. And add GDB_PYTHON_INITIALIZED_BASE and GDB_PYTHON_INITIALIZED_DIR as its flags. In _initialize_python, set GDB_PYTHON_INITIALIZED_BASE to gdb_python_initialized. In gdb_python_initialized, plus GDB_PYTHON_INITIALIZED_DIR to gdb_python_initialized. Then in the function that need python lib support (apply_frame_filter, start_type_printers), check GDB_PYTHON_INITIALIZED_DIR. It handle the issue and pass the regression test in x86_64 linux. Please help me review it. Thanks, Hui 2013-12-04 Hui Zhu * python/py-framefilter.c (apply_frame_filter): Change the check of "gdb_python_initialized". * python/python-internal.h (GDB_PYTHON_INITIALIZED_BASE, GDB_PYTHON_INITIALIZED_DIR): New. (gdb_python_initialized): Add comments. * python/python.c (gdb_python_initialized): Remove comments. (ensure_python_env): Change the check of "gdb_python_initialized". (start_type_printers): Ditto. (_initialize_python): Change the setup of "gdb_python_initialized". (finish_python_initialization): Add setup of "gdb_python_initialized". --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -1474,7 +1474,7 @@ apply_frame_filter (struct frame_info *f PyObject *item; htab_t levels_printed; - if (!gdb_python_initialized) + if ((gdb_python_initialized & GDB_PYTHON_INITIALIZED_DIR) == 0) return PY_BT_NO_FILTERS; cleanups = ensure_python_env (gdbarch, current_language); --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -204,6 +204,14 @@ struct program_space; struct bpstats; struct inferior; +/* This bit will be true if Python libary has been successfully + initialized. */ +#define GDB_PYTHON_INITIALIZED_BASE 0x1 +/* This bit will be true if Python directory has been successfully + initialized. */ +#define GDB_PYTHON_INITIALIZED_DIR 0x2 + +/* The status of Python initialized. */ extern int gdb_python_initialized; extern PyObject *gdb_module; --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -73,9 +73,6 @@ static const char *gdbpy_should_print_st #include "interps.h" #include "event-top.h" -/* True if Python has been successfully initialized, false - otherwise. */ - int gdb_python_initialized; static PyMethodDef GdbMethods[]; @@ -151,7 +148,7 @@ ensure_python_env (struct gdbarch *gdbar struct python_env *env = xmalloc (sizeof *env); /* We should not ever enter Python unless initialized. */ - if (!gdb_python_initialized) + if ((gdb_python_initialized & GDB_PYTHON_INITIALIZED_BASE) == 0) error (_("Python not initialized")); env->state = PyGILState_Ensure (); @@ -1235,7 +1232,7 @@ start_type_printers (void) struct cleanup *cleanups; PyObject *type_module, *func = NULL, *result_obj = NULL; - if (!gdb_python_initialized) + if ((gdb_python_initialized & GDB_PYTHON_INITIALIZED_DIR) == 0) return NULL; cleanups = ensure_python_env (get_current_arch (), current_language); @@ -1717,7 +1714,7 @@ message == an error message without a st make_final_cleanup (finalize_python, NULL); - gdb_python_initialized = 1; + gdb_python_initialized = GDB_PYTHON_INITIALIZED_BASE; return; fail: @@ -1807,6 +1804,8 @@ finish_python_initialization (void) variable. */ do_cleanups (cleanup); + + gdb_python_initialized |= GDB_PYTHON_INITIALIZED_DIR; return; fail: