Commits

Anonymous committed dbff67a

Display the thread name on Linux systems

  • Participants
  • Parent commits 65ef7e4

Comments (0)

Files changed (3)

 
   if (args->suppress) return;
 
-  printf("Thread %d (LWP %d)\n", args->nthread, thread->lwpid);
+  printf("Thread %d (LWP %d) %s\n", args->nthread,
+      thread->lwpid, thread->name);
   for (args->nframe = 0; args->nframe < num_frames; args->nframe++) {
     args->suppress = 0;
     gimli_visit_modules(should_suppress_frame, args);
   int lwpid;
 
   int valid;
+  char name[32];
 #if defined(__linux__)
   struct user_regs_struct regs;
 #elif defined(sun)
     thr->lwpid = lwpid;
     thr->proc = proc;
 
+#ifdef __linux__
+    {
+      int fd, ret;
+      char buffer[1024];
+
+      /* load the thread name */
+      snprintf(buffer, sizeof(buffer),
+          "/proc/%d/task/%d/comm", proc->pid, lwpid);
+      fd = open(buffer, O_RDONLY);
+      if (fd >= 0) {
+        ret = read(fd, thr->name, sizeof(thr->name));
+        while (ret > 0 && isspace(thr->name[ret-1])) {
+          ret--;
+        }
+        thr->name[ret] = '\0';
+        close(fd);
+      }
+    }
+#endif
+
     STAILQ_INSERT_TAIL(&proc->threads, thr, threadlist);
     return thr;
   }