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