[BACK]Return to pthread_dbg.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libpthread_dbg

Annotation of src/lib/libpthread_dbg/pthread_dbg.h, Revision 1.8

1.8     ! kamil       1: /*     $NetBSD: pthread_dbg.h,v 1.7 2016/10/22 18:04:40 skrll Exp $    */
1.2       thorpej     2:
                      3: /*-
                      4:  * Copyright (c) 2002 Wasabi Systems, Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Written by Nathan J. Williams for Wasabi Systems, Inc.
                      8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
                     17:  * 3. All advertising materials mentioning features or use of this software
                     18:  *    must display the following acknowledgement:
                     19:  *      This product includes software developed for the NetBSD Project by
                     20:  *      Wasabi Systems, Inc.
                     21:  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
                     22:  *    or promote products derived from this software without specific
                     23:  *    prior written permission.
                     24:  *
                     25:  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
                     26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     27:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     28:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
                     29:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     30:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     31:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     32:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     33:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     34:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     35:  * POSSIBILITY OF SUCH DAMAGE.
                     36:  */
                     37:
1.7       skrll      38: #ifndef _LIB_PTHREAD_DBG_H
                     39: #define _LIB_PTHREAD_DBG_H
                     40:
1.2       thorpej    41: #include <sys/types.h>
                     42: #include <signal.h>
                     43:
1.7       skrll      44: __BEGIN_DECLS
                     45:
1.2       thorpej    46: struct td_proc_st;
                     47: struct td_thread_st;
                     48: struct td_sync_st;
                     49:
                     50: typedef struct td_proc_st td_proc_t;
                     51: typedef struct td_thread_st td_thread_t;
                     52: typedef struct td_sync_st td_sync_t;
                     53:
                     54: struct td_proc_callbacks_t {
                     55:        int (*proc_read)(void *arg, caddr_t addr, void *buf, size_t size);
                     56:        int (*proc_write)(void *arg, caddr_t addr, void *buf, size_t size);
1.6       christos   57:        int (*proc_lookup)(void *arg, const char *sym, caddr_t *addr);
1.2       thorpej    58:        int (*proc_regsize)(void *arg, int regset, size_t *size);
                     59:        int (*proc_getregs)(void *arg, int regset, int lwp, void *buf);
                     60:        int (*proc_setregs)(void *arg, int regset, int lwp, void *buf);
                     61: };
                     62:
                     63:
                     64: typedef struct td_thread_info_st {
                     65:        caddr_t thread_addr;            /* Address of data structure */
                     66:        int     thread_state;           /* TD_STATE_*; see below */
                     67:        int     thread_type;            /* TD_TYPE_*; see below */
                     68:        int     thread_id;
                     69:        stack_t thread_stack;
                     70:        int     thread_hasjoiners;      /* 1 if threads are waiting */
                     71:        caddr_t thread_tls;
                     72:        int     thread_errno;
                     73:        sigset_t thread_sigmask;
                     74:        sigset_t thread_sigpending;
                     75:        long    pad[32];
                     76: } td_thread_info_t;
                     77:
                     78: #define        TD_STATE_UNKNOWN        0
                     79: #define TD_STATE_RUNNING       1       /* On a processor */
1.8     ! kamil      80: #define        TD_STATE_UNUSED2        2       /* former TD_STATE_RUNNABLE for SA */
        !            81: #define        TD_STATE_UNUSED3        3       /* former TD_STATE_BLOCKED for SA */
        !            82: #define        TD_STATE_UNUSED4        4       /* former TD_STATE_SLEEPING for SA */
1.2       thorpej    83: #define        TD_STATE_ZOMBIE         5
1.8     ! kamil      84: #define        TD_STATE_UNUSED6        6       /* former TD_STATE_SUSPENDED for SA */
        !            85: #define        TD_STATE_DEAD           7
