From 50ede76876981364d6b1a314bb79c0412980c435 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Sat, 9 Mar 2024 16:13:10 +0100 Subject: [gdb/python] Normalize exceptions in gdbpy_err_fetch 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. Approved-By: Tom Tromey --- gdb/python/python-internal.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'gdb/python') diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 9ceb4aa..30802ae 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -683,6 +683,18 @@ public: 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 @@ public: 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 -- cgit v1.1