trace.c revision b1dda4bc2c78429823a5ca7699f3207a7aea2371
1#if HAVE_CONFIG_H 2#include "config.h" 3#endif 4 5#include <sys/types.h> 6#include <sys/wait.h> 7#include <signal.h> 8#include <sys/ptrace.h> 9#include <asm/ptrace.h> 10#include <elf.h> 11 12#include "common.h" 13 14#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) 15# define PTRACE_PEEKUSER PTRACE_PEEKUSR 16#endif 17 18#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) 19# define PTRACE_POKEUSER PTRACE_POKEUSR 20#endif 21 22void get_arch_dep(Process *proc) 23{ 24} 25 26/* Returns 1 if syscall, 2 if sysret, 0 otherwise. 27 */ 28#define SYSCALL_INSN 0xe93d 29int syscall_p(Process *proc, int status, int *sysnum) 30{ 31 if (WIFSTOPPED(status) 32 && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) { 33 long pc = (long)get_instruction_pointer(proc); 34 unsigned int insn = 35 (int)ptrace(PTRACE_PEEKTEXT, proc->pid, pc - sizeof(long), 36 0); 37 38 if ((insn >> 16) == SYSCALL_INSN) { 39 *sysnum = 40 (int)ptrace(PTRACE_PEEKUSER, proc->pid, 41 sizeof(long) * PT_R9, 0); 42 if (proc->callstack_depth > 0 43 && proc->callstack[proc->callstack_depth - 44 1].is_syscall) { 45 return 2; 46 } 47 return 1; 48 } 49 } 50 return 0; 51} 52 53long gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info) 54{ 55 int pid = proc->pid; 56 57 if (arg_num == -1) { /* return value */ 58 return ptrace(PTRACE_PEEKUSER, pid, PT_R10 * 4, 0); 59 } else if (arg_num < 6) { 60 int pt_arg[6] = 61 { 62 PT_ORIG_R10, PT_R11, PT_R12, PT_R13, PT_MOF, 63 PT_SRP 64 }; 65 return ptrace(PTRACE_PEEKUSER, pid, pt_arg[arg_num] * 4, 0); 66 } else { 67 return ptrace(PTRACE_PEEKDATA, pid, 68 proc->stack_pointer + 4 * (arg_num - 6), 0); 69 } 70 return 0; 71} 72 73void save_register_args(enum tof type, Process *proc) 74{ 75} 76