From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29807 invoked by alias); 14 Jan 2014 17:41:44 -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 29761 invoked by uid 89); 14 Jan 2014 17:41:43 -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,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Jan 2014 17:41:42 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0EHfeVE026823 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 14 Jan 2014 12:41:40 -0500 Received: from barimba (ovpn-113-85.phx2.redhat.com [10.3.113.85]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0EHfcjW030114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 14 Jan 2014 12:41:39 -0500 From: Tom Tromey To: Hui Zhu Cc: gdb-patches ml , Phil Muldoon 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> <52AAF43B.5060603@mentor.com> <87vbxmwnn3.fsf@fleche.redhat.com> Date: Tue, 14 Jan 2014 17:41:00 -0000 In-Reply-To: <87vbxmwnn3.fsf@fleche.redhat.com> (Tom Tromey's message of "Tue, 14 Jan 2014 09:09:52 -0700") Message-ID: <87ha96wje5.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: 2014-01/txt/msg00451.txt.bz2 >>>>> "Hui" == Tom Tromey writes: Hui> With this patch, GDB will output a lot of "Python not initialized" Hui> that output by function "ensure_python_env". Hui> For example: Hui> (gdb) start Hui> Temporary breakpoint 1 at 0x400507: file 2.c, line 4. Hui> Starting program: /home/teawater/tmp/2 Hui> Python not initialized Tom> I think this may be an independent bug. Tom> I'll have a better patch soon. Ok, I have looked into the problem some more. I'm sorry this has been taking so long. I've appended my current patch. It arranges to clear gdb_python_initialized if the second stage of initialization fails. And, it adds a check on gdb_python_initialized in a couple of spots that we missed before. However, it still isn't quite right, due to this code in finish_python_initialization: if (gdb_python_module == NULL) { gdbpy_print_stack (); /* This is passed in one call to warning so that blank lines aren't inserted between each line of text. */ warning (_("\n" "Could not load the Python gdb module from `%s'.\n" "Limited Python support is available from the _gdb module.\n" "Suggest passing --data-directory=/path/to/gdb/data-directory.\n"), gdb_pythondir); do_cleanups (cleanup); return; } The question is -- what should we really do here? One option is to set gdb_python_initialized = 0. I think this makes the warning text obsolete, though, since the "limited" support would not actually be available at all (e.g., the "python" command wouldn't work at all). Another option is to try to split the initialization global. One of your patches in this thread did that. It wasn't clear to me that your patch went far enough, though -- it changed some spots to check the new flag, but not every spot. This approach would seem to involve auditing all uses of gdb_python_initialized and deciding (how?) whether or not the particular spot needs "full" initialization. I lean toward the simpler solution of changing the warning message and clearing the flag. Tom 2014-01-14 Tom Tromey * python/py-finishbreakpoint.c (bpfinishpy_handle_stop): Check gdb_python_initialized. (bpfinishpy_handle_exit): Likewise. * python/python.c (_initialize_python): Don't release the GIL. (release_gil): New function. (finish_python_initialization): Use release_gil. Don't call ensure_python_env. Possibly clear gdb_python_initialized. diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index 712a9ee..4e052d7 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -382,8 +382,12 @@ bpfinishpy_detect_out_scope_cb (struct breakpoint *b, void *args) static void bpfinishpy_handle_stop (struct bpstats *bs, int print_frame) { - struct cleanup *cleanup = ensure_python_env (get_current_arch (), - current_language); + struct cleanup *cleanup; + + if (!gdb_python_initialized) + return; + + cleanup = ensure_python_env (get_current_arch (), current_language); iterate_over_breakpoints (bpfinishpy_detect_out_scope_cb, bs == NULL ? NULL : bs->breakpoint_at); @@ -397,8 +401,12 @@ bpfinishpy_handle_stop (struct bpstats *bs, int print_frame) static void bpfinishpy_handle_exit (struct inferior *inf) { - struct cleanup *cleanup = ensure_python_env (target_gdbarch (), - current_language); + struct cleanup *cleanup; + + if (!gdb_python_initialized) + return; + + cleanup = ensure_python_env (target_gdbarch (), current_language); iterate_over_breakpoints (bpfinishpy_detect_out_scope_cb, NULL); diff --git a/gdb/python/python.c b/gdb/python/python.c index 337c170..8a6389f 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1712,10 +1712,6 @@ 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; @@ -1731,6 +1727,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 @@ -1744,7 +1749,13 @@ finish_python_initialization (void) PyObject *sys_path; struct cleanup *cleanup; - cleanup = ensure_python_env (get_current_arch (), current_language); + /* If the first phase of initialization failed, don't bother doing + anything here. */ + if (!gdb_python_initialized) + return; + + /* Release the GIL while gdb runs. */ + cleanup = make_cleanup (release_gil, NULL); /* Add the initial data-directory to sys.path. */ @@ -1814,6 +1825,7 @@ finish_python_initialization (void) gdbpy_print_stack (); warning (_("internal error: Unhandled Python exception")); do_cleanups (cleanup); + gdb_python_initialized = 0; } #endif /* HAVE_PYTHON */