diff options
author | Tom Tromey <tromey@redhat.com> | 2011-01-19 17:21:39 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2011-01-19 17:21:39 +0000 |
commit | 4694da01479181361c847bb9185c458e1ec51c46 (patch) | |
tree | 01db52325361b0cb5b25bb982a0e11829331aeb1 /gdb/linux-nat.c | |
parent | 6ac88ef38d4da039b342dff4c457044f924bfc8a (diff) | |
download | gdb-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/linux-nat.c')
-rw-r--r-- | gdb/linux-nat.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 62a4538..a855219 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -4078,6 +4078,43 @@ linux_nat_pid_to_str (struct target_ops *ops, ptid_t ptid) return normal_pid_to_str (ptid); } +static char * +linux_nat_thread_name (struct thread_info *thr) +{ + int pid = ptid_get_pid (thr->ptid); + long lwp = ptid_get_lwp (thr->ptid); +#define FORMAT "/proc/%d/task/%ld/comm" + char buf[sizeof (FORMAT) + 30]; + FILE *comm_file; + char *result = NULL; + + snprintf (buf, sizeof (buf), FORMAT, pid, lwp); + comm_file = fopen (buf, "r"); + if (comm_file) + { + /* Not exported by the kernel, so we define it here. */ +#define COMM_LEN 16 + static char line[COMM_LEN + 1]; + + if (fgets (line, sizeof (line), comm_file)) + { + char *nl = strchr (line, '\n'); + + if (nl) + *nl = '\0'; + if (*line != '\0') + result = line; + } + + fclose (comm_file); + } + +#undef COMM_LEN +#undef FORMAT + + return result; +} + /* Accepts an integer PID; Returns a string representing a file that can be opened to get the symbols for the child process. */ @@ -5683,6 +5720,7 @@ linux_nat_add_target (struct target_ops *t) t->to_mourn_inferior = linux_nat_mourn_inferior; t->to_thread_alive = linux_nat_thread_alive; t->to_pid_to_str = linux_nat_pid_to_str; + t->to_thread_name = linux_nat_thread_name; t->to_has_thread_control = tc_schedlock; t->to_thread_address_space = linux_nat_thread_address_space; t->to_stopped_by_watchpoint = linux_nat_stopped_by_watchpoint; |