regs.c revision 929bd57ca202fd2f2e8485ebf65d683e664f67b5
1/* 2 * This file is part of ltrace. 3 * Copyright (C) 2004,2008,2009 Juan Cespedes 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation; either version 2 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 * 02110-1301 USA 19 */ 20 21#include "config.h" 22 23#include <sys/types.h> 24#include <sys/ptrace.h> 25#include <asm/ptrace.h> 26 27#include "proc.h" 28#include "common.h" 29 30#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) 31# define PTRACE_PEEKUSER PTRACE_PEEKUSR 32#endif 33 34#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) 35# define PTRACE_POKEUSER PTRACE_POKEUSR 36#endif 37 38void * 39get_instruction_pointer(struct process *proc) 40{ 41 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 64 /* REG_PC */ , 0); 42} 43 44void 45set_instruction_pointer(struct process *proc, void *addr) 46{ 47 ptrace(PTRACE_POKEUSER, proc->pid, 64 /* REG_PC */ , addr); 48} 49 50void * 51get_stack_pointer(struct process *proc) 52{ 53 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 30 /* REG_FP */ , 0); 54} 55 56void * 57get_return_addr(struct process *proc, void *stack_pointer) 58{ 59 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 26 /* RA */ , 0); 60} 61 62void 63set_return_addr(struct process *proc, void *addr) 64{ 65 ptrace(PTRACE_POKEUSER, proc->pid, 26 /* RA */ , addr); 66} 67