ptrace.h revision 147692
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: head/sys/sys/ptrace.h 147692 2005-06-30 07:49:22Z peter $ 311541Srgrimes */ 321541Srgrimes 331541Srgrimes#ifndef _SYS_PTRACE_H_ 341541Srgrimes#define _SYS_PTRACE_H_ 351541Srgrimes 361541Srgrimes#define PT_TRACE_ME 0 /* child declares it's being traced */ 371541Srgrimes#define PT_READ_I 1 /* read word in child's I space */ 381541Srgrimes#define PT_READ_D 2 /* read word in child's D space */ 3981265Speter/* was PT_READ_U 3 * read word in child's user structure */ 401541Srgrimes#define PT_WRITE_I 4 /* write word in child's I space */ 411541Srgrimes#define PT_WRITE_D 5 /* write word in child's D space */ 4281265Speter/* was PT_WRITE_U 6 * write word in child's user structure */ 431541Srgrimes#define PT_CONTINUE 7 /* continue the child */ 441541Srgrimes#define PT_KILL 8 /* kill the child process */ 451541Srgrimes#define PT_STEP 9 /* single step the child */ 461945Sdg 471541Srgrimes#define PT_ATTACH 10 /* trace some running process */ 481541Srgrimes#define PT_DETACH 11 /* stop tracing a process */ 4992395Sdes#define PT_IO 12 /* do I/O to/from stopped process. */ 50132016Smarcel#define PT_LWPINFO 13 /* Info about the LWP that stopped. */ 51132089Sdavidxu#define PT_GETNUMLWPS 14 /* get total number of threads */ 52132089Sdavidxu#define PT_GETLWPLIST 15 /* get thread list */ 53132089Sdavidxu#define PT_CLEARSTEP 16 /* turn off single step */ 54132089Sdavidxu#define PT_SETSTEP 17 /* turn on single step */ 55132089Sdavidxu#define PT_SUSPEND 18 /* suspend a thread */ 56132089Sdavidxu#define PT_RESUME 19 /* resume a thread */ 571541Srgrimes 58120937Srobert#define PT_TO_SCE 20 59120937Srobert#define PT_TO_SCX 21 60120937Srobert#define PT_SYSCALL 22 61120937Srobert 6292383Sdes#define PT_GETREGS 33 /* get general-purpose registers */ 6392383Sdes#define PT_SETREGS 34 /* set general-purpose registers */ 6492383Sdes#define PT_GETFPREGS 35 /* get floating-point registers */ 6592383Sdes#define PT_SETFPREGS 36 /* set floating-point registers */ 6692383Sdes#define PT_GETDBREGS 37 /* get debugging registers */ 6792383Sdes#define PT_SETDBREGS 38 /* set debugging registers */ 68132089Sdavidxu#define PT_FIRSTMACH 64 /* for machine-specific requests */ 691541Srgrimes#include <machine/ptrace.h> /* machine-specific requests, if any */ 701541Srgrimes 7192395Sdesstruct ptrace_io_desc { 7292395Sdes int piod_op; /* I/O operation */ 7392395Sdes void *piod_offs; /* child offset */ 7492395Sdes void *piod_addr; /* parent offset */ 7592395Sdes size_t piod_len; /* request length */ 7692395Sdes}; 7792395Sdes 7892395Sdes/* 7992395Sdes * Operations in piod_op. 8092395Sdes */ 8192395Sdes#define PIOD_READ_D 1 /* Read from D space */ 8292395Sdes#define PIOD_WRITE_D 2 /* Write to D space */ 8392395Sdes#define PIOD_READ_I 3 /* Read from I space */ 8492395Sdes#define PIOD_WRITE_I 4 /* Write to I space */ 8592395Sdes 86132016Smarcel/* Argument structure for PT_LWPINFO. */ 87132016Smarcelstruct ptrace_lwpinfo { 88132016Smarcel lwpid_t pl_lwpid; /* LWP described. */ 89132016Smarcel int pl_event; /* Event that stopped the LWP. */ 90132016Smarcel#define PL_EVENT_NONE 0 91132016Smarcel#define PL_EVENT_SIGNAL 1 92133337Sdavidxu int pl_flags; /* LWP flags. */ 93133337Sdavidxu#define PL_FLAG_SA 0x01 /* M:N thread */ 94133337Sdavidxu#define PL_FLAG_BOUND 0x02 /* M:N bound thread */ 95132016Smarcel}; 96132016Smarcel 9755205Speter#ifdef _KERNEL 98120937Srobert 99120937Srobert#define PTRACESTOP_SC(p, td, flag) \ 100120937Srobert if ((p)->p_flag & P_TRACED && (p)->p_stops & (flag)) { \ 101120937Srobert PROC_LOCK(p); \ 102120937Srobert ptracestop((td), SIGTRAP); \ 103145691Scperciva PROC_UNLOCK(p); \ 104120937Srobert } 105120937Srobert/* 106120937Srobert * The flags below are used for ptrace(2) tracing and have no relation 107120937Srobert * to procfs. They are stored in struct proc's p_stops member. 108120937Srobert */ 109120937Srobert#define S_PT_SCE 0x000010000 110120937Srobert#define S_PT_SCX 0x000020000 111120937Srobert 11284637Sdesint ptrace_set_pc(struct thread *_td, unsigned long _addr); 11384637Sdesint ptrace_single_step(struct thread *_td); 114132089Sdavidxuint ptrace_clear_single_step(struct thread *_td); 11584637Sdes 116118932Smarcel#ifdef __HAVE_PTRACE_MACHDEP 117118932Smarcelint cpu_ptrace(struct thread *_td, int _req, void *_addr, int _data); 118118932Smarcel#endif 119118932Smarcel 12084637Sdes/* 12184637Sdes * These are prototypes for functions that implement some of the 12284637Sdes * debugging functionality exported by procfs / linprocfs and by the 12384637Sdes * ptrace(2) syscall. They used to be part of procfs, but they don't 12484637Sdes * really belong there. 12584637Sdes */ 12684637Sdesstruct reg; 12784637Sdesstruct fpreg; 12884637Sdesstruct dbreg; 12985941Sdesstruct uio; 13085297Sdesint proc_read_regs(struct thread *_td, struct reg *_reg); 13185297Sdesint proc_write_regs(struct thread *_td, struct reg *_reg); 13285297Sdesint proc_read_fpregs(struct thread *_td, struct fpreg *_fpreg); 13385297Sdesint proc_write_fpregs(struct thread *_td, struct fpreg *_fpreg); 13485297Sdesint proc_read_dbregs(struct thread *_td, struct dbreg *_dbreg); 13585297Sdesint proc_write_dbregs(struct thread *_td, struct dbreg *_dbreg); 13685297Sdesint proc_sstep(struct thread *_td); 13784637Sdesint proc_rwmem(struct proc *_p, struct uio *_uio); 138147692Speter#ifdef COMPAT_IA32 139147692Speterstruct reg32; 140147692Speterstruct fpreg32; 141147692Speterstruct dbreg32; 142147692Speterint proc_read_regs32(struct thread *_td, struct reg32 *_reg32); 143147692Speterint proc_write_regs32(struct thread *_td, struct reg32 *_reg32); 144147692Speterint proc_read_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32); 145147692Speterint proc_write_fpregs32(struct thread *_td, struct fpreg32 *_fpreg32); 146147692Speterint proc_read_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32); 147147692Speterint proc_write_dbregs32(struct thread *_td, struct dbreg32 *_dbreg32); 148147692Speter#endif 14955205Speter#else /* !_KERNEL */ 1501541Srgrimes 1511541Srgrimes#include <sys/cdefs.h> 1521541Srgrimes 1531541Srgrimes__BEGIN_DECLS 15484637Sdesint ptrace(int _request, pid_t _pid, caddr_t _addr, int _data); 1551541Srgrimes__END_DECLS 1561541Srgrimes 15755205Speter#endif /* !_KERNEL */ 1581541Srgrimes 1591541Srgrimes#endif /* !_SYS_PTRACE_H_ */ 160