From owner-p4-projects@FreeBSD.ORG Fri May 7 22:17:09 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 13B7C16A4D0; Fri, 7 May 2004 22:17:09 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CA4B916A4CF for ; Fri, 7 May 2004 22:17:08 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7E5BD43D3F for ; Fri, 7 May 2004 22:17:08 -0700 (PDT) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.10/8.12.10) with ESMTP id i485H8Ge065180 for ; Fri, 7 May 2004 22:17:08 -0700 (PDT) (envelope-from marcel@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.10/8.12.10/Submit) id i485H87U065177 for perforce@freebsd.org; Fri, 7 May 2004 22:17:08 -0700 (PDT) (envelope-from marcel@freebsd.org) Date: Fri, 7 May 2004 22:17:08 -0700 (PDT) Message-Id: <200405080517.i485H87U065177@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to marcel@freebsd.org using -f From: Marcel Moolenaar To: Perforce Change Reviews Subject: PERFORCE change 52492 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 May 2004 05:17:09 -0000 http://perforce.freebsd.org/chv.cgi?CH=52492 Change 52492 by marcel@marcel_nfs on 2004/05/07 22:16:29 Add thread support functions: o kdb_thr_first() and kdb_thr_next() are to be used when iterating over the threads. Typically one calls these to list threads. o kdb_thr_lookup() maps a TID onto a struct thread. This allows thread selection based on TIDs. o kdb_thr_select() is used to switch the current thread. Currently threads that haven't run yet are considered non-existent. This is mostly done to avoid complexities caused by not having a valid or complete trapframe. Remove kdb_set_thread(). Affected files ... .. //depot/projects/gdb/sys/kern/subr_kdb.c#12 edit .. //depot/projects/gdb/sys/sys/kdb.h#9 edit Differences ... ==== //depot/projects/gdb/sys/kern/subr_kdb.c#12 (text+ko) ==== @@ -193,20 +193,6 @@ } /* - * Handle contexts. - */ - -void * -kdb_jmpbuf(jmp_buf new) -{ - void *old; - - old = kdb_jmpbufp; - kdb_jmpbufp = new; - return (old); -} - -/* * Enter the currently selected debugger. If a message has been provided, * it is printed first. If the debugger does not support the enter method, * it is entered by using breakpoint(), which enters the debugger through @@ -260,24 +246,79 @@ } /* - * Switch the current thread. + * Handle contexts. + */ + +void * +kdb_jmpbuf(jmp_buf new) +{ + void *old; + + old = kdb_jmpbufp; + kdb_jmpbufp = new; + return (old); +} + +/* + * Thread related support functions. */ -int -kdb_set_thread(pid_t tid) +struct thread * +kdb_thr_first(void) { struct proc *p; + struct thread *thr; p = LIST_FIRST(&allproc); - while (p != NULL && p->p_pid != tid) + while (p != NULL) { + thr = FIRST_THREAD_IN_PROC(p); + while (thr != NULL && thr->td_last_frame == NULL) + thr = TAILQ_NEXT(thr, td_plist); + if (thr != NULL) + return (thr); p = LIST_NEXT(p, p_list); - if (p != NULL) { - kdb_thread = FIRST_THREAD_IN_PROC(p); - kdb_frame = kdb_thread->td_last_frame; - if (kdb_frame == NULL) - kdb_frame = kdb_thread->td_frame; } - return ((p != NULL) ? 1 : 0); + return (NULL); +} + +struct thread * +kdb_thr_lookup(pid_t tid) +{ + struct thread *thr; + + thr = kdb_thr_first(); + while (thr != NULL && thr->td_tid != tid) + thr = kdb_thr_next(thr); + return (thr); +} + +struct thread * +kdb_thr_next(struct thread *thr) +{ + struct proc *p; + + p = thr->td_proc; + thr = TAILQ_NEXT(thr, td_plist); + do { + while (thr != NULL && thr->td_last_frame == NULL) + thr = TAILQ_NEXT(thr, td_plist); + if (thr != NULL) + return (thr); + p = LIST_NEXT(p, p_list); + if (p != NULL) + thr = FIRST_THREAD_IN_PROC(p); + } while (p != NULL); + return (NULL); +} + +int +kdb_thr_select(struct thread *thr) +{ + if (thr == NULL || thr->td_last_frame == NULL) + return (EINVAL); + kdb_thread = thr; + kdb_frame = kdb_thread->td_last_frame; + return (0); } /* ==== //depot/projects/gdb/sys/sys/kdb.h#9 (text+ko) ==== @@ -65,7 +65,10 @@ void kdb_enter(const char *); void kdb_init(void); void * kdb_jmpbuf(jmp_buf); -int kdb_set_thread(pid_t); +struct thread *kdb_thr_first(void); +struct thread *kdb_thr_lookup(pid_t); +struct thread *kdb_thr_next(struct thread *); +int kdb_thr_select(struct thread *); int kdb_trap(int, int, struct trapframe *); #endif /* !_SYS_KDB_H_ */