diff options
| author | sef <sef@NetBSD.org> | 1993-09-05 03:53:52 +0000 |
|---|---|---|
| committer | sef <sef@NetBSD.org> | 1993-09-05 03:53:52 +0000 |
| commit | b477be52eb71efdc7e09cec48ca89ca0d90eb676 (patch) | |
| tree | 5ab4d4ca81c2f9cbc2fc5b98d3ca3d0a03df6f42 /sys | |
| parent | 15359c9f59525c9589c3f3b86111e7c73da78fe7 (diff) | |
Yet more of the ptrace() reorg; now ptrace_setregs() and ptrace_getregs()
are present, along with PT_GETREGS and PT_SETREGS ptrace commands.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arch/i386/i386/machdep.c | 113 | ||||
| -rw-r--r-- | sys/arch/i386/include/reg.h | 30 | ||||
| -rw-r--r-- | sys/kern/sys_process.c | 2 | ||||
| -rw-r--r-- | sys/sys/ptrace.h | 5 |
4 files changed, 139 insertions, 11 deletions
diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 24ba6fde716..060b52ec840 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.46 1993/09/05 01:31:39 cgd Exp $ + * $Id: machdep.c,v 1.47 1993/09/05 03:54:11 sef Exp $ */ #include "npx.h" @@ -1518,3 +1518,114 @@ ptrace_single_step (struct proc *p) { ((struct syscframe *)regs)->sf_eflags |= PSL_T; return 0; } +/* + * Copy the registers to user-space. This is tedious because + * we essentially duplicate code for trapframe and syscframe. *sigh* + */ + +int +ptrace_getregs (struct proc *p, unsigned int *addr) { + int error; + struct trapframe *tp; + struct syscframe *sp; + struct pcb *pcb; + struct regs regs = {0}; + void *ptr = (char*)p->p_addr + + ((char*) p->p_regs - (char*) kstack); + + pcb = &p->p_addr->u_pcb; + if (pcb->pcb_flags & FM_TRAP) { + tp = ptr; + regs.r_es = tp->tf_es; + regs.r_ds = tp->tf_ds; + regs.r_edi = tp->tf_edi; + regs.r_esi = tp->tf_esi; + regs.r_ebp = tp->tf_ebp; + regs.r_ebx = tp->tf_ebx; + regs.r_edx = tp->tf_edx; + regs.r_ecx = tp->tf_ecx; + regs.r_eax = tp->tf_eax; + regs.r_eip = tp->tf_eip; + regs.r_cs = tp->tf_cs; + regs.r_eflags = tp->tf_eflags; + regs.r_esp = tp->tf_esp; + regs.r_ss = tp->tf_ss; + } else { + sp = ptr; + /* + * No sf_es or sf_ds... dunno why. + */ + /* + * regs.r_es = sp->sf_es; + * regs.r_ds = sp->sf_ds; + */ + regs.r_edi = sp->sf_edi; + regs.r_esi = sp->sf_esi; + regs.r_ebp = sp->sf_ebp; + regs.r_ebx = sp->sf_ebx; + regs.r_edx = sp->sf_edx; + regs.r_ecx = sp->sf_ecx; + regs.r_eax = sp->sf_eax; + regs.r_eip = sp->sf_eip; + regs.r_cs = sp->sf_cs; + regs.r_eflags = sp->sf_eflags; + regs.r_esp = sp->sf_esp; + regs.r_ss = sp->sf_ss; + } + return copyout (®s, addr, sizeof (regs)); +} + +int +ptrace_setregs (struct proc *p, unsigned int *addr) { + int error; + struct trapframe *tp; + struct syscframe *sp; + struct pcb *pcb; + struct regs regs = {0}; + void *ptr = (char*)p->p_addr + + ((char*) p->p_regs - (char*) kstack); + + if (error = copyin (addr, ®s, sizeof(regs))) + return error; + + pcb = &p->p_addr->u_pcb; + if (pcb->pcb_flags & FM_TRAP) { + tp = ptr; + tp->tf_es = regs.r_es; + tp->tf_ds = regs.r_ds; + tp->tf_edi = regs.r_edi; + tp->tf_esi = regs.r_esi; + tp->tf_ebp = regs.r_ebp; + tp->tf_ebx = regs.r_ebx; + tp->tf_edx = regs.r_edx; + tp->tf_ecx = regs.r_ecx; + tp->tf_eax = regs.r_eax; + tp->tf_eip = regs.r_eip; + tp->tf_cs = regs.r_cs; + tp->tf_eflags = regs.r_eflags; + tp->tf_esp = regs.r_esp; + tp->tf_ss = regs.r_ss; + } else { + sp = ptr; + /* + * No sf_es or sf_ds members, dunno why... + */ + /* + * sp->sf_es = regs.r_es; + * sp->sf_ds = regs.r_ds; + */ + sp->sf_edi = regs.r_edi; + sp->sf_esi = regs.r_esi; + sp->sf_ebp = regs.r_ebp; + sp->sf_ebx = regs.r_ebx; + sp->sf_edx = regs.r_edx; + sp->sf_ecx = regs.r_ecx; + sp->sf_eax = regs.r_eax; + sp->sf_eip = regs.r_eip; + sp->sf_cs = regs.r_cs; + regs.r_eflags = sp->sf_eflags; + regs.r_esp = sp->sf_esp; + regs.r_ss = sp->sf_ss; + } + return 0; +} diff --git a/sys/arch/i386/include/reg.h b/sys/arch/i386/include/reg.h index 37e2051871c..bda590ca198 100644 --- a/sys/arch/i386/include/reg.h +++ b/sys/arch/i386/include/reg.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)reg.h 5.5 (Berkeley) 1/18/91 - * $Id: reg.h,v 1.3 1993/05/24 11:37:21 cgd Exp $ + * $Id: reg.h,v 1.4 1993/09/05 03:54:15 sef Exp $ */ /* @@ -86,11 +86,25 @@ #define R1 sECX /* * Registers accessible to ptrace(2) syscall for debugger + * The machine-dependent code for PT_{SET,GET}REGS needs to + * use whichver order, defined above, is correct, so that it + * is all invisible to the user. */ -#ifdef IPCREG -#define NIPCREG 14 -int ipcreg[NIPCREG] = - { tES,tDS,tEDI,tESI,tEBP,tEBX,tEDX,tECX,tEAX,tEIP,tCS,tEFLAGS,tESP,tSS }; -int sipcreg[NIPCREG] = /* Should we define a structure with all regs? XXX */ - { 0, 0, sEDI,sESI,sEBP,sEBX,sEDX,sECX,sEAX,sEIP,sCS,sEFLAGS,sESP,sSS }; -#endif +struct regs { + unsigned int r_es; + unsigned int r_ds; + unsigned int r_edi; + unsigned int r_esi; + unsigned int r_ebp; + unsigned int r_ebx; + unsigned int r_edx; + unsigned int r_ecx; + unsigned int r_eax; + unsigned int r_eip; + unsigned int r_cs; + unsigned int r_eflags; + unsigned int r_esp; + unsigned int r_ss; + unsigned int r_fs; + unsigned int r_gs; +}; diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 3dc887baafe..b5140f51032 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1 +1 @@ -revision 1.10 intentionally removed +revision 1.11 intentionally removed diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index ae0ed4d3892..3267ca81c48 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * from: @(#)ptrace.h 7.4 (Berkeley) 2/22/91 - * $Id: ptrace.h,v 1.4 1993/09/04 05:32:42 cgd Exp $ + * $Id: ptrace.h,v 1.5 1993/09/05 03:54:18 sef Exp $ */ #ifndef _SYS_PTRACE_H_ @@ -49,6 +49,9 @@ #define PT_STEP 9 /* single step the child */ /*#define PT_ATTACH 10 /* attach to running process */ /*#define PT_DETACH 11 /* detach from running process */ +#define PT_GETREGS 12 /* fetch registers */ +#define PT_SETREGS 13 /* set registers */ + #ifndef KERNEL #include <sys/cdefs.h> |
