15e53a4f9SPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
43c1e38eaSMarcel Moolenaar  * Copyright (c) 2004 David Xu <[email protected]>
53c1e38eaSMarcel Moolenaar  * All rights reserved.
63c1e38eaSMarcel Moolenaar  *
73c1e38eaSMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
83c1e38eaSMarcel Moolenaar  * modification, are permitted provided that the following conditions
93c1e38eaSMarcel Moolenaar  * are met:
103c1e38eaSMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
113c1e38eaSMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
123c1e38eaSMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
133c1e38eaSMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
143c1e38eaSMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
153c1e38eaSMarcel Moolenaar  *
163c1e38eaSMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
173c1e38eaSMarcel Moolenaar  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
183c1e38eaSMarcel Moolenaar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
193c1e38eaSMarcel Moolenaar  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
203c1e38eaSMarcel Moolenaar  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
213c1e38eaSMarcel Moolenaar  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223c1e38eaSMarcel Moolenaar  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
233c1e38eaSMarcel Moolenaar  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
243c1e38eaSMarcel Moolenaar  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
253c1e38eaSMarcel Moolenaar  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
263c1e38eaSMarcel Moolenaar  * SUCH DAMAGE.
273c1e38eaSMarcel Moolenaar  *
283c1e38eaSMarcel Moolenaar  * $FreeBSD$
293c1e38eaSMarcel Moolenaar  */
303c1e38eaSMarcel Moolenaar 
313c1e38eaSMarcel Moolenaar #ifndef _LIBPTHREAD_DB_H_
323c1e38eaSMarcel Moolenaar #define	_LIBPTHREAD_DB_H_
333c1e38eaSMarcel Moolenaar 
343c1e38eaSMarcel Moolenaar #include <sys/ucontext.h>
353c1e38eaSMarcel Moolenaar #include <machine/reg.h>
363c1e38eaSMarcel Moolenaar 
373c1e38eaSMarcel Moolenaar #include "thread_db_int.h"
383c1e38eaSMarcel Moolenaar 
39820c1c55SMarcel Moolenaar enum pt_type {
403c1e38eaSMarcel Moolenaar 	PT_NONE,
413c1e38eaSMarcel Moolenaar 	PT_USER,
423c1e38eaSMarcel Moolenaar 	PT_LWP
43820c1c55SMarcel Moolenaar };
443c1e38eaSMarcel Moolenaar 
45820c1c55SMarcel Moolenaar struct pt_map {
46820c1c55SMarcel Moolenaar 	enum pt_type	type;
473c1e38eaSMarcel Moolenaar 	union {
483c1e38eaSMarcel Moolenaar 		lwpid_t		lwp;
493c1e38eaSMarcel Moolenaar 		psaddr_t	thr;
503c1e38eaSMarcel Moolenaar 	};
513c1e38eaSMarcel Moolenaar };
523c1e38eaSMarcel Moolenaar 
533c1e38eaSMarcel Moolenaar struct td_thragent {
543c1e38eaSMarcel Moolenaar 	TD_THRAGENT_FIELDS;
553c1e38eaSMarcel Moolenaar 	psaddr_t	libkse_debug_addr;
563c1e38eaSMarcel Moolenaar 	psaddr_t	thread_list_addr;
573c1e38eaSMarcel Moolenaar 	psaddr_t	thread_listgen_addr;
583c1e38eaSMarcel Moolenaar 	psaddr_t	thread_activated_addr;
593c1e38eaSMarcel Moolenaar 	psaddr_t	thread_active_threads_addr;
603c1e38eaSMarcel Moolenaar 	psaddr_t	thread_keytable_addr;
613c1e38eaSMarcel Moolenaar 	int		thread_activated;
62cd980d46SDavid Xu 	int		thread_off_dtv;
63cd980d46SDavid Xu 	int		thread_off_kse_locklevel;
64cd980d46SDavid Xu 	int		thread_off_kse;
65cd980d46SDavid Xu 	int		thread_off_tlsindex;
66cd980d46SDavid Xu 	int		thread_off_attr_flags;
67cd980d46SDavid Xu 	int		thread_size_key;
68cd980d46SDavid Xu 	int		thread_off_tcb;
69cd980d46SDavid Xu 	int		thread_off_linkmap;
70cd980d46SDavid Xu 	int		thread_off_tmbx;
71cd980d46SDavid Xu 	int		thread_off_thr_locklevel;
72cd980d46SDavid Xu 	int		thread_off_next;
73cd980d46SDavid Xu 	int		thread_off_state;
74cd980d46SDavid Xu 	int		thread_max_keys;
75cd980d46SDavid Xu 	int		thread_off_key_allocated;
76cd980d46SDavid Xu 	int		thread_off_key_destructor;
77cd980d46SDavid Xu 	int		thread_state_zoombie;
78cd980d46SDavid Xu 	int		thread_state_running;
792ed66c93SDavid Xu 	int		thread_off_sigmask;
802ed66c93SDavid Xu 	int		thread_off_sigpend;
813c1e38eaSMarcel Moolenaar 	struct pt_map	*map;
821f2b051dSPedro F. Giffuni 	unsigned int	map_len;
833c1e38eaSMarcel Moolenaar };
843c1e38eaSMarcel Moolenaar 
853c1e38eaSMarcel Moolenaar void pt_md_init(void);
863c1e38eaSMarcel Moolenaar void pt_reg_to_ucontext(const struct reg *, ucontext_t *);
873c1e38eaSMarcel Moolenaar void pt_ucontext_to_reg(const ucontext_t *, struct reg *);
883c1e38eaSMarcel Moolenaar void pt_fpreg_to_ucontext(const struct fpreg *, ucontext_t *);
893c1e38eaSMarcel Moolenaar void pt_ucontext_to_fpreg(const ucontext_t *, struct fpreg *);
908d7681bbSDoug Rabson #ifdef __i386__
918d7681bbSDoug Rabson void pt_fxsave_to_ucontext(const char *, ucontext_t *);
928d7681bbSDoug Rabson void pt_ucontext_to_fxsave(const ucontext_t *, char *);
938d7681bbSDoug Rabson #endif
943c1e38eaSMarcel Moolenaar int  pt_reg_sstep(struct reg *reg, int step);
953c1e38eaSMarcel Moolenaar 
963c1e38eaSMarcel Moolenaar #endif /* _LIBPTHREAD_DB_H_ */
97