aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2011-01-19 17:21:39 +0000
committerTom Tromey <tromey@redhat.com>2011-01-19 17:21:39 +0000
commit4694da01479181361c847bb9185c458e1ec51c46 (patch)
tree01db52325361b0cb5b25bb982a0e11829331aeb1 /gdb/python
parent6ac88ef38d4da039b342dff4c457044f924bfc8a (diff)
downloadgdb-4694da01479181361c847bb9185c458e1ec51c46.zip
gdb-4694da01479181361c847bb9185c458e1ec51c46.tar.gz
gdb-4694da01479181361c847bb9185c458e1ec51c46.tar.bz2
gdb
PR mi/8618: * thread.c (free_thread): Free 'name'. (print_thread_info): Emit thread name. Change CLI output. (thread_name_command): New function. (do_captured_thread_select): Emit newline. (_initialize_thread): Register 'thread name' command. * target.h (struct target_ops) <to_thread_name>: New field. (target_thread_name): New macro. * target.c (update_current_target): Handle to_thread_name. * python/py-infthread.c (thpy_get_name): New function. (thpy_set_name): Likewise. (thread_object_getset): Add "name". * linux-nat.c (linux_nat_thread_name): New function. (linux_nat_add_target): Set to_thread_name. * gdbthread.h (struct thread_info) <name>: New field. gdb/doc * gdb.texinfo (Threads): Document thread name output and `thread name' command. (Threads In Python): Document Thread.name attribute. (GDB/MI Thread Commands): Document thread attributes. gdb/testsuite * gdb.python/py-infthread.exp: Add thread tests.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-infthread.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 46637d0..059422d 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -64,6 +64,63 @@ thpy_dealloc (PyObject *self)
}
static PyObject *
+thpy_get_name (PyObject *self, void *ignore)
+{
+ thread_object *thread_obj = (thread_object *) self;
+ char *name;
+
+ THPY_REQUIRE_VALID (thread_obj);
+
+ name = thread_obj->thread->name;
+ if (name == NULL)
+ name = target_thread_name (thread_obj->thread);
+
+ if (name == NULL)
+ Py_RETURN_NONE;
+
+ return PyString_FromString (name);
+}
+
+static int
+thpy_set_name (PyObject *self, PyObject *newvalue, void *ignore)
+{
+ thread_object *thread_obj = (thread_object *) self;
+ char *name;
+
+ if (! thread_obj->thread)
+ {
+ PyErr_SetString (PyExc_RuntimeError, _("Thread no longer exists."));
+ return -1;
+ }
+
+ if (newvalue == NULL)
+ {
+ PyErr_SetString (PyExc_TypeError,
+ _("Cannot delete `name' attribute."));
+ return -1;
+ }
+ else if (newvalue == Py_None)
+ name = NULL;
+ else if (! gdbpy_is_string (newvalue))
+ {
+ PyErr_SetString (PyExc_TypeError,
+ _("The value of `name' must be a string."));
+ return -1;
+ }
+ else
+ {
+ name = python_string_to_host_string (newvalue);
+ if (! name)
+ return -1;
+ }
+
+ xfree (thread_obj->thread->name);
+ thread_obj->thread->name = name;
+
+ return 0;
+}
+
+static PyObject *
thpy_get_num (PyObject *self, void *closure)
{
thread_object *thread_obj = (thread_object *) self;
@@ -201,6 +258,8 @@ gdbpy_initialize_thread (void)
static PyGetSetDef thread_object_getset[] =
{
+ { "name", thpy_get_name, thpy_set_name,
+ "The name of the thread, as set by the user or the OS.", NULL },
{ "num", thpy_get_num, NULL, "ID of the thread, as assigned by GDB.", NULL },
{ "ptid", thpy_get_ptid, NULL, "ID of the thread, as assigned by the OS.",
NULL },