mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-18 00:37:28 +08:00
gdb/python: add gdb.InferiorThread.__repr__() method
Add a gdb.InferiorThread.__repr__() method. Before this patch we would see output like this: (gdb) pi >>> gdb.selected_thread() <gdb.InferiorThread object at 0x7f4dcc49b970> After this patch, we now see: (gdb) pi >>> gdb.selected_thread() <gdb.InferiorThread id=1.2 target-id="Thread 0x7ffff7da1700 (LWP 458134)"> More verbose, but, I hope, more useful. If the gdb.InferiorThread becomes invalid, then we will see: (gdb) pi >>> invalid_thread_variable <gdb.InferiorThread (invalid)> Which is inline with how other invalid objects are displayed. Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
@@ -337,6 +337,23 @@ thpy_thread_handle (PyObject *self, PyObject *args)
|
||||
return object;
|
||||
}
|
||||
|
||||
/* Implement repr() for gdb.InferiorThread. */
|
||||
|
||||
static PyObject *
|
||||
thpy_repr (PyObject *self)
|
||||
{
|
||||
thread_object *thread_obj = (thread_object *) self;
|
||||
|
||||
if (thread_obj->thread == nullptr)
|
||||
return gdb_py_invalid_object_repr (self);
|
||||
|
||||
thread_info *thr = thread_obj->thread;
|
||||
return PyUnicode_FromFormat ("<%s id=%s target-id=\"%s\">",
|
||||
Py_TYPE (self)->tp_name,
|
||||
print_full_thread_id (thr),
|
||||
target_pid_to_str (thr->ptid).c_str ());
|
||||
}
|
||||
|
||||
/* Return a reference to a new Python object representing a ptid_t.
|
||||
The object is a tuple containing (pid, lwp, tid). */
|
||||
PyObject *
|
||||
@@ -456,7 +473,7 @@ PyTypeObject thread_object_type =
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
thpy_repr, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
|
||||
Reference in New Issue
Block a user