kgdb info threads and proc / thread names
Ed Maste
emaste at freebsd.org
Thu Jan 17 17:42:56 PST 2008
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
-------------- next part --------------
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);
}
More information about the freebsd-hackers
mailing list