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 @@ 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 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"