| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 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 | |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame^] | 21 | void |
| 22 | get_arch_dep(struct process * proc) { |
| 23 | } |
| 24 | |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 25 | /* Returns 1 if syscall, 2 if sysret, 0 otherwise. |
| 26 | */ |
| Juan Cespedes | b1dd77d | 2002-03-03 00:22:06 +0100 | [diff] [blame] | 27 | int |
| 28 | syscall_p(struct process * proc, int status, int * sysnum) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 29 | int depth; |
| 30 | |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 31 | if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) { |
| 32 | *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_ORIG_D0, 0); |
| 33 | if (*sysnum == -1) return 0; |
| 34 | if (*sysnum>=0) { |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 35 | depth = proc->callstack_depth; |
| 36 | if (depth>0 && |
| 37 | proc->callstack[depth-1].is_syscall && |
| 38 | proc->callstack[depth-1].c_un.syscall==*sysnum) { |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 39 | return 2; |
| Juan Cespedes | 5b3ffdf | 2001-07-02 00:52:45 +0200 | [diff] [blame] | 40 | } else { |
| 41 | return 1; |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | } |
| 45 | return 0; |
| 46 | } |
| 47 | |
| Juan Cespedes | b1dd77d | 2002-03-03 00:22:06 +0100 | [diff] [blame] | 48 | long |
| 49 | gimme_arg(enum tof type, struct process * proc, int arg_num) { |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 50 | if (arg_num==-1) { /* return value */ |
| 51 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D0, 0); |
| 52 | } |
| 53 | |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame^] | 54 | if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) { |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 55 | return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+4*(arg_num+1), 0); |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame^] | 56 | } else if (type==LT_TOF_SYSCALL || type==LT_TOF_SYSCALLR) { |
| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 57 | #if 0 |
| 58 | switch(arg_num) { |
| 59 | case 0: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D1, 0); |
| 60 | case 1: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D2, 0); |
| 61 | case 2: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D3, 0); |
| 62 | case 3: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D4, 0); |
| 63 | case 4: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D5, 0); |
| 64 | default: |
| 65 | fprintf(stderr, "gimme_arg called with wrong arguments\n"); |
| 66 | exit(2); |
| 67 | } |
| 68 | #else |
| 69 | /* That hack works on m68k, too */ |
| 70 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4*arg_num, 0); |
| 71 | #endif |
| 72 | } else { |
| 73 | fprintf(stderr, "gimme_arg called with wrong arguments\n"); |
| 74 | exit(1); |
| 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame^] | 79 | |
| 80 | void |
| 81 | save_register_args(enum tof type, struct process * proc) { |
| 82 | } |