From patchwork Fri Jun 7 22:10:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33050 Received: (qmail 79372 invoked by alias); 7 Jun 2019 22:10:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 79362 invoked by uid 89); 7 Jun 2019 22:10:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.1 spammy=gdbpy_ref, gil X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.125) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Jun 2019 22:10:31 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway22.websitewelcome.com (Postfix) with ESMTP id B49F268C1 for ; Fri, 7 Jun 2019 17:10:29 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id ZN49hGuGv2PzOZN49hagSt; Fri, 07 Jun 2019 17:10:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=mBkQ60OaD819ZfO70LJ5u2w9VhPIn1OKnobWRr0Jyjs=; b=uaKAfIUszZUCO4eeRrsgoYxgT5 g2cwMfs9g9MmiMF1MvLpxTpYHHubhKyPN2Jvfco/1y2Xi4HEnbskYB4fKT2CuGNcJ6Iv/vTdt1DaM OmhyZ71nDsjsawp/pjp0w7YKG; Received: from 174-29-48-168.hlrn.qwest.net ([174.29.48.168]:57620 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hZN49-003Yro-0X; Fri, 07 Jun 2019 17:10:29 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Use gdbpy_enter in py-breakpoint.c Date: Fri, 7 Jun 2019 16:10:26 -0600 Message-Id: <20190607221026.15939-1-tom@tromey.com> A few spots in py-breakpoint.c acquire the GIL manually. However, because these spots generate events, and because events are expected to be arbitrary gdb-flavored Python code, it's important to use gdbpy_enter instead, in order to ensure that the other gdb-related Python globals are set correctly. This patch makes this change. Tested on x86-64 Fedora 29. gdb/ChangeLog 2019-06-07 Tom Tromey * python/py-breakpoint.c (gdbpy_breakpoint_created) (gdbpy_breakpoint_deleted, gdbpy_breakpoint_modified): Use gdbpy_enter. --- gdb/ChangeLog | 6 ++++++ gdb/python/py-breakpoint.c | 18 ++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index fc9543eba0e..88cd7de3343 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -1003,7 +1003,6 @@ static void gdbpy_breakpoint_created (struct breakpoint *bp) { gdbpy_breakpoint_object *newbp; - PyGILState_STATE state; if (!user_breakpoint_p (bp) && bppy_pending_object == NULL) return; @@ -1015,7 +1014,8 @@ gdbpy_breakpoint_created (struct breakpoint *bp) && bp->type != bp_access_watchpoint) return; - state = PyGILState_Ensure (); + struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch (); + gdbpy_enter enter_py (garch, current_language); if (bppy_pending_object) { @@ -1046,8 +1046,6 @@ gdbpy_breakpoint_created (struct breakpoint *bp) gdb_py_events.breakpoint_created) < 0) gdbpy_print_stack (); } - - PyGILState_Release (state); } /* Callback that is used when a breakpoint is deleted. This will @@ -1056,13 +1054,14 @@ static void gdbpy_breakpoint_deleted (struct breakpoint *b) { int num = b->number; - PyGILState_STATE state; struct breakpoint *bp = NULL; - state = PyGILState_Ensure (); bp = get_breakpoint (num); if (bp) { + struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch (); + gdbpy_enter enter_py (garch, current_language); + gdbpy_ref bp_obj (bp->py_bp_object); if (bp_obj != NULL) { @@ -1077,7 +1076,6 @@ gdbpy_breakpoint_deleted (struct breakpoint *b) --bppy_live; } } - PyGILState_Release (state); } /* Callback that is used when a breakpoint is modified. */ @@ -1086,13 +1084,14 @@ static void gdbpy_breakpoint_modified (struct breakpoint *b) { int num = b->number; - PyGILState_STATE state; struct breakpoint *bp = NULL; - state = PyGILState_Ensure (); bp = get_breakpoint (num); if (bp) { + struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch (); + gdbpy_enter enter_py (garch, current_language); + PyObject *bp_obj = (PyObject *) bp->py_bp_object; if (bp_obj) { @@ -1104,7 +1103,6 @@ gdbpy_breakpoint_modified (struct breakpoint *b) } } } - PyGILState_Release (state); }