regs.c revision 5570a7769869a4df25ef85f302f74a7feb6c0cd3
1#if HAVE_CONFIG_H 2#include "config.h" 3#endif 4 5#include <sys/types.h> 6#include <sys/ptrace.h> 7 8#include <asm/ptrace_offsets.h> 9#include <asm/rse.h> 10 11#include <stddef.h> 12#include "debug.h" 13#include "ltrace.h" 14 15void * 16get_instruction_pointer(struct process * proc) { 17 unsigned long ip = ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IIP, 0); 18 unsigned long slot = (ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IPSR, 0) >> 41) & 3; 19 20 return (void*)(ip | slot); 21} 22 23void 24set_instruction_pointer(struct process * proc, void * addr) { 25 26 unsigned long newip = (unsigned long)addr; 27 int slot = (int) addr & 0xf; 28 unsigned long psr = ptrace(PTRACE_PEEKUSER, proc->pid, PT_CR_IPSR, 0); 29 30 psr &= ~(3UL << 41); 31 psr |= (unsigned long)(slot & 0x3) << 41; 32 33 newip &= ~0xfUL; 34 35 ptrace(PTRACE_POKEUSER, proc->pid, PT_CR_IIP, (long)newip); 36 ptrace(PTRACE_POKEUSER, proc->pid, PT_CR_IPSR, psr); 37} 38 39void * 40get_stack_pointer(struct process * proc) { 41 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_R12, 0); 42} 43 44void * 45get_return_addr(struct process * proc, void * stack_pointer) { 46 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_B0, 0); 47} 48