mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-08-06 14:49:38 +08:00
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).
This commit is contained in:

committed by
Andrew Burgess

parent
b8c2de06bc
commit
bb2bd584f3
@ -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 */
|
||||
|
Reference in New Issue
Block a user