regs.c revision bc0de433c25d224cf5f4743ba4a78131267c532d
1/* 2 * This file is part of ltrace. 3 * Copyright (C) 2008,2009 Juan Cespedes 4 * Copyright (C) 2006 Eric Vaitl, Cisco Systems, Inc. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of the 9 * License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 19 * 02110-1301 USA 20 */ 21 22#include "config.h" 23 24#include <stddef.h> 25#include <sys/types.h> 26#include <sys/ptrace.h> 27#include <asm/ptrace.h> 28 29#include "proc.h" 30#include "common.h" 31#include "mips.h" 32 33#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) 34# define PTRACE_PEEKUSER PTRACE_PEEKUSR 35#endif 36 37#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) 38# define PTRACE_POKEUSER PTRACE_POKEUSR 39#endif 40 41/** 42 \addtogroup mips 43 @{ 44 */ 45 46 47/** 48 \param proc The process to work on. 49 \return The current instruction pointer. 50 */ 51void * 52get_instruction_pointer(struct process *proc) 53{ 54 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_pc, 0); 55} 56 57/** 58 \param proc The process to work on. 59 \param addr The address to set to. 60 61 Called by \c continue_after_breakpoint(). 62 63 \todo Our mips kernel ptrace doesn't support PTRACE_SINGLESTEP, so 64 we \c continue_process() after a breakpoint. Check if this is OK. 65 */ 66void 67set_instruction_pointer(struct process *proc, void *addr) 68{ 69 ptrace(PTRACE_POKEUSER, proc->pid, off_pc, addr); 70} 71 72/** 73 \param proc The process to work on. 74 \return The current stack pointer. 75 */ 76void * 77get_stack_pointer(struct process *proc) 78{ 79 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_sp, 0); 80} 81 82/** 83 \param proc The process to work on. 84 \param stack_pointer The current stack pointer for proc 85 \return The current return address. 86 87 Called by \c handle_breakpoint(). 88 89 Mips uses r31 for the return address, so the stack_pointer is 90 unused. 91 */ 92void * 93get_return_addr(struct process *proc, void *stack_pointer) 94{ 95 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_lr, 0); 96} 97 98void 99set_return_addr(struct process *proc, void *addr) 100{ 101 ptrace(PTRACE_POKEUSER, proc->pid, off_lr, addr); 102} 103