diff options
author | Matheus Branco Borella <dark.ryu.550@gmail.com> | 2023-05-18 00:33:57 -0300 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2023-07-04 12:07:16 +0100 |
commit | bb2bd584f31a25ba1cfe5bdac4d07d8cffe87c3d (patch) | |
tree | 8dac0966bc63e625f87af8e1a6a2243e15df3803 /gdb/python/py-arch.c | |
parent | b8c2de06bcbc13a1a6b93163cf675272d7eada9f (diff) | |
download | binutils-bb2bd584f31a25ba1cfe5bdac4d07d8cffe87c3d.zip binutils-bb2bd584f31a25ba1cfe5bdac4d07d8cffe87c3d.tar.gz binutils-bb2bd584f31a25ba1cfe5bdac4d07d8cffe87c3d.tar.bz2 |
gdb: add __repr__() implementation to a few Python types
Only a few types in the Python API currently have __repr__()
implementations. This patch adds a few more of them. specifically: it
adds __repr__() implementations to gdb.Symbol, gdb.Architecture,
gdb.Block, gdb.Breakpoint, gdb.BreakpointLocation, and gdb.Type.
This makes it easier to play around the GDB Python API in the Python
interpreter session invoked with the 'pi' command in GDB, giving more
easily accessible tipe information to users.
An example of how this would look like:
(gdb) pi
>> gdb.lookup_type("char")
<gdb.Type code=TYPE_CODE_INT name=char>
>> gdb.lookup_global_symbol("main")
<gdb.Symbol print_name=main>
The gdb.Block.__repr__() method shows the first 5 symbols from the
block, and then a message to show how many more were elided (if any).
Diffstat (limited to 'gdb/python/py-arch.c')
-rw-r--r-- | gdb/python/py-arch.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 4d133d1..ac51933 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -319,6 +319,21 @@ archpy_integer_type (PyObject *self, PyObject *args, PyObject *kw) return type_to_type_object (type); } +/* __repr__ implementation for gdb.Architecture. */ + +static PyObject * +archpy_repr (PyObject *self) +{ + const auto gdbarch = arch_object_to_gdbarch (self); + if (gdbarch == nullptr) + return PyUnicode_FromFormat ("<%s (invalid)>", Py_TYPE (self)->tp_name); + + auto arch_info = gdbarch_bfd_arch_info (gdbarch); + return PyUnicode_FromFormat ("<%s arch_name=%s printable_name=%s>", + Py_TYPE (self)->tp_name, arch_info->arch_name, + arch_info->printable_name); +} + /* Implementation of gdb.architecture_names(). Return a list of all the BFD architecture names that GDB understands. */ @@ -395,7 +410,7 @@ PyTypeObject arch_object_type = { 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_compare */ - 0, /* tp_repr */ + archpy_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ |