aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2015-11-26 09:49:04 -0500
committerSimon Marchi <simon.marchi@ericsson.com>2015-11-26 10:50:08 -0500
commit79efa585c51f0657b319beb1e213d5721eaacdcc (patch)
tree9aad1092fe7553087c7cffb036422864870f6c56 /gdb/nat
parent73ede76585a987a07fbd67a7474b193e4ca05517 (diff)
Display names of remote threads
This patch adds support for thread names in the remote protocol, and updates gdb/gdbserver to use it. The information is added to the XML description sent in response to the qXfer:threads:read packet. gdb/ChangeLog: * linux-nat.c (linux_nat_thread_name): Replace implementation by call to linux_proc_tid_get_name. * nat/linux-procfs.c (linux_proc_tid_get_name): New function, implementation inspired by linux_nat_thread_name. * nat/linux-procfs.h (linux_proc_tid_get_name): New declaration. * remote.c (struct private_thread_info) <name>: New field. (free_private_thread_info): Free name field. (remote_thread_name): New function. (thread_item_t) <name>: New field. (clear_threads_listing_context): Free name field. (start_thread): Get name xml attribute. (thread_attributes): Add "name" attribute. (remote_update_thread_list): Copy name field. (init_remote_ops): Assign remote_thread_name callback. * target.h (target_thread_name): Update comment. * NEWS: Mention remote thread name support. gdb/gdbserver/ChangeLog: * linux-low.c (linux_target_ops): Use linux_proc_tid_get_name. * server.c (handle_qxfer_threads_worker): Refactor to include thread name in reply. * target.h (struct target_ops) <thread_name>: New field. (target_thread_name): New macro. gdb/doc/ChangeLog: * gdb.texinfo (Thread List Format): Mention thread names.
Diffstat (limited to 'gdb/nat')
-rw-r--r--gdb/nat/linux-procfs.c42
-rw-r--r--gdb/nat/linux-procfs.h7
2 files changed, 49 insertions, 0 deletions
diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c
index 24bcb019a3..78cbb03cb2 100644
--- a/gdb/nat/linux-procfs.c
+++ b/gdb/nat/linux-procfs.c
@@ -187,6 +187,48 @@ linux_proc_pid_is_zombie (pid_t pid)
/* See linux-procfs.h. */
+const char *
+linux_proc_tid_get_name (ptid_t ptid)
+{
+#define TASK_COMM_LEN 16 /* As defined in the kernel's sched.h. */
+
+ static char comm_buf[TASK_COMM_LEN];
+ char comm_path[100];
+ FILE *comm_file;
+ const char *comm_val;
+ pid_t pid = ptid_get_pid (ptid);
+ pid_t tid = ptid_lwp_p (ptid) ? ptid_get_lwp (ptid) : ptid_get_pid (ptid);
+
+ xsnprintf (comm_path, sizeof (comm_path),
+ "/proc/%ld/task/%ld/comm", (long) pid, (long) tid);
+
+ comm_file = gdb_fopen_cloexec (comm_path, "r");
+ if (comm_file == NULL)
+ return NULL;
+
+ comm_val = fgets (comm_buf, sizeof (comm_buf), comm_file);
+ fclose (comm_file);
+
+ if (comm_val != NULL)
+ {
+ int i;
+
+ /* Make sure there is no newline at the end. */
+ for (i = 0; i < sizeof (comm_buf); i++)
+ {
+ if (comm_buf[i] == '\n')
+ {
+ comm_buf[i] = '\0';
+ break;
+ }
+ }
+ }
+
+ return comm_val;
+}
+
+/* See linux-procfs.h. */
+
void
linux_proc_attach_tgid_threads (pid_t pid,
linux_proc_attach_lwp_func attach_lwp)
diff --git a/gdb/nat/linux-procfs.h b/gdb/nat/linux-procfs.h
index f9cad39562..f28c1ba344 100644
--- a/gdb/nat/linux-procfs.h
+++ b/gdb/nat/linux-procfs.h
@@ -54,6 +54,13 @@ extern int linux_proc_pid_is_zombie_nowarn (pid_t pid);
extern int linux_proc_pid_is_gone (pid_t pid);
+/* Return a string giving the thread's name or NULL if the
+ information is unavailable. The returned value points to a statically
+ allocated buffer. The value therefore becomes invalid at the next
+ linux_proc_tid_get_name call. */
+
+extern const char *linux_proc_tid_get_name (ptid_t ptid);
+
/* Callback function for linux_proc_attach_tgid_threads. If the PTID
thread is not yet known, try to attach to it and return true,
otherwise return false. */