From patchwork Fri Mar 8 15:29:37 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: 86983 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 E08C2385DC3E for ; Fri, 8 Mar 2024 16:17:31 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id B0F473858D38 for ; Fri, 8 Mar 2024 16:17:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0F473858D38 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 B0F473858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709914629; cv=none; b=WY3zV9t/09IbrxLRt0SQ+7VnN03MDjKMOugOX89z0iJ2865mhpPtzYWWWXuI70mt0Lw9nJ6AJTV6K8vRX0hMhxolyTMTv3hl59xgAITuUTLPomlmqiS6qHOp/EV3iMNInfoy1T8iNxZn0IeICXLPMZD1Y6ZaV18UYGlC9tBvFQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709914629; c=relaxed/simple; bh=OWMRYeK5xMVWnBDOO3gnlQfh1+2WNkM4ns6bojO/FvI=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=Pw3c05DR9vEP2SJ6rGJLKEVPCEuLrwBZXG4pYMqy3vSL8YqDoxCpB7LDHM6zTxUikAc1DKjVAdVPaShGF1xzMAETP7eejvIB29ouyXKkSCwke8GzShYrwPZMmmBzXh/H98ArF3ZxEUgvTwNM5IF14h7QsArPdAlTev+80fTwCzw= 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-out2.suse.de (Postfix) with ESMTPS id D729660B22 for ; Fri, 8 Mar 2024 15:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709911740; 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=Qrs4iIZnWhi8RWDZBYQNL4Hszm4zFpn3q1BpC4syihw=; b=uNR1gvKV5NwcwP9Hrzh0LaLS1Py0AE7dTXBsiMl3qe0QST3ngbGAiJQ0KVDPriCddPTj4G /Rhe8JebVaXdkn/MbLiQzAzttejj3glCGryshA2xLJLn1vqj01VuiyVJgUamdoXDd3wcij kFC9CpnbHviTE4vYNi42iXbS+Rnmdl8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709911740; 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=Qrs4iIZnWhi8RWDZBYQNL4Hszm4zFpn3q1BpC4syihw=; b=fEQ4BRm0GrlmFEDTms8kD3PS0wxVa8ovvUUejtwj0GEyqnKb38w2CEsxRjgGjCQ906tAsP ZkBp2fhdXIE/b+AA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709911740; 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=Qrs4iIZnWhi8RWDZBYQNL4Hszm4zFpn3q1BpC4syihw=; b=uNR1gvKV5NwcwP9Hrzh0LaLS1Py0AE7dTXBsiMl3qe0QST3ngbGAiJQ0KVDPriCddPTj4G /Rhe8JebVaXdkn/MbLiQzAzttejj3glCGryshA2xLJLn1vqj01VuiyVJgUamdoXDd3wcij kFC9CpnbHviTE4vYNi42iXbS+Rnmdl8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709911740; 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=Qrs4iIZnWhi8RWDZBYQNL4Hszm4zFpn3q1BpC4syihw=; b=fEQ4BRm0GrlmFEDTms8kD3PS0wxVa8ovvUUejtwj0GEyqnKb38w2CEsxRjgGjCQ906tAsP ZkBp2fhdXIE/b+AA== 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 C16D613786 for ; Fri, 8 Mar 2024 15:29:00 +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 IITdLbwu62USQwAAD6G6ig (envelope-from ) for ; Fri, 08 Mar 2024 15:29:00 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 2/3] [gdb/python] Normalize exceptions in gdbpy_err_fetch Date: Fri, 8 Mar 2024 16:29:37 +0100 Message-Id: <20240308152938.18166-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240308152938.18166-1-tdevries@suse.de> References: <20240308152938.18166-1-tdevries@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 3.69 X-Spamd-Result: default: False [3.69 / 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.999]; 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.01)[51.49%] 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, I run into: ... (gdb) PASS: gdb.python/py-block.exp: check variable access 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 ... The problem is that that PyErr_Fetch returns a normalized exception, while the test-case matches the output for an unnormalized exception. With python 3.6, PyErr_Fetch returns an unnormalized exception, and the test passes. Fix this by: - updating the test-case to match the output for a normalized exception, and - lazily forcing normalized exceptions using PyErr_NormalizeException. Tested on aarch64-linux. --- gdb/python/python-internal.h | 15 ++++++++++++++- gdb/testsuite/gdb.python/py-block.exp | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 9ceb4aa7ed4..30802ae2480 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -683,6 +683,18 @@ class gdbpy_err_fetch gdbpy_ref<> value () const { + if (!m_normalized) + { + PyObject *error_type, *error_value, *error_traceback; + error_type = m_error_type.release (); + error_value = m_error_value.release (); + error_traceback = m_error_traceback.release (); + PyErr_NormalizeException (&error_type, &error_value, &error_traceback); + m_error_type.reset (error_type); + m_error_value.reset (error_value); + m_error_traceback.reset (error_traceback); + m_normalized = true; + } return m_error_value; } @@ -695,7 +707,8 @@ class gdbpy_err_fetch private: - gdbpy_ref<> m_error_type, m_error_value, m_error_traceback; + mutable gdbpy_ref<> m_error_type, m_error_value, m_error_traceback; + mutable bool m_normalized = false; }; /* Called before entering the Python interpreter to install the diff --git a/gdb/testsuite/gdb.python/py-block.exp b/gdb/testsuite/gdb.python/py-block.exp index 942611af305..99642a546a7 100644 --- a/gdb/testsuite/gdb.python/py-block.exp +++ b/gdb/testsuite/gdb.python/py-block.exp @@ -44,7 +44,7 @@ gdb_test "python print (block.function)" "None" "first anonymous block" gdb_test "python print (block.start)" "${decimal}" "check start not None" gdb_test "python print (block.end)" "${decimal}" "check end not None" gdb_test "python print (block\['f'\].name == 'f')" "True" "check variable access" -gdb_test "python print (block\['nonexistent'\])" ".*KeyError.*: nonexistent.*" \ +gdb_test "python print (block\['nonexistent'\])" ".*KeyError.*: 'nonexistent'.*" \ "check nonexistent variable" gdb_test "python print (block\[42\])" ".*TypeError.*: Expected a string.*" \ "check non-string key"