aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-block.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2024-01-04 10:07:48 +0000
committerAndrew Burgess <aburgess@redhat.com>2024-01-12 11:21:25 +0000
commitaef117b7374053099099600ded2f4eaa2c450327 (patch)
treec376f0ba3cff2ee35ce0e97a7fd32c898eab4ca4 /gdb/python/py-block.c
parent3b9ff5d9009d587aa76ec7bbaab4439e26a52c50 (diff)
downloadbinutils-aef117b7374053099099600ded2f4eaa2c450327.zip
binutils-aef117b7374053099099600ded2f4eaa2c450327.tar.gz
binutils-aef117b7374053099099600ded2f4eaa2c450327.tar.bz2
gdb/python: hoist common invalid object repr code into py-utils.c
Many object types now have a __repr__() function implementation. A common pattern is that, if an object is invalid, we print its representation as: <TYPENAME (invalid)>. I thought it might be a good idea to move the formatting of this specific representation into a utility function, and then update all of our existing code to call the new function. The only place where I haven't made use of the new function is in unwind_infopy_repr, where we currently return a different string. This case is a little different as the UnwindInfo is invalid because it references a frame, and it is the frame itself which is invalid. That said, I think it would be fine to switch to using the standard format; if the UnwindInfo references an invalid frame, then the UnwindInfo is itself invalid. But changing this would be an actual change in behaviour, while all the other changes in this commit are just refactoring. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python/py-block.c')
-rw-r--r--gdb/python/py-block.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index dd6d6d2..34be466 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -425,7 +425,7 @@ blpy_repr (PyObject *self)
{
const auto block = block_object_to_block (self);
if (block == nullptr)
- return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name);
+ return gdb_py_invalid_object_repr (self);
const auto name = block->function () ?
block->function ()->print_name () : "<anonymous>";