trace.c revision 3219f320604810532a4938dda8f9dfadb0e840f3
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 11#include "ltrace.h" 12 13#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) 14# define PTRACE_PEEKUSER PTRACE_PEEKUSR 15#endif 16 17#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) 18# define PTRACE_POKEUSER PTRACE_POKEUSR 19#endif 20 21void get_arch_dep(struct process *proc) 22{ 23} 24 25/* Returns 1 if syscall, 2 if sysret, 0 otherwise. 26 */ 27#define SYSCALL_INSN 0x44000002 28int syscall_p(struct process *proc, int status, int *sysnum) 29{ 30 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) { 31 int pc = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_NIP, 0); 32 int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0); 33 34 if (insn == SYSCALL_INSN) { 35 *sysnum = 36 ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_R0, 0); 37 if (proc->callstack_depth > 0 38 && proc->callstack[proc->callstack_depth - 39 1].is_syscall) { 40 return 2; 41 } 42 return 1; 43 } 44 } 45 return 0; 46} 47 48long gimme_arg(enum tof type, struct process *proc, int arg_num) 49{ 50 if (arg_num == -1) { /* return value */ 51 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_R3, 0); 52 } else if (arg_num < 8) { 53 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * (arg_num + PT_R3), 54 0); 55 } else { 56 return ptrace(PTRACE_PEEKDATA, proc->pid, 57 proc->stack_pointer + 8 * (arg_num - 8), 0); 58 } 59 return 0; 60} 61 62void save_register_args(enum tof type, struct process *proc) 63{ 64} 65