1.2       thorpej    86:
                     87: #define        TD_TYPE_UNKNOWN 0
                     88: #define        TD_TYPE_USER    1
                     89: #define        TD_TYPE_SYSTEM  2
                     90:
                     91: typedef struct {
                     92:        caddr_t sync_addr;      /* Address within the process */
                     93:        int     sync_type;      /* TD_SYNC_*; see below */
                     94:        size_t  sync_size;
                     95:        int     sync_haswaiters;  /* 1 if threads are known to be waiting */
                     96:        union {
                     97:                struct {
                     98:                        int     locked;
                     99:                        td_thread_t *owner;
                    100:                } mutex;
                    101:                struct {
                    102:                        int     locked;
                    103:                } spin;
                    104:                struct {
                    105:                        td_thread_t *thread;
                    106:                } join;
                    107:                struct {
                    108:                        int     locked;
                    109:                        int     readlocks;
                    110:                        td_thread_t *writeowner;
                    111:                } rwlock;
                    112:                long pad[8];
                    113:        } sync_data;
                    114: } td_sync_info_t;
                    115:
                    116: #define        TD_SYNC_UNKNOWN 0
                    117: #define        TD_SYNC_MUTEX   1       /* pthread_mutex_t */
                    118: #define TD_SYNC_COND   2       /* pthread_cond_t */
                    119: #define TD_SYNC_SPIN   3       /* pthread_spinlock_t */
                    120: #define TD_SYNC_JOIN   4       /* thread being joined */
                    121: #define TD_SYNC_RWLOCK 5       /* pthread_rwlock_t */
                    122:
                    123: /* Error return codes */
                    124: #define TD_ERR_OK              0
                    125: #define TD_ERR_ERR             1  /* Generic error */
                    126: #define TD_ERR_NOSYM           2  /* Symbol not found (proc_lookup) */
                    127: #define TD_ERR_NOOBJ           3  /* No object matched the request */
                    128: #define TD_ERR_BADTHREAD       4  /* Request is not meaningful for that thread */
                    129: #define TD_ERR_INUSE           5  /* The process is already being debugged */
                    130: #define TD_ERR_NOLIB           6  /* The process is not using libpthread */
                    131: #define TD_ERR_NOMEM           7  /* malloc() failed */
                    132: #define TD_ERR_IO              8  /* A callback failed to read or write */
                    133: #define TD_ERR_INVAL           9  /* Invalid parameter */
                    134:
                    135: /* Make a connection to a threaded process */
                    136: int td_open(struct td_proc_callbacks_t *, void *arg, td_proc_t **);
                    137: int td_close(td_proc_t *);
                    138:
                    139: /* Iterate over the threads in the process */
                    140: int td_thr_iter(td_proc_t *, int (*)(td_thread_t *, void *), void *);
                    141:
                    142: /* Get information on a thread */
                    143: int td_thr_info(td_thread_t *, td_thread_info_t *);
1.3       nathanw   144:
                    145: /* Get the user-assigned name of a thread */
                    146: int td_thr_getname(td_thread_t *, char *, int);
1.2       thorpej   147:
                    148: /* Get register state of a thread */
                    149: int td_thr_getregs(td_thread_t *, int, void *);
                    150:
                    151: /* Set register state of a thread */
                    152: int td_thr_setregs(td_thread_t *, int, void *);
                    153:
                    154: /* Iterate over the set of threads that are joining with the given thread */
                    155: int td_thr_join_iter(td_thread_t *, int (*)(td_thread_t *, void *), void *);
                    156:
                    157: /* Get the synchronization object that the thread is sleeping on */
                    158: int td_thr_sleepinfo(td_thread_t *, td_sync_t **);
                    159:
                    160: /* Get information on a synchronization object */
                    161: int td_sync_info(td_sync_t *, td_sync_info_t *);
                    162:
                    163: /* Iterate over the set of threads waiting on a synchronization object */
                    164: int td_sync_waiters_iter(td_sync_t *, int (*)(td_thread_t *, void *), void *);
                    165:
                    166: /* Convert the process address to a synchronization handle, if possible */
                    167: int td_map_addr2sync(td_proc_t *, caddr_t addr, td_sync_t **);
                    168:
                    169: /* Convert the pthread_t to a thread handle, if possible */
                    170: int td_map_pth2thr(td_proc_t *, pthread_t, td_thread_t **);
                    171:
                    172: /* Convert the thread ID to a thread handle, if possible */
                    173: int td_map_id2thr(td_proc_t *, int, td_thread_t **);
                    174:
                    175: /* Return the thread handle of the thread running on the given LWP */
                    176: int td_map_lwp2thr(td_proc_t *, int, td_thread_t **);
                    177:
                    178: /*
                    179:  * Establish a mapping between threads and LWPs. Must be called
                    180:  * every time a live process runs before calling td_thr_getregs() or
                    181:  * td_thr_setregs().
                    182:  */
                    183: int td_map_lwps(td_proc_t *);
                    184:
                    185: /* Iterate over the set of TSD keys in the process */
                    186: int td_tsd_iter(td_proc_t *, int (*)(pthread_key_t, void (*)(void *), void *),
                    187:     void *);
                    188:
                    189: /* Get a TSD value from a thread */
                    190: int td_thr_tsd(td_thread_t *, pthread_key_t, void **);
1.4       nathanw   191:
                    192: /* Suspend a thread from running */
                    193: int td_thr_suspend(td_thread_t *);
                    194:
                    195: /* Restore a suspended thread to its previous state */
                    196: int td_thr_resume(td_thread_t *);
1.7       skrll     197:
                    198: __END_DECLS
                    199:
                    200: #endif /* _LIB_PTHREAD_DBG_H */

CVSweb <webmaster@jp.NetBSD.org>