]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/python] Use gdbpy_err_fetch::{type,value} as getters
authorTom de Vries <tdevries@suse.de>
Sat, 9 Mar 2024 15:13:10 +0000 (16:13 +0100)
committerTom de Vries <tdevries@suse.de>
Sat, 9 Mar 2024 15:13:10 +0000 (16:13 +0100)
Similar to gdbpy_err_fetch::value, add a getter gdbpy_err_fetch::type, and use
both consistently to get gdbpy_err_fetch members m_error_value and
m_error_type.

Tested on aarch64-linux.

gdb/python/py-utils.c
gdb/python/python-internal.h

index 9382eb62a5fe5bc69c57fb11aee682b29f2d5800..3fcf48f79988a72f5032408f736f407260f438bc 100644 (file)
@@ -195,10 +195,11 @@ gdbpy_err_fetch::to_string () const
      Using str (aka PyObject_Str) will fetch the error message from
      gdb.GdbError ("message").  */
 
-  if (m_error_value.get () != nullptr && m_error_value.get () != Py_None)
-    return gdbpy_obj_to_string (m_error_value.get ());
+  gdbpy_ref<> value = this->value ();
+  if (value.get () != nullptr && value.get () != Py_None)
+    return gdbpy_obj_to_string (value.get ());
   else
-    return gdbpy_obj_to_string (m_error_type.get ());
+    return gdbpy_obj_to_string (this->type ().get ());
 }
 
 /* See python-internal.h.  */
@@ -206,7 +207,7 @@ gdbpy_err_fetch::to_string () const
 gdb::unique_xmalloc_ptr<char>
 gdbpy_err_fetch::type_to_string () const
 {
-  return gdbpy_obj_to_string (m_error_type.get ());
+  return gdbpy_obj_to_string (this->type ().get ());
 }
 
 /* Convert a GDB exception to the appropriate Python exception.
index c68aff5340e7b5295c700e559838df3d59d408b8..9ceb4aa7ed4d91c414c5ae8f3791ce01e85f2127 100644 (file)
@@ -675,16 +675,24 @@ public:
 
   bool type_matches (PyObject *type) const
   {
-    return PyErr_GivenExceptionMatches (m_error_type.get (), type);
+    gdbpy_ref<> err_type = this->type ();
+    return PyErr_GivenExceptionMatches (err_type.get (), type);
   }
 
   /* Return a new reference to the exception value object.  */
 
-  gdbpy_ref<> value ()
+  gdbpy_ref<> value () const
   {
     return m_error_value;
   }
 
+  /* Return a new reference to the exception type object.  */
+
+  gdbpy_ref<> type () const
+  {
+    return m_error_type;
+  }
+
 private:
 
   gdbpy_ref<> m_error_type, m_error_value, m_error_traceback;