public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/python] Use gdbpy_err_fetch::{type,value} as getters
@ 2024-03-09 15:12 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2024-03-09 15:12 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b1abf8b1b93b5ccdcd400b925dd9046b80f0c32b
commit b1abf8b1b93b5ccdcd400b925dd9046b80f0c32b
Author: Tom de Vries <tdevries@suse.de>
Date: Sat Mar 9 16:13:10 2024 +0100
[gdb/python] Use gdbpy_err_fetch::{type,value} as getters
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.
Diff:
---
gdb/python/py-utils.c | 9 +++++----
gdb/python/python-internal.h | 12 ++++++++++--
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 9382eb62a5f..3fcf48f7998 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -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.
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 @@ 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-03-09 15:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-09 15:12 [binutils-gdb] [gdb/python] Use gdbpy_err_fetch::{type,value} as getters 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).