From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 18 01:42:56 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 01A3616A41B for ; Fri, 18 Jan 2008 01:42:56 +0000 (UTC) (envelope-from emaste@freebsd.org) Received: from gw.sandvine.com (gw.sandvine.com [199.243.201.138]) by mx1.freebsd.org (Postfix) with ESMTP id 9A13E13C448 for ; Fri, 18 Jan 2008 01:42:55 +0000 (UTC) (envelope-from emaste@freebsd.org) Received: from labgw2.phaedrus.sandvine.com ([192.168.3.11]) by gw.sandvine.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 17 Jan 2008 20:41:53 -0500 Received: by labgw2.phaedrus.sandvine.com (Postfix, from userid 12627) id 8746F116FD; Thu, 17 Jan 2008 20:41:53 -0500 (EST) Date: Thu, 17 Jan 2008 20:41:53 -0500 From: Ed Maste To: freebsd-hackers@freebsd.org Message-ID: <20080118014153.GA12493@sandvine.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="azLHFNyN32YCQGCU" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-OriginalArrivalTime: 18 Jan 2008 01:41:53.0739 (UTC) FILETIME=[4D8F09B0:01C85973] Subject: kgdb info threads and proc / thread names X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jan 2008 01:42:56 -0000 --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 #include #include +#include #include #include @@ -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--