1/*
2 * Copyright (c) 2004 David Xu <davidxu@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#ifndef _THREAD_DB_INT_H_
30#define	_THREAD_DB_INT_H_
31
32#include <sys/types.h>
33#include <sys/queue.h>
34
35typedef struct {
36	const td_thragent_t *ti_ta_p;
37	thread_t	ti_tid;
38	psaddr_t	ti_thread;
39	td_thr_state_e	ti_state;
40	td_thr_type_e	ti_type;
41	td_thr_events_t	ti_events;
42	int		ti_pri;
43	lwpid_t		ti_lid;
44	char		ti_db_suspended;
45	char		ti_traceme;
46	sigset_t	ti_sigmask;
47	sigset_t	ti_pending;
48	psaddr_t	ti_tls;
49	psaddr_t	ti_startfunc;
50	psaddr_t	ti_stkbase;
51	size_t		ti_stksize;
52} td_old_thrinfo_t;
53
54#define	TD_THRAGENT_FIELDS			\
55	struct ta_ops		*ta_ops;	\
56	TAILQ_ENTRY(td_thragent) ta_next;	\
57	struct ps_prochandle	*ph
58
59struct ta_ops {
60	td_err_e (*to_init)(void);
61
62	td_err_e (*to_ta_clear_event)(const td_thragent_t *,
63	    td_thr_events_t *);
64	td_err_e (*to_ta_delete)(td_thragent_t *);
65	td_err_e (*to_ta_event_addr)(const td_thragent_t *, td_thr_events_e,
66	    td_notify_t *);
67	td_err_e (*to_ta_event_getmsg)(const td_thragent_t *,
68	    td_event_msg_t *);
69	td_err_e (*to_ta_map_id2thr)(const td_thragent_t *, thread_t,
70	    td_thrhandle_t *);
71	td_err_e (*to_ta_map_lwp2thr)(const td_thragent_t *, lwpid_t,
72	    td_thrhandle_t *);
73	td_err_e (*to_ta_new)(struct ps_prochandle *, td_thragent_t **);
74	td_err_e (*to_ta_set_event)(const td_thragent_t *, td_thr_events_t *);
75	td_err_e (*to_ta_thr_iter)(const td_thragent_t *, td_thr_iter_f *,
76	    void *, td_thr_state_e, int, sigset_t *, unsigned int);
77	td_err_e (*to_ta_tsd_iter)(const td_thragent_t *, td_key_iter_f *,
78	    void *);
79
80	td_err_e (*to_thr_clear_event)(const td_thrhandle_t *,
81	    td_thr_events_t *);
82	td_err_e (*to_thr_dbresume)(const td_thrhandle_t *);
83	td_err_e (*to_thr_dbsuspend)(const td_thrhandle_t *);
84	td_err_e (*to_thr_event_enable)(const td_thrhandle_t *, int);
85	td_err_e (*to_thr_event_getmsg)(const td_thrhandle_t *,
86	    td_event_msg_t *);
87	td_err_e (*to_thr_old_get_info)(const td_thrhandle_t *,
88	    td_old_thrinfo_t *);
89	td_err_e (*to_thr_get_info)(const td_thrhandle_t *, td_thrinfo_t *);
90	td_err_e (*to_thr_getfpregs)(const td_thrhandle_t *, prfpregset_t *);
91	td_err_e (*to_thr_getgregs)(const td_thrhandle_t *, prgregset_t);
92	td_err_e (*to_thr_set_event)(const td_thrhandle_t *,
93	    td_thr_events_t *);
94	td_err_e (*to_thr_setfpregs)(const td_thrhandle_t *,
95	    const prfpregset_t *);
96	td_err_e (*to_thr_setgregs)(const td_thrhandle_t *, const prgregset_t);
97	td_err_e (*to_thr_validate)(const td_thrhandle_t *);
98	td_err_e (*to_thr_tls_get_addr)(const td_thrhandle_t *, psaddr_t,
99	    size_t, psaddr_t *);
100
101	/* FreeBSD specific extensions. */
102	td_err_e (*to_thr_sstep)(const td_thrhandle_t *, int);
103#if defined(__i386__)
104	td_err_e (*to_thr_getxmmregs)(const td_thrhandle_t *, char *);
105	td_err_e (*to_thr_setxmmregs)(const td_thrhandle_t *, const char *);
106#endif
107};
108
109#ifdef TD_DEBUG
110#define TDBG(...) ps_plog(__VA_ARGS__)
111#define TDBG_FUNC() ps_plog("%s\n", __func__)
112#else
113#define TDBG(...)
114#define TDBG_FUNC()
115#endif
116
117struct td_thragent;
118
119int thr_pread_int(const struct td_thragent *, psaddr_t, uint32_t *);
120int thr_pread_long(const struct td_thragent *, psaddr_t, uint64_t *);
121int thr_pread_ptr(const struct td_thragent *, psaddr_t, psaddr_t *);
122
123int thr_pwrite_int(const struct td_thragent *, psaddr_t, uint32_t);
124int thr_pwrite_long(const struct td_thragent *, psaddr_t, uint64_t);
125int thr_pwrite_ptr(const struct td_thragent *, psaddr_t, psaddr_t);
126
127td_err_e td_thr_old_get_info(const td_thrhandle_t *th, td_old_thrinfo_t *info);
128
129#endif /* _THREAD_DB_INT_H_ */
130