ptrace.h revision 304188
12656Srgrimes/*- 22656Srgrimes * Copyright (c) 1984, 1993 32656Srgrimes * The Regents of the University of California. All rights reserved. 42656Srgrimes * 52656Srgrimes * Redistribution and use in source and binary forms, with or without 62656Srgrimes * modification, are permitted provided that the following conditions 72656Srgrimes * are met: 82656Srgrimes * 1. Redistributions of source code must retain the above copyright 92656Srgrimes * notice, this list of conditions and the following disclaimer. 102656Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 112656Srgrimes * notice, this list of conditions and the following disclaimer in the 122656Srgrimes * documentation and/or other materials provided with the distribution. 132656Srgrimes * 4. Neither the name of the University nor the names of its contributors 142656Srgrimes * may be used to endorse or promote products derived from this software 152656Srgrimes * without specific prior written permission. 162656Srgrimes * 172656Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 182656Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 192656Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 202656Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 212656Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 222656Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 232656Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 242656Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 252656Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 262656Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 272656Srgrimes * SUCH DAMAGE. 282656Srgrimes * 292656Srgrimes * @(#)ptrace.h 8.2 (Berkeley) 1/4/94 302656Srgrimes * $FreeBSD: stable/10/sys/sys/ptrace.h 304188 2016-08-15 21:10:41Z jhb $ 312656Srgrimes */ 322656Srgrimes 332656Srgrimes#ifndef _SYS_PTRACE_H_ 342656Srgrimes#define _SYS_PTRACE_H_ 352656Srgrimes 362656Srgrimes#include <sys/signal.h> 372656Srgrimes#include <sys/param.h> 382656Srgrimes#include <machine/reg.h> 392656Srgrimes 402656Srgrimes#define PT_TRACE_ME 0 /* child declares it's being traced */ 412656Srgrimes#define PT_READ_I 1 /* read word in child's I space */ 422656Srgrimes#define PT_READ_D 2 /* read word in child's D space */ 432656Srgrimes/* was PT_READ_U 3 * read word in child's user structure */ 442656Srgrimes#define PT_WRITE_I 4 /* write word in child's I space */ 452656Srgrimes#define PT_WRITE_D 5 /* write word in child's D space */ 462656Srgrimes/* was PT_WRITE_U 6 * write word in child's user structure */ 472656Srgrimes#define PT_CONTINUE 7 /* continue the child */ 482656Srgrimes#define PT_KILL 8 /* kill the child process */ 492656Srgrimes#define PT_STEP 9 /* single step the child */ 502656Srgrimes 512656Srgrimes#define PT_ATTACH 10 /* trace some running process */ 522656Srgrimes#define PT_DETACH 11 /* stop tracing a process */ 532656Srgrimes#define PT_IO 12 /* do I/O to/from stopped process. */ 542656Srgrimes#define PT_LWPINFO 13 /* Info about the LWP that stopped. */ 552656Srgrimes#define PT_GETNUMLWPS 14 /* get total number of threads */ 562656Srgrimes#define PT_GETLWPLIST 15 /* get thread list */ 572656Srgrimes#define PT_CLEARSTEP 16 /* turn off single step */ 582656Srgrimes#define PT_SETSTEP 17 /* turn on single step */ 592656Srgrimes#define PT_SUSPEND 18 /* suspend a thread */ 602656Srgrimes#define PT_RESUME 19 /* resume a thread */ 612656Srgrimes 622656Srgrimes#define PT_TO_SCE 20 632656Srgrimes#define PT_TO_SCX 21 642656Srgrimes#define PT_SYSCALL 22 65 66#define PT_FOLLOW_FORK 23 67#define PT_LWP_EVENTS 24 /* report LWP birth and exit */ 68 69#define PT_GET_EVENT_MASK 25 /* get mask of optional events */ 70#define PT_SET_EVENT_MASK 26 /* set mask of optional events */ 71 72#define PT_GETREGS 33 /* get general-purpose registers */ 73#define PT_SETREGS 34 /* set general-purpose registers */ 74#define PT_GETFPREGS 35 /* get floating-point registers */ 75#define PT_SETFPREGS 36 /* set floating-point registers */ 76#define PT_GETDBREGS 37 /* get debugging registers */ 77#define PT_SETDBREGS 38 /* set debugging registers */ 78 79#define PT_VM_TIMESTAMP 40 /* Get VM version (timestamp) */ 80#define PT_VM_ENTRY 41 /* Get VM map (entry) */ 81 82#define PT_FIRSTMACH 64 /* for machine-specific requests */ 83#include <machine/ptrace.h> /* machine-specific requests, if any */ 84 85/* Events used with PT_GET_EVENT_MASK and PT_SET_EVENT_MASK */ 86#define PTRACE_EXEC 0x0001 87#define PTRACE_SCE 0x0002 88#define PTRACE_SCX 0x0004 89#define PTRACE_SYSCALL (PTRACE_SCE | PTRACE_SCX) 90#define PTRACE_FORK 0x0008 91#define PTRACE_LWP 0x0010 92 93#define PTRACE_DEFAULT (PTRACE_EXEC) 94 95struct ptrace_io_desc { 96 int piod_op; /* I/O operation */ 97 void *piod_offs; /* child offset */ 98 void *piod_addr; /* parent offset */ 99 size_t piod_len; /* request length */ 100}; 101 102/* 103 * Operations in piod_op. 104 */ 105#define PIOD_READ_D 1 /* Read from D space */ 106#define PIOD_WRITE_D 2 /* Write to D space */ 107#define PIOD_READ_I 3 /* Read from I space */ 108#define PIOD_WRITE_I 4 /* Write to I space */ 109 110/* Argument structure for PT_LWPINFO. */ 111struct ptrace_lwpinfo { 112 lwpid_t pl_lwpid; /* LWP described. */ 113 int pl_event; /* Event that stopped the LWP. */ 114#define PL_EVENT_NONE 0 115#define PL_EVENT_SIGNAL 1 116 int pl_flags; /* LWP flags. */ 117#define PL_FLAG_SA 0x01 /* M:N thread */ 118#define PL_FLAG_BOUND 0x02 /* M:N bound thread */ 119#define PL_FLAG_SCE 0x04 /* syscall enter point */ 120#define PL_FLAG_SCX 0x08 /* syscall leave point */ 121#define PL_FLAG_EXEC 0x10 /* exec(2) succeeded */ 122#define PL_FLAG_SI 0x20 /* siginfo is valid */ 123#define PL_FLAG_FORKED 0x40 /* new child */ 124#define PL_FLAG_CHILD 0x80 /* I am from child */ 125#define PL_FLAG_BORN 0x100 /* new LWP */ 126#define PL_FLAG_EXITED 0x200 /* exiting LWP */ 127 sigset_t pl_sigmask; /* LWP signal mask */ 128 sigset_t pl_siglist; /* LWP pending signal */ 129 struct __siginfo pl_siginfo; /* siginfo for signal */ 130 char pl_tdname[MAXCOMLEN + 1]; /* LWP name */ 131 pid_t pl_child_pid; /* New child pid */ 132 u_int pl_syscall_code; 133 u_int pl_syscall_narg; 134}; 135 136/* Argument structure for PT_VM_ENTRY. */ 137struct ptrace_vm_entry { 138 int pve_entry; /* Entry number used for iteration. */ 139 int pve_timestamp; /* Generation number of VM map. */ 140 u_long pve_start; /* Start VA of range. */ 141 u_long pve_end; /* End VA of range (incl). */ 142 u_long pve_offset; /* Offset in backing object. */ 143 u_int pve_prot; /* Protection of memory range. */ 144 u_int pve_pathlen; /* Size of path. */ 145 long pve_fileid; /* File ID. */ 146 uint32_t pve_fsid; /* File system ID. */ 147 char *pve_path; /* Path name of object. */ 148}; 149 150#ifdef _KERNEL 151 152int ptrace_set_pc(struct thread *_td, unsigned long _addr); 153int ptrace_single_step(struct thread *_td); 154int ptrace_clear_single_step(struct thread *_td); 155 156#ifdef __HAVE_PTRACE_MACHDEP 157int cpu_ptrace(struct thread *_td, int _req, void *_addr, int _data); 158#endif 159 160/* 161 * These are prototypes for functions that implement some of the 162 * debugging functionality exported by procfs / linprocfs and by the 163 * ptrace(2) syscall. They used to be part of procfs, but they don't 164 * really belong there. 165 */ 166struct reg; 167struct fpreg; 168struct dbreg; 169struct uio; 170int proc_read_regs(struct thread *_td, struct reg *_reg); 171int proc_write_regs(struct thread *_td, struct reg *_reg); 172int proc_read_fpregs(struct thread *_td, struct fpreg *_fpreg); 173int proc_write_fpregs(struct thread *_td, struct fpreg *_fpreg); 174int proc_read_dbregs(struct thread *_td, struct dbreg *_dbreg); 175int proc_write_dbregs(struct thread *_td, struct dbreg *_dbreg); 176int proc_sstep(struct thread *_td); 177int proc_rwmem(struct proc *_p, struct uio *_uio); 178#ifdef COMPAT_FREEBSD32 179struct reg32; 180struct fpreg32; 181struct dbreg32; 182int proc_read_regs32(struct thread *_td, struct reg32 *_reg32); 183int proc_write_regs32(struct thread *_td, struct reg32 *_reg32); 184int proc_read_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32); 185int proc_write_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32); 186int proc_read_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32); 187int proc_write_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32); 188#endif 189#else /* !_KERNEL */ 190 191#include <sys/cdefs.h> 192 193__BEGIN_DECLS 194int ptrace(int _request, pid_t _pid, caddr_t _addr, int _data); 195__END_DECLS 196 197#endif /* !_KERNEL */ 198 199#endif /* !_SYS_PTRACE_H_ */ 200