summaryrefslogtreecommitdiff
path: root/gdb/python/py-disasm.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python/py-disasm.c')
-rw-r--r--gdb/python/py-disasm.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c
index 6b19b556d0d..eeb16d8650c 100644
--- a/gdb/python/py-disasm.c
+++ b/gdb/python/py-disasm.c
@@ -247,6 +247,21 @@ disasm_info_dealloc (PyObject *self)
Py_TYPE (self)->tp_free (self);
}
+/* Implement __repr__ for the DisassembleInfo type. */
+
+static PyObject *
+disasmpy_info_repr (PyObject *self)
+{
+ disasm_info_object *obj = (disasm_info_object *) self;
+
+ const char *arch_name
+ = (gdbarch_bfd_arch_info (obj->gdbarch))->printable_name;
+ return PyUnicode_FromFormat ("<%s address=%s architecture=%s>",
+ Py_TYPE (obj)->tp_name,
+ core_addr_to_string_nz (obj->address),
+ arch_name);
+}
+
/* Implement DisassembleInfo.is_valid(), really just a wrapper around the
disasm_info_object_is_valid function above. */
@@ -653,6 +668,21 @@ disasmpy_result_init (PyObject *self, PyObject *args, PyObject *kwargs)
return 0;
}
+/* Implement __repr__ for the DisassemblerResult type. */
+
+static PyObject *
+disasmpy_result_repr (PyObject *self)
+{
+ disasm_result_object *obj = (disasm_result_object *) self;
+
+ gdb_assert (obj->content != nullptr);
+
+ return PyUnicode_FromFormat ("<%s length=%d string=\"%s\">",
+ Py_TYPE (obj)->tp_name,
+ obj->length,
+ obj->content->string ().c_str ());
+}
+
/* Implement memory_error_func callback for disassemble_info. Extract the
underlying DisassembleInfo Python object, and set a memory error on
it. */
@@ -1069,7 +1099,7 @@ PyTypeObject disasm_info_object_type = {
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
- 0, /*tp_repr*/
+ disasmpy_info_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
@@ -1111,7 +1141,7 @@ PyTypeObject disasm_result_object_type = {
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
- 0, /*tp_repr*/
+ disasmpy_result_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/