From patchwork Mon Mar 4 16:03:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 86748 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 499223858426 for ; Mon, 4 Mar 2024 16:03:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 3B25D3858D33 for ; Mon, 4 Mar 2024 16:03:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B25D3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3B25D3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709568211; cv=none; b=m2amCm8k1dxuzQo4A9b5VopWlhAxIx6+t26h0VKbP8u5Iza741zgG7dfXdJrmH6CicxTVFsxFzi1PtBbuYRVhiUBXNyk+YfZH+3DD6jvpnwdtRbun1hQxU8AYqYW7Bo1I7TUbibX8nfkb1jdXGMZf5pZLKork28eRtbgUM5EXkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709568211; c=relaxed/simple; bh=VNi2BXpVXMuwaLYeiWXwcS4gdWdwarPg1H0klH7Uu00=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=vOGrdlwySkfZUwlqZnZUQ/cCxvU4MvKR3r5/mpxx9OxzzCBChQgUslCiqltoX9NKqtxubUSw3A2TQ1ZDJnV9O0kQqKN7+bjsR5QT3VbYnm3yVCwqQJpaTossIvv7wY6LwsP9DILhvQXHEVxN2SNOgR+WJRchtJwXZIo3BEghojA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3EAC222B6F for ; Mon, 4 Mar 2024 16:03:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709568200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4FeUVLehhk7oZ/Xu1fzzrWPkv2nkjzRdUql0TMwMxT0=; b=fMAT+72N2fqf39Ex9wC3mnJRhXc40S7xcwuyCRl64OZfD4tLw1UBNjBysPyRQpgn07t80O EEGLRzpEGHavrjYdJjUPPKBJ+jyERBssOWvRg3BaTVaqgAMpi91NT9uo82h4MGY1ZQsTZW qI2KcZlROc8Z8YT3+c5IuTCGp1bk/4o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709568200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4FeUVLehhk7oZ/Xu1fzzrWPkv2nkjzRdUql0TMwMxT0=; b=rSod3gdkm8nmAV+tu0PcjhjSzlRvRczqBsktMhYLRKFV2mLQbujmhKhKev+y5sqQPeT/pO nMyVTxCFEQmHkADg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709568200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4FeUVLehhk7oZ/Xu1fzzrWPkv2nkjzRdUql0TMwMxT0=; b=fMAT+72N2fqf39Ex9wC3mnJRhXc40S7xcwuyCRl64OZfD4tLw1UBNjBysPyRQpgn07t80O EEGLRzpEGHavrjYdJjUPPKBJ+jyERBssOWvRg3BaTVaqgAMpi91NT9uo82h4MGY1ZQsTZW qI2KcZlROc8Z8YT3+c5IuTCGp1bk/4o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709568200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=4FeUVLehhk7oZ/Xu1fzzrWPkv2nkjzRdUql0TMwMxT0=; b=rSod3gdkm8nmAV+tu0PcjhjSzlRvRczqBsktMhYLRKFV2mLQbujmhKhKev+y5sqQPeT/pO nMyVTxCFEQmHkADg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2832013A58 for ; Mon, 4 Mar 2024 16:03:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id v76OCMjw5WWvdAAAD6G6ig (envelope-from ) for ; Mon, 04 Mar 2024 16:03:20 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 1/2] [gdb/python] Handle normalized exception returned by PyErr_Fetch Date: Mon, 4 Mar 2024 17:03:46 +0100 Message-Id: <20240304160347.31182-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sourceware.org:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 1.90 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org With python 3.12 and test-case gdb.python/py-block.exp, before commit a207f6b3a38 ("Rewrite "python" command exception handling"), we had: ... (gdb) python print (block['nonexistent'])^M Traceback (most recent call last):^M File "", line 1, in ^M KeyError: 'nonexistent'^M Error while executing Python code.^M (gdb) PASS: gdb.python/py-block.exp: check nonexistent variable ... but after the commit we have: ... (gdb) python print (block['nonexistent'])^M Python Exception : 'nonexistent'^M Error occurred in Python: 'nonexistent'^M (gdb) FAIL: gdb.python/py-block.exp: check nonexistent variable ... In contrast, with python 3.6 we have: ... (gdb) python print (block['nonexistent'])^M Python Exception : nonexistent^M Error occurred in Python: nonexistent^M (gdb) PASS: gdb.python/py-block.exp: check nonexistent variable ... The change in the test-case is: ... -gdb_test "python print (block\['nonexistent'\])" ".*KeyError: 'nonexistent'.*" \ +gdb_test "python print (block\['nonexistent'\])" ".*KeyError.*: nonexistent.*" \ "check nonexistent variable" ... which drops the single quotes around the nonexistent string, which matches the output with python 3.6, but not with python 3.12. The difference is caused by a difference in the result of PyErr_Fetch. [ PyErr_Fetch is deprecated in python 3.12, this will be addressed in a follow-up commit. ] With python 3.6, we have PyErr_Fetch returning: ... (gdb) p PyObject_Print(error_value, stderr, 0) 'nonexistent'$3 = 0 (gdb) p PyObject_Print(error_value, stderr, 1) nonexistent$4 = 0 ... but with python 3.12, we have instead: ... (gdb) p (int)PyObject_Print(error_value,stderr, 0) KeyError('nonexistent')$3 = 0 (gdb) p (int)PyObject_Print(error_value,stderr, 1) 'nonexistent'$4 = 0 ... In more detail, with python 3.12 we get a normalized exception, so the error_value is an object of class KeyError. With python 3.6, error_value is an unnormalized exception, meaning not of class KeyError. Apparantly we rely here on PyErr_Fetch to return an unnormalized exception. Fix this by pretending to have an unnormalized exception in gdbpy_err_fetch::to_string. Tested on aarch64-linux. PR python/31425 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31425 --- gdb/python/py-utils.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) base-commit: 1485a3fb63619cced99dd7a4a043cf01a0f423d9 diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 9382eb62a5f..8eee33f89bb 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -196,7 +196,19 @@ gdbpy_err_fetch::to_string () const gdb.GdbError ("message"). */ if (m_error_value.get () != nullptr && m_error_value.get () != Py_None) - return gdbpy_obj_to_string (m_error_value.get ()); + { + if ((PyObject *)Py_TYPE (m_error_value.get ()) == m_error_type.get ()) + { + /* Detected a normalized exception. */ + PyObject *args = PyException_GetArgs (m_error_value.get ()); + if (PyTuple_Size (args) == 1) + { + /* Pretend to be looking at an unnormalized exception. */ + return gdbpy_obj_to_string (PyTuple_GetItem (args, 0)); + } + } + return gdbpy_obj_to_string (m_error_value.get ()); + } else return gdbpy_obj_to_string (m_error_type.get ()); } From patchwork Mon Mar 4 16:03:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 86747 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 055A13858288 for ; Mon, 4 Mar 2024 16:03:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 3B0963858D28 for ; Mon, 4 Mar 2024 16:03:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B0963858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3B0963858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709568211; cv=none; b=BWncRI4UHT3XCUdsrmyHzCRx+uQP0EHOhpFOa9e0b7PldcrQMmcGq5Qif4SXCNO2VdZs5oU4fmPGUfs69NGyHzcBj34E7hWx6bM/zwqDznN2LPsn34tPTMiWiYIZGEnEj6wujeo0RtqXWo59WIUdhfzPcp0y1vYWK4C41AXdSu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709568211; c=relaxed/simple; bh=mvvx0k2E3DThXeW8xv5xeGqBTS2ITPez+YyUqqeA4j4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=R8G9Q9ixbdD/Z031fLuNX4ow0Q/lGgVozgX9ppQgpVM/Q/xQ88G4pGfEgL4fb17FxQTBS/M0OKJ6xmiTjX9kLSqPzIlOYwpo16lmkrnJG4S+sWcu6OWrTv0erGqlwfGuu4Ff/vwezo0Mb7miR9twjk1yPQ0IOEY/K3/kSbTVMkA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5A67A22BDB for ; Mon, 4 Mar 2024 16:03:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709568200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VGlTIPcDnH+ym6zOe/JZkODjfuKVzQ3rHmcSVfsVypw=; b=TgHLqqketBVDDqQZixEwjYIZu1CBkMDJa5/9l2azupil6aSFH/81mb9I+bjMymgPzVIod4 pQ/sJ4JRzENEZ+uXHLngEds7+0BNYBBbx+p1lqi3Z2mHXQTPX0HAD//lMONk2Ft28m0woh GFZq0cI+Pf3CvIig5GlmHYkZtjXvLtc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709568200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VGlTIPcDnH+ym6zOe/JZkODjfuKVzQ3rHmcSVfsVypw=; b=vCfl2e9VF/JxrqG83MIUq3LduPc+dVJ+pi2hxagq7vxq9ZeAh76i7ijPD2uKlwGLvnj7fs RV4c+Br9udJ7nUDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709568200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VGlTIPcDnH+ym6zOe/JZkODjfuKVzQ3rHmcSVfsVypw=; b=TgHLqqketBVDDqQZixEwjYIZu1CBkMDJa5/9l2azupil6aSFH/81mb9I+bjMymgPzVIod4 pQ/sJ4JRzENEZ+uXHLngEds7+0BNYBBbx+p1lqi3Z2mHXQTPX0HAD//lMONk2Ft28m0woh GFZq0cI+Pf3CvIig5GlmHYkZtjXvLtc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709568200; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VGlTIPcDnH+ym6zOe/JZkODjfuKVzQ3rHmcSVfsVypw=; b=vCfl2e9VF/JxrqG83MIUq3LduPc+dVJ+pi2hxagq7vxq9ZeAh76i7ijPD2uKlwGLvnj7fs RV4c+Br9udJ7nUDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 42F3813AC2 for ; Mon, 4 Mar 2024 16:03:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id cHYoD8jw5WWvdAAAD6G6ig (envelope-from ) for ; Mon, 04 Mar 2024 16:03:20 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 2/2] [gdb/python] Handle deprecation of PyErr_{Fetch, Restore} in 3.12 Date: Mon, 4 Mar 2024 17:03:47 +0100 Message-Id: <20240304160347.31182-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240304160347.31182-1-tdevries@suse.de> References: <20240304160347.31182-1-tdevries@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 3.66 X-Spamd-Result: default: False [3.66 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.996]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.04)[57.85%] X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Starting python version 3.12, PyErr_Fetch and PyErr_Restore are deprecated. Use PyErr_GetRaisedException and PyErr_SetRaisedException instead, for python >= 3.12. This causes a regression in gdb.python/py-mi-cmd.exp: ... -pycmd exp^M ^error,msg=""^M (gdb) ^M FAIL: gdb.python/py-mi-cmd.exp: -pycmd exp (unexpected output) ... where a gdbError with missing message goes undetected because it's in unnormalized form. Fix this by detecting the unnormalized from in gdbpy_err_fetch::to_string. Tested on aarch64-linux. --- gdb/python/py-utils.c | 7 +++++++ gdb/python/python-internal.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 8eee33f89bb..23afb9be353 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -195,6 +195,13 @@ gdbpy_err_fetch::to_string () const Using str (aka PyObject_Str) will fetch the error message from gdb.GdbError ("message"). */ + if (type_matches (gdbpy_gdberror_exc) && m_error_value.get () == nullptr) + { + /* We have an unnormalized gdb.GdbError with missing message, make sure + gdbpy_handle_exception flags it as such.*/ + return nullptr; + } + if (m_error_value.get () != nullptr && m_error_value.get () != Py_None) { if ((PyObject *)Py_TYPE (m_error_value.get ()) == m_error_type.get ()) diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index c68aff5340e..40084d76502 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -640,12 +640,36 @@ class gdbpy_err_fetch gdbpy_err_fetch () { +#if PY_VERSION_HEX < 0x030c0000 PyObject *error_type, *error_value, *error_traceback; PyErr_Fetch (&error_type, &error_value, &error_traceback); m_error_type.reset (error_type); m_error_value.reset (error_value); m_error_traceback.reset (error_traceback); +#else + /* PyErr_Fetch is deprecated in python 3.12, use PyErr_GetRaisedException + instead. */ + PyObject *exc = PyErr_GetRaisedException (); + m_exc.reset (exc); + if (exc == nullptr) + { + m_error_type.reset (nullptr); + m_error_value.reset (nullptr); + m_error_traceback.reset (nullptr); + return; + } + + m_error_type = gdbpy_ref<>::new_reference ((PyObject *)Py_TYPE (exc)); + + PyObject *args = PyException_GetArgs (exc); + if (PyTuple_Size (args) >= 1) + m_error_value = gdbpy_ref<>::new_reference (PyTuple_GetItem (args, 0)); + else + m_error_value.reset (nullptr); + + m_error_traceback.reset (PyException_GetTraceback (exc)); +#endif } /* Call PyErr_Restore using the values stashed in this object. @@ -654,9 +678,18 @@ class gdbpy_err_fetch void restore () { +#if PY_VERSION_HEX < 0x030c0000 PyErr_Restore (m_error_type.release (), m_error_value.release (), m_error_traceback.release ()); +#else + /* PyErr_Restore is deprecated in python 3.12, use PyErr_SetRaisedException + instead. */ + m_error_type.reset (nullptr); + m_error_value.reset (nullptr); + m_error_traceback.reset (nullptr); + PyErr_SetRaisedException (m_exc.release ()); +#endif } /* Return the string representation of the exception represented by @@ -688,6 +721,9 @@ class gdbpy_err_fetch private: gdbpy_ref<> m_error_type, m_error_value, m_error_traceback; +#if PY_VERSION_HEX >= 0x030c0000 + gdbpy_ref<> m_exc; +#endif }; /* Called before entering the Python interpreter to install the