]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/python: hoist common invalid object repr code into py-utils.c
authorAndrew Burgess <aburgess@redhat.com>
Thu, 4 Jan 2024 10:07:48 +0000 (10:07 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 12 Jan 2024 11:21:25 +0000 (11:21 +0000)
commitaef117b7374053099099600ded2f4eaa2c450327
treec376f0ba3cff2ee35ce0e97a7fd32c898eab4ca4
parent3b9ff5d9009d587aa76ec7bbaab4439e26a52c50
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>
gdb/python/py-arch.c
gdb/python/py-block.c
gdb/python/py-breakpoint.c
gdb/python/py-connection.c
gdb/python/py-inferior.c
gdb/python/py-objfile.c
gdb/python/py-symbol.c
gdb/python/py-type.c
gdb/python/py-unwind.c
gdb/python/py-utils.c
gdb/python/python-internal.h