trace.c revision f13505251e6402460f6cc7ec84e0d8ca91607b4f
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 22get_arch_dep(struct process *proc) { 23} 24 25/* Returns 1 if syscall, 2 if sysret, 0 otherwise. 26 */ 27int 28syscall_p(struct process *proc, int status, int *sysnum) { 29 int depth; 30 31 if (WIFSTOPPED(status) 32 && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) { 33 *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_ORIG_D0, 0); 34 if (*sysnum == -1) 35 return 0; 36 if (*sysnum >= 0) { 37 depth = proc->callstack_depth; 38 if (depth > 0 && 39 proc->callstack[depth - 1].is_syscall && 40 proc->callstack[depth - 1].c_un.syscall == 41 *sysnum) { 42 return 2; 43 } else { 44 return 1; 45 } 46 } 47 } 48 return 0; 49} 50 51long 52gimme_arg(enum tof type, struct process *proc, int arg_num, arg_type_info *info) { 53 if (arg_num == -1) { /* return value */ 54 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D0, 0); 55 } 56 57 if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) { 58 return ptrace(PTRACE_PEEKTEXT, proc->pid, 59 proc->stack_pointer + 4 * (arg_num + 1), 0); 60 } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) { 61#if 0 62 switch (arg_num) { 63 case 0: 64 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D1, 0); 65 case 1: 66 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D2, 0); 67 case 2: 68 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D3, 0); 69 case 3: 70 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D4, 0); 71 case 4: 72 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D5, 0); 73 default: 74 fprintf(stderr, 75 "gimme_arg called with wrong arguments\n"); 76 exit(2); 77 } 78#else 79 /* That hack works on m68k, too */ 80 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, 0); 81#endif 82 } else { 83 fprintf(stderr, "gimme_arg called with wrong arguments\n"); 84 exit(1); 85 } 86 87 return 0; 88} 89 90void 91save_register_args(enum tof type, struct process *proc) { 92} 93