Annotation of src/lib/libpthread_dbg/pthread_dbg.h, Revision 1.4
1.4 ! nathanw 1: /* $NetBSD: pthread_dbg.h,v 1.3 2003/02/27 00:54:08 nathanw 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:
38: #include <sys/types.h>
39: #include <signal.h>
40:
41: struct td_proc_st;
42: struct td_thread_st;
43: struct td_sync_st;
44:
45: typedef struct td_proc_st td_proc_t;
46: typedef struct td_thread_st td_thread_t;
47: typedef struct td_sync_st td_sync_t;
48:
49: struct td_proc_callbacks_t {
50: int (*proc_read)(void *arg, caddr_t addr, void *buf, size_t size);
51: int (*proc_write)(void *arg, caddr_t addr, void *buf, size_t size);
52: int (*proc_lookup)(void *arg, char *sym, caddr_t *addr);
53: int (*proc_regsize)(void *arg, int regset, size_t *size);
54: int (*proc_getregs)(void *arg, int regset, int lwp, void *buf);
55: int (*proc_setregs)(void *arg, int regset, int lwp, void *buf);
56: };
57:
58:
59: typedef struct td_thread_info_st {
60: caddr_t thread_addr; /* Address of data structure */
61: int thread_state; /* TD_STATE_*; see below */
62: int thread_type; /* TD_TYPE_*; see below */
63: int thread_id;
64: stack_t thread_stack;
65: int thread_hasjoiners; /* 1 if threads are waiting */
66: caddr_t thread_tls;
67: int thread_errno;
68: sigset_t thread_sigmask;
69: sigset_t thread_sigpending;
70: long pad[32];
71: } td_thread_info_t;
72:
73: #define TD_STATE_UNKNOWN 0
74: #define TD_STATE_RUNNING 1 /* On a processor */
75: #define TD_STATE_RUNNABLE 2 /* On a run queue */
76: #define TD_STATE_BLOCKED 3 /* Blocked in the kernel */
77: #define TD_STATE_SLEEPING 4 /* Blocked on a sync object */
78: #define TD_STATE_ZOMBIE 5
79:
80: #define TD_TYPE_UNKNOWN 0
81: #define TD_TYPE_USER 1
82: #define TD_TYPE_SYSTEM 2
83:
84: typedef struct {
85: caddr_t sync_addr; /* Address within the process */
86: int sync_type; /* TD_SYNC_*; see below */
87: size_t sync_size;
88: int sync_haswaiters; /* 1 if threads are known to be waiting */
89: union {
90: struct {
91: int locked;
92: td_thread_t *owner;
93: } mutex;
94: struct {
95: int locked;
96: } spin;
97: struct {
98: td_thread_t *thread;
99: } join;
100: struct {
101: int locked;
102: int readlocks;
103: td_thread_t *writeowner;
104: } rwlock;
105: long pad[8];
106: } sync_data;
107: } td_sync_info_t;
108:
109: #define TD_SYNC_UNKNOWN 0
110: #define TD_SYNC_MUTEX 1 /* pthread_mutex_t */
111: #define TD_SYNC_COND 2 /* pthread_cond_t */
112: #define TD_SYNC_SPIN 3 /* pthread_spinlock_t */
113: #define TD_SYNC_JOIN 4 /* thread being joined */
114: #define TD_SYNC_RWLOCK 5 /* pthread_rwlock_t */
115:
116: /* Error return codes */
117: #define TD_ERR_OK 0
118: #define TD_ERR_ERR 1 /* Generic error */
119: #define TD_ERR_NOSYM 2 /* Symbol not found (proc_lookup) */
120: #define TD_ERR_NOOBJ 3 /* No object matched the request */
121: #define TD_ERR_BADTHREAD 4 /* Request is not meaningful for that thread */
122: #define TD_ERR_INUSE 5 /* The process is already being debugged */
123: #define TD_ERR_NOLIB 6 /* The process is not using libpthread */
124: #define TD_ERR_NOMEM 7 /* malloc() failed */
125: #define TD_ERR_IO 8 /* A callback failed to read or write */
126: #define TD_ERR_INVAL 9 /* Invalid parameter */
127:
128: /* Make a connection to a threaded process */
129: int td_open(struct td_proc_callbacks_t *, void *arg, td_proc_t **);
130: int td_close(td_proc_t *);
131:
132: /* Iterate over the threads in the process */
133: int td_thr_iter(td_proc_t *, int (*)(td_thread_t *, void *), void *);
134:
135: /* Get information on a thread */
136: int td_thr_info(td_thread_t *, td_thread_info_t *);
1.3 nathanw 137:
138: /* Get the user-assigned name of a thread */
139: int td_thr_getname(td_thread_t *, char *, int);
1.2 thorpej 140:
141: /* Get register state of a thread */
142: int td_thr_getregs(td_thread_t *, int, void *);
143:
144: /* Set register state of a thread */
145: int td_thr_setregs(td_thread_t *, int, void *);
146:
147: /* Iterate over the set of threads that are joining with the given thread */
148: int td_thr_join_iter(td_thread_t *, int (*)(td_thread_t *, void *), void *);
149:
150: /* Get the synchronization object that the thread is sleeping on */
151: int td_thr_sleepinfo(td_thread_t *, td_sync_t **);
152:
153: /* Get information on a synchronization object */
154: int td_sync_info(td_sync_t *, td_sync_info_t *);
155:
156: /* Iterate over the set of threads waiting on a synchronization object */
157: int td_sync_waiters_iter(td_sync_t *, int (*)(td_thread_t *, void *), void *);
158:
159: /* Convert the process address to a synchronization handle, if possible */
160: int td_map_addr2sync(td_proc_t *, caddr_t addr, td_sync_t **);
161:
162: /* Convert the pthread_t to a thread handle, if possible */
163: int td_map_pth2thr(td_proc_t *, pthread_t, td_thread_t **);
164:
165: /* Convert the thread ID to a thread handle, if possible */
166: int td_map_id2thr(td_proc_t *, int, td_thread_t **);
167:
168: /* Return the thread handle of the thread running on the given LWP */
169: int td_map_lwp2thr(td_proc_t *, int, td_thread_t **);
170:
171: /*
172: * Establish a mapping between threads and LWPs. Must be called
173: * every time a live process runs before calling td_thr_getregs() or
174: * td_thr_setregs().
175: */
176: int td_map_lwps(td_proc_t *);
177:
178: /* Iterate over the set of TSD keys in the process */
179: int td_tsd_iter(td_proc_t *, int (*)(pthread_key_t, void (*)(void *), void *),
180: void *);
181:
182: /* Get a TSD value from a thread */
183: int td_thr_tsd(td_thread_t *, pthread_key_t, void **);
1.4 ! nathanw 184:
! 185: /* Suspend a thread from running */
! 186: int td_thr_suspend(td_thread_t *);
! 187:
! 188: /* Restore a suspended thread to its previous state */
! 189: int td_thr_resume(td_thread_t *);
CVSweb <webmaster@jp.NetBSD.org>