11541Srgrimes/*-
21541Srgrimes * Copyright (c) 1984, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
291541Srgrimes *	@(#)ptrace.h	8.2 (Berkeley) 1/4/94
3050477Speter * $FreeBSD$
311541Srgrimes */
321541Srgrimes
331541Srgrimes#ifndef	_SYS_PTRACE_H_
341541Srgrimes#define	_SYS_PTRACE_H_
351541Srgrimes
36209688Skib#include <sys/signal.h>
37215679Sattilio#include <sys/param.h>
38205014Snwhitehorn#include <machine/reg.h>
39155381Sdavidxu
401541Srgrimes#define	PT_TRACE_ME	0	/* child declares it's being traced */
411541Srgrimes#define	PT_READ_I	1	/* read word in child's I space */
421541Srgrimes#define	PT_READ_D	2	/* read word in child's D space */
4381265Speter/* was	PT_READ_U	3	 * read word in child's user structure */
441541Srgrimes#define	PT_WRITE_I	4	/* write word in child's I space */
451541Srgrimes#define	PT_WRITE_D	5	/* write word in child's D space */
4681265Speter/* was	PT_WRITE_U	6	 * write word in child's user structure */
471541Srgrimes#define	PT_CONTINUE	7	/* continue the child */
481541Srgrimes#define	PT_KILL		8	/* kill the child process */
491541Srgrimes#define	PT_STEP		9	/* single step the child */
501945Sdg
511541Srgrimes#define	PT_ATTACH	10	/* trace some running process */
521541Srgrimes#define	PT_DETACH	11	/* stop tracing a process */
5392395Sdes#define PT_IO		12	/* do I/O to/from stopped process. */
54132016Smarcel#define	PT_LWPINFO	13	/* Info about the LWP that stopped. */
55132089Sdavidxu#define PT_GETNUMLWPS	14	/* get total number of threads */
56132089Sdavidxu#define PT_GETLWPLIST	15	/* get thread list */
57132089Sdavidxu#define PT_CLEARSTEP	16	/* turn off single step */
58132089Sdavidxu#define PT_SETSTEP	17	/* turn on single step */
59132089Sdavidxu#define PT_SUSPEND	18	/* suspend a thread */
60132089Sdavidxu#define PT_RESUME	19	/* resume a thread */
611541Srgrimes
62120937Srobert#define	PT_TO_SCE	20
63120937Srobert#define	PT_TO_SCX	21
64120937Srobert#define	PT_SYSCALL	22
65120937Srobert
66217819Skib#define	PT_FOLLOW_FORK	23
67304017Sjhb#define	PT_LWP_EVENTS	24	/* report LWP birth and exit */
68217819Skib
69304188Sjhb#define	PT_GET_EVENT_MASK 25	/* get mask of optional events */
70304188Sjhb#define	PT_SET_EVENT_MASK 26	/* set mask of optional events */
71304188Sjhb
7292383Sdes#define PT_GETREGS      33	/* get general-purpose registers */
7392383Sdes#define PT_SETREGS      34	/* set general-purpose registers */
7492383Sdes#define PT_GETFPREGS    35	/* get floating-point registers */
7592383Sdes#define PT_SETFPREGS    36	/* set floating-point registers */
7692383Sdes#define PT_GETDBREGS    37	/* get debugging registers */
7792383Sdes#define PT_SETDBREGS    38	/* set debugging registers */
78203696Smarcel
79203696Smarcel#define	PT_VM_TIMESTAMP	40	/* Get VM version (timestamp) */
80203696Smarcel#define	PT_VM_ENTRY	41	/* Get VM map (entry) */
81203696Smarcel
82132089Sdavidxu#define PT_FIRSTMACH    64	/* for machine-specific requests */
831541Srgrimes#include <machine/ptrace.h>	/* machine-specific requests, if any */
841541Srgrimes
85304188Sjhb/* Events used with PT_GET_EVENT_MASK and PT_SET_EVENT_MASK */
86304188Sjhb#define	PTRACE_EXEC	0x0001
87304188Sjhb#define	PTRACE_SCE	0x0002
88304188Sjhb#define	PTRACE_SCX	0x0004
89304188Sjhb#define	PTRACE_SYSCALL	(PTRACE_SCE | PTRACE_SCX)
90304188Sjhb#define	PTRACE_FORK	0x0008
91304188Sjhb#define	PTRACE_LWP	0x0010
92304499Sjhb#define	PTRACE_VFORK	0x0020
93304188Sjhb
94304188Sjhb#define	PTRACE_DEFAULT	(PTRACE_EXEC)
95304188Sjhb
9692395Sdesstruct ptrace_io_desc {
9792395Sdes	int	piod_op;	/* I/O operation */
9892395Sdes	void	*piod_offs;	/* child offset */
9992395Sdes	void	*piod_addr;	/* parent offset */
10092395Sdes	size_t	piod_len;	/* request length */
10192395Sdes};
10292395Sdes
10392395Sdes/*
10492395Sdes * Operations in piod_op.
10592395Sdes */
10692395Sdes#define PIOD_READ_D	1	/* Read from D space */
10792395Sdes#define PIOD_WRITE_D	2	/* Write to D space */
10892395Sdes#define PIOD_READ_I	3	/* Read from I space */
10992395Sdes#define PIOD_WRITE_I	4	/* Write to I space */
11092395Sdes
111132016Smarcel/* Argument structure for PT_LWPINFO. */
112132016Smarcelstruct ptrace_lwpinfo {
113132016Smarcel	lwpid_t	pl_lwpid;	/* LWP described. */
114132016Smarcel	int	pl_event;	/* Event that stopped the LWP. */
115132016Smarcel#define	PL_EVENT_NONE	0
116132016Smarcel#define	PL_EVENT_SIGNAL	1
117133337Sdavidxu	int	pl_flags;	/* LWP flags. */
118133337Sdavidxu#define	PL_FLAG_SA	0x01	/* M:N thread */
119133337Sdavidxu#define	PL_FLAG_BOUND	0x02	/* M:N bound thread */
120208453Skib#define	PL_FLAG_SCE	0x04	/* syscall enter point */
121208453Skib#define	PL_FLAG_SCX	0x08	/* syscall leave point */
122208453Skib#define	PL_FLAG_EXEC	0x10	/* exec(2) succeeded */
123209688Skib#define	PL_FLAG_SI	0x20	/* siginfo is valid */
124217819Skib#define	PL_FLAG_FORKED	0x40	/* new child */
125231320Skib#define	PL_FLAG_CHILD	0x80	/* I am from child */
126304017Sjhb#define	PL_FLAG_BORN	0x100	/* new LWP */
127304017Sjhb#define	PL_FLAG_EXITED	0x200	/* exiting LWP */
128304499Sjhb#define	PL_FLAG_VFORKED	0x400	/* new child via vfork */
129304499Sjhb#define	PL_FLAG_VFORK_DONE 0x800 /* vfork parent has resumed */
130155381Sdavidxu	sigset_t	pl_sigmask;	/* LWP signal mask */
131155381Sdavidxu	sigset_t	pl_siglist;	/* LWP pending signal */
132209688Skib	struct __siginfo pl_siginfo;	/* siginfo for signal */
133215679Sattilio	char		pl_tdname[MAXCOMLEN + 1]; /* LWP name */
134290464Sjhb	pid_t		pl_child_pid;	/* New child pid */
135289780Sjhb	u_int		pl_syscall_code;
136289780Sjhb	u_int		pl_syscall_narg;
137132016Smarcel};
138132016Smarcel
139203696Smarcel/* Argument structure for PT_VM_ENTRY. */
140203696Smarcelstruct ptrace_vm_entry {
141203783Smarcel	int		pve_entry;	/* Entry number used for iteration. */
142203783Smarcel	int		pve_timestamp;	/* Generation number of VM map. */
143203783Smarcel	u_long		pve_start;	/* Start VA of range. */
144203783Smarcel	u_long		pve_end;	/* End VA of range (incl). */
145203783Smarcel	u_long		pve_offset;	/* Offset in backing object. */
146203783Smarcel	u_int		pve_prot;	/* Protection of memory range. */
147203783Smarcel	u_int		pve_pathlen;	/* Size of path. */
148203783Smarcel	long		pve_fileid;	/* File ID. */
149203783Smarcel	uint32_t	pve_fsid;	/* File system ID. */
150203783Smarcel	char		*pve_path;	/* Path name of object. */
151203696Smarcel};
152203696Smarcel
15355205Speter#ifdef _KERNEL
154120937Srobert
15584637Sdesint	ptrace_set_pc(struct thread *_td, unsigned long _addr);
15684637Sdesint	ptrace_single_step(struct thread *_td);
157132089Sdavidxuint	ptrace_clear_single_step(struct thread *_td);
15884637Sdes
159118932Smarcel#ifdef __HAVE_PTRACE_MACHDEP
160118932Smarcelint	cpu_ptrace(struct thread *_td, int _req, void *_addr, int _data);
161118932Smarcel#endif
162118932Smarcel
16384637Sdes/*
16484637Sdes * These are prototypes for functions that implement some of the
16584637Sdes * debugging functionality exported by procfs / linprocfs and by the
16684637Sdes * ptrace(2) syscall.  They used to be part of procfs, but they don't
16784637Sdes * really belong there.
16884637Sdes */
16984637Sdesstruct reg;
17084637Sdesstruct fpreg;
17184637Sdesstruct dbreg;
17285941Sdesstruct uio;
17385297Sdesint	proc_read_regs(struct thread *_td, struct reg *_reg);
17485297Sdesint	proc_write_regs(struct thread *_td, struct reg *_reg);
17585297Sdesint	proc_read_fpregs(struct thread *_td, struct fpreg *_fpreg);
17685297Sdesint	proc_write_fpregs(struct thread *_td, struct fpreg *_fpreg);
17785297Sdesint	proc_read_dbregs(struct thread *_td, struct dbreg *_dbreg);
17885297Sdesint	proc_write_dbregs(struct thread *_td, struct dbreg *_dbreg);
17985297Sdesint	proc_sstep(struct thread *_td);
18084637Sdesint	proc_rwmem(struct proc *_p, struct uio *_uio);
181205014Snwhitehorn#ifdef COMPAT_FREEBSD32
182147692Speterstruct reg32;
183147692Speterstruct fpreg32;
184147692Speterstruct dbreg32;
185147692Speterint	proc_read_regs32(struct thread *_td, struct reg32 *_reg32);
186147692Speterint	proc_write_regs32(struct thread *_td, struct reg32 *_reg32);
187147692Speterint	proc_read_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32);
188147692Speterint	proc_write_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32);
189147692Speterint	proc_read_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32);
190147692Speterint	proc_write_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32);
191147692Speter#endif
19255205Speter#else /* !_KERNEL */
1931541Srgrimes
1941541Srgrimes#include <sys/cdefs.h>
1951541Srgrimes
1961541Srgrimes__BEGIN_DECLS
19784637Sdesint	ptrace(int _request, pid_t _pid, caddr_t _addr, int _data);
1981541Srgrimes__END_DECLS
1991541Srgrimes
20055205Speter#endif /* !_KERNEL */
2011541Srgrimes
2021541Srgrimes#endif	/* !_SYS_PTRACE_H_ */
203