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