public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] [gdb/python] Use gdbpy_err_fetch::{type,value} as getters
@ 2024-03-08 15:29 Tom de Vries
  2024-03-08 15:29 ` [PATCH v2 2/3] [gdb/python] Normalize exceptions in gdbpy_err_fetch Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tom de Vries @ 2024-03-08 15:29 UTC (permalink / raw)
  To: gdb-patches

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        |  8 ++++----
 gdb/python/python-internal.h | 12 ++++++++++--
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 9382eb62a5f..4fbdb695a50 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -195,10 +195,10 @@ 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 ());
+  if (this->value ().get () != nullptr && this->value ().get () != Py_None)
+    return gdbpy_obj_to_string (this->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 +206,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.
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index c68aff5340e..9ceb4aa7ed4 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -675,16 +675,24 @@ class gdbpy_err_fetch
 
   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;

base-commit: cdabd12b186e8e794045372b753416a18c387d7b
-- 
2.35.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-03-09 15:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08 15:29 [PATCH v2 1/3] [gdb/python] Use gdbpy_err_fetch::{type,value} as getters Tom de Vries
2024-03-08 15:29 ` [PATCH v2 2/3] [gdb/python] Normalize exceptions in gdbpy_err_fetch Tom de Vries
2024-03-08 20:21   ` Tom Tromey
2024-03-09 15:11     ` Tom de Vries
2024-03-08 15:29 ` [PATCH v2 3/3] [gdb/python] Handle deprecation of PyErr_{Fetch,Restore} in 3.12 Tom de Vries
2024-03-08 20:22   ` [PATCH v2 3/3] [gdb/python] Handle deprecation of PyErr_{Fetch, Restore} " Tom Tromey
2024-03-08 20:20 ` [PATCH v2 1/3] [gdb/python] Use gdbpy_err_fetch::{type, value} as getters Tom Tromey
2024-03-09 15:09   ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).