2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004 David Xu <davidxu@freebsd.org>
5 * Copyright (c) 2004 Marcel Moolenaar
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/procfs.h>
39 TD_ERR = -1, /* Unspecified error. */
40 TD_OK = 0, /* No error. */
63 typedef struct td_thragent td_thragent_t;
64 typedef long thread_t; /* Must be an integral type. */
67 const td_thragent_t *th_ta;
70 } td_thrhandle_t; /* Used non-opaguely. */
79 TD_CONCURRENCY= 0x0002,
85 TD_PRI_INHERIT= 0x0080,
89 TD_SWITCHFROM = 0x0800,
95 /* Compatibility with Linux. */
96 #define td_event_e td_thr_events_e
99 td_thr_events_e event;
104 typedef unsigned int td_thr_events_t;
107 NOTIFY_BPT, /* User inserted breakpoint. */
108 NOTIFY_AUTOBPT, /* Automatic breakpoint. */
109 NOTIFY_SYSCALL /* Invocation of system call. */
121 td_event_addset(td_thr_events_t *es, td_thr_events_e e)
127 td_event_delset(td_thr_events_t *es, td_thr_events_e e)
133 td_event_emptyset(td_thr_events_t *es)
139 td_event_fillset(td_thr_events_t *es)
145 td_eventisempty(td_thr_events_t *es)
147 return ((*es == TD_EVENT_NONE) ? 1 : 0);
151 td_eventismember(td_thr_events_t *es, td_thr_events_e e)
153 return ((*es & e) ? 1 : 0);
162 TD_THR_ANY_STATE = 0,
167 TD_THR_STOPPED_ASLEEP,
177 typedef pthread_key_t thread_key_t;
180 const td_thragent_t *ti_ta_p;
183 td_thr_state_e ti_state;
184 td_thr_type_e ti_type;
185 td_thr_events_t ti_events;
188 char ti_db_suspended;
193 psaddr_t ti_startfunc;
196 siginfo_t ti_siginfo;
203 typedef int td_key_iter_f(thread_key_t, void (*)(void *), void *);
204 typedef int td_thr_iter_f(const td_thrhandle_t *, void *);
206 /* Flags for `td_ta_thr_iter'. */
207 #define TD_THR_ANY_USER_FLAGS 0xffffffff
208 #define TD_THR_LOWEST_PRIORITY -20
209 #define TD_SIGNO_MASK NULL
212 td_err_e td_init(void);
214 td_err_e td_ta_clear_event(const td_thragent_t *, td_thr_events_t *);
215 td_err_e td_ta_delete(td_thragent_t *);
216 td_err_e td_ta_event_addr(const td_thragent_t *, td_thr_events_e,
218 td_err_e td_ta_event_getmsg(const td_thragent_t *, td_event_msg_t *);
219 td_err_e td_ta_map_id2thr(const td_thragent_t *, thread_t, td_thrhandle_t *);
220 td_err_e td_ta_map_lwp2thr(const td_thragent_t *, lwpid_t, td_thrhandle_t *);
221 td_err_e td_ta_new(struct ps_prochandle *, td_thragent_t **);
222 td_err_e td_ta_set_event(const td_thragent_t *, td_thr_events_t *);
223 td_err_e td_ta_thr_iter(const td_thragent_t *, td_thr_iter_f *, void *,
224 td_thr_state_e, int, sigset_t *, unsigned int);
225 td_err_e td_ta_tsd_iter(const td_thragent_t *, td_key_iter_f *, void *);
227 td_err_e td_thr_clear_event(const td_thrhandle_t *, td_thr_events_t *);
228 td_err_e td_thr_dbresume(const td_thrhandle_t *);
229 td_err_e td_thr_dbsuspend(const td_thrhandle_t *);
230 td_err_e td_thr_event_enable(const td_thrhandle_t *, int);
231 td_err_e td_thr_event_getmsg(const td_thrhandle_t *, td_event_msg_t *);
232 td_err_e td_thr_get_info(const td_thrhandle_t *, td_thrinfo_t *);
234 td_err_e td_thr_getxmmregs(const td_thrhandle_t *, char *);
236 td_err_e td_thr_getfpregs(const td_thrhandle_t *, prfpregset_t *);
237 td_err_e td_thr_getgregs(const td_thrhandle_t *, prgregset_t);
238 td_err_e td_thr_set_event(const td_thrhandle_t *, td_thr_events_t *);
240 td_err_e td_thr_setxmmregs(const td_thrhandle_t *, const char *);
242 td_err_e td_thr_setfpregs(const td_thrhandle_t *, const prfpregset_t *);
243 td_err_e td_thr_setgregs(const td_thrhandle_t *, const prgregset_t);
244 td_err_e td_thr_validate(const td_thrhandle_t *);
245 td_err_e td_thr_tls_get_addr(const td_thrhandle_t *, psaddr_t, size_t,
248 /* FreeBSD specific extensions. */
249 td_err_e td_thr_sstep(const td_thrhandle_t *, int);
252 #endif /* _THREAD_DB_H_ */