Date: Thu, 17 Jan 2008 20:41:53 -0500 From: Ed Maste <emaste@freebsd.org> To: freebsd-hackers@freebsd.org Subject: kgdb info threads and proc / thread names Message-ID: <20080118014153.GA12493@sandvine.com>
next in thread | raw e-mail | index | archive | help
--azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I noticed kgdb's "info threads" is a little less useful after kernel threads have been changed to share a proc: 8 Thread 100007 (PID=12: intr) fork_trampoline 7 Thread 100006 (PID=12: intr) sched_switch 6 Thread 100005 (PID=12: intr) sched_switch The attached patch outputs both the proc's p_comm and the thread's td_name, like so: 8 Thread 100007 (PID=12: intr/swi3: vm) 7 Thread 100006 (PID=12: intr/swi4: clock sio) 6 Thread 100005 (PID=12: intr/swi1: net) Any comments on the format (p_comm/td_name) or the patch? I'd like to do something similar with top, as right now for threaded apps you just get {initial thread} in the COMMAND column. I'd like to display something like artsd/initial thread instead. -Ed --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="kgdb.diff" Index: kthr.c =================================================================== RCS file: /usr/cvs/src/gnu/usr.bin/gdb/kgdb/kthr.c,v retrieving revision 1.8 diff -p -u -r1.8 kthr.c --- kthr.c 16 Nov 2007 22:17:37 -0000 1.8 +++ kthr.c 17 Jan 2008 21:24:48 -0000 @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include <kvm.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <defs.h> #include <frame-unwind.h> @@ -206,15 +207,25 @@ kgdb_thr_extra_thread_info(int tid) { struct kthr *kt; struct proc *p; - static char comm[MAXCOMLEN + 1]; + struct thread *t; + char comm[MAXCOMLEN + 1]; + char td_name[MAXCOMLEN + 1]; + static char info[MAXCOMLEN + 1 + MAXCOMLEN + 1]; kt = kgdb_thr_lookup_tid(tid); if (kt == NULL) return (NULL); p = (struct proc *)kt->paddr; + t = (struct thread *)kt->kaddr; if (kvm_read(kvm, (uintptr_t)&p->p_comm[0], &comm, sizeof(comm)) != sizeof(comm)) return (NULL); - - return (comm); + if (kvm_read(kvm, (uintptr_t)&t->td_name[0], &td_name, + sizeof(td_name)) != sizeof(td_name)) + td_name[0] = '\0'; + if (td_name[0] != '\0' && strcmp(comm, td_name) != 0) + snprintf(info, sizeof(info), "%s/%s", comm, td_name); + else + strlcpy(info, comm, sizeof(info)); + return (info); } --azLHFNyN32YCQGCU--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080118014153.GA12493>