From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 250BB385840A for ; Thu, 7 Dec 2023 11:02:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 250BB385840A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 250BB385840A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701946971; cv=none; b=vBf0sVzyAJ+umvmnPDJ97ewqA4HRWCX4do62Vy+1nvPz6v8qQdb2uXBn5nQAOtuJwb5piyXFZMrBK9ftdAsiIJa5L2419cG3znFE5F+lJPVyaKvs4qbI/qz8K4JxQJFb4kSIHGPzD4zTbdshpsZlFlUEyvOg6TgF0lI5/XNCwXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701946971; c=relaxed/simple; bh=MwHc7ebsIUTMSgpmuzE/Q23kUukjz5+rwuQvz7+WcUs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ttt7T0eEOlDcZhVBr4rOP2hk/A1E6AlGHPU/XYxnKM68RsGztdZxmJVkR0WE2GG/JJm7z0fNXDDyWXMh60oAzJfCD96lIbqt14sj/3oT4VDLZ/qKSZ7YtpX86rXkKOB5Br/xwVwB2hzx5m0tZHow7DP12ZjrYiVXARId1y5c04U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701946965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gItL2RIrverZJtq5PypLcDOdbTq1frEBabi6c8jW9VM=; b=Xj2WYjNcWPF2MKSbQxS4BR9XAO5Dza9PrBHdH/qwYMedWKAxpomqS9Me9lzjCYcshxZadc 7CPirmXfZIXGSyn+8wWJ2s1UuQX63aoIUtIxW2/dL2R1JtdQvd1aU8cUJw2/xGOp66L56/ aXpJVm56k7btwsNclwdLAIqJw9WptlE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-198-LkRU2f5SNO2uW8C2287i_g-1; Thu, 07 Dec 2023 06:02:44 -0500 X-MC-Unique: LkRU2f5SNO2uW8C2287i_g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6316584A2E2 for ; Thu, 7 Dec 2023 11:02:44 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.242.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE7351C00043 for ; Thu, 7 Dec 2023 11:02:43 +0000 (UTC) From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= To: gdb-patches@sourceware.org Subject: [PATCH 2/2] gdb/python: avoid use of _PyOS_ReadlineTState Date: Thu, 7 Dec 2023 12:02:40 +0100 Message-ID: <20231207110240.1853760-2-ahajkova@redhat.com> In-Reply-To: <20231207110240.1853760-1-ahajkova@redhat.com> References: <20231207110240.1853760-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Andrew Burgess In python/py-gdb-readline.c we make use of _PyOS_ReadlineTState, however, this variable is no longer public in Python 3.13, and so GDB no longer builds. We are making use of _PyOS_ReadlineTState in order to re-acquire the Python Global Interpreter Lock (GIL). The _PyOS_ReadlineTState variable is set in Python's outer readline code prior to calling the user (GDB) supplied readline callback function, which for us is gdbpy_readline_wrapper. The gdbpy_readline_wrapper function is called without the GIL held. Instead of using _PyOS_ReadlineTState, I propose that we switch to calling PyGILState_Ensure() and PyGILState_Release(). These functions will acquire the GIL based on the current thread. I think this should be sufficient; I can't imagine why we'd be running gdbpy_readline_wrapper on one thread on behalf of a different Python thread.... that would be unexpected I think. --- gdb/python/py-gdb-readline.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c index 124cec8055d..699d396dd19 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -56,13 +56,11 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout, if (except.reason == RETURN_QUIT) return NULL; - /* The thread state is nulled during gdbpy_readline_wrapper, - with the original value saved in the following undocumented - variable (see Python's Parser/myreadline.c and - Modules/readline.c). */ - PyEval_RestoreThread (_PyOS_ReadlineTState); + + /* This readline callback is called without the GIL held. */ + gdbpy_gil gil; + gdbpy_convert_exception (except); - PyEval_SaveThread (); return NULL; } -- 2.41.0