aboutsummaryrefslogtreecommitdiff
path: root/gdb/linux-nat.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/linux-nat.c')
-rw-r--r--gdb/linux-nat.c38
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;