Date: Fri, 7 May 2004 22:17:08 -0700 (PDT) From: Marcel Moolenaar <marcel@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 52492 for review Message-ID: <200405080517.i485H87U065177@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200405080517.i485H87U065177>