From 0e0a0e7f515fbebbde98cdf0d9da784fdf1f6f66 Mon Sep 17 00:00:00 2001 From: nathanw Date: Thu, 27 Feb 2003 00:54:07 +0000 Subject: [PATCH] Add hooks to read the application-assigned name of a thread. --- lib/libpthread_dbg/pthread_dbg.c | 34 ++++++++++++++++++++++++++++++-- lib/libpthread_dbg/pthread_dbg.h | 5 ++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/libpthread_dbg/pthread_dbg.c b/lib/libpthread_dbg/pthread_dbg.c index 012e2200da85..ae95069e85b3 100644 --- a/lib/libpthread_dbg/pthread_dbg.c +++ b/lib/libpthread_dbg/pthread_dbg.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_dbg.c,v 1.3 2003/01/18 19:10:41 christos Exp $ */ +/* $NetBSD: pthread_dbg.c,v 1.4 2003/02/27 00:54:07 nathanw Exp $ */ /*- * Copyright (c) 2002 Wasabi Systems, Inc. @@ -48,6 +48,8 @@ #include #include +#define MIN(a,b) ((a)<(b) ? (a) : (b)) + static int td__getthread(td_proc_t *proc, caddr_t addr, td_thread_t **threadp); static int td__getsync(td_proc_t *proc, caddr_t addr, td_sync_t **syncp); @@ -273,6 +275,34 @@ td_thr_info(td_thread_t *thread, td_thread_info_t *info) return 0; } +int +td_thr_getname(td_thread_t *thread, char *name, int len) +{ + int val, tmp; + caddr_t nameaddr; + + + val = READ(thread->proc, thread->addr, &tmp, sizeof(tmp)); + if (val != 0) + return val; + + if (tmp != PT_MAGIC) + return TD_ERR_BADTHREAD; + + if ((val = READ(thread->proc, + thread->addr + offsetof(struct pthread_st, pt_name), + &nameaddr, sizeof(nameaddr))) != 0) + return val; + + if (nameaddr == 0) + name[0] = '\0'; + else if ((val = READ(thread->proc, nameaddr, + name, MIN(PTHREAD_MAX_NAMELEN_NP, len))) != 0) + return val; + + return 0; +} + int td_thr_getregs(td_thread_t *thread, int regset, void *buf) { @@ -422,7 +452,7 @@ td_thr_join_iter(td_thread_t *thread, int (*call)(td_thread_t *, void *), val = td__getthread(thread->proc, next, &thread2); if (val != 0) return val; - val = (*call)(thread, arg); + val = (*call)(thread2, arg); if (val != 0) return 0; diff --git a/lib/libpthread_dbg/pthread_dbg.h b/lib/libpthread_dbg/pthread_dbg.h index 2b920581a60e..c963cd68a744 100644 --- a/lib/libpthread_dbg/pthread_dbg.h +++ b/lib/libpthread_dbg/pthread_dbg.h @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_dbg.h,v 1.2 2003/01/18 10:34:23 thorpej Exp $ */ +/* $NetBSD: pthread_dbg.h,v 1.3 2003/02/27 00:54:08 nathanw Exp $ */ /*- * Copyright (c) 2002 Wasabi Systems, Inc. @@ -135,6 +135,9 @@ int td_thr_iter(td_proc_t *, int (*)(td_thread_t *, void *), void *); /* Get information on a thread */ int td_thr_info(td_thread_t *, td_thread_info_t *); +/* Get the user-assigned name of a thread */ +int td_thr_getname(td_thread_t *, char *, int); + /* Get register state of a thread */ int td_thr_getregs(td_thread_t *, int, void *);