aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
diff options
context:
space:
mode:
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 24bcb01..78cbb03 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 f9cad39..f28c1ba 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. */