| Juan Cespedes | d44c6b8 | 1998-09-25 14:48:42 +0200 | [diff] [blame] | 1 | #if HAVE_CONFIG_H |
| 2 | #include "config.h" |
| 3 | #endif |
| 4 | |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 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 | |
| 21 | /* syscall tracing protocol: ArmLinux |
| 22 | on the way in, ip is 0 |
| 23 | on the way out, ip is non-zero |
| 24 | */ |
| 25 | #define off_r0 0 |
| 26 | #define off_ip 48 |
| 27 | #define off_pc 60 |
| 28 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 29 | void get_arch_dep(struct process *proc) |
| 30 | { |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 31 | } |
| 32 | |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 33 | /* Returns 1 if syscall, 2 if sysret, 0 otherwise. |
| 34 | */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 35 | int syscall_p(struct process *proc, int status, int *sysnum) |
| 36 | { |
| 37 | if (WIFSTOPPED(status) |
| 38 | && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) { |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 39 | /* get the user's pc (plus 8) */ |
| 40 | int pc = ptrace(PTRACE_PEEKUSER, proc->pid, off_pc, 0); |
| 41 | /* fetch the SWI instruction */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 42 | int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0); |
| 43 | |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 44 | *sysnum = insn & 0xFFFF; |
| 45 | /* if it is a syscall, return 1 or 2 */ |
| 46 | if ((insn & 0xFFFF0000) == 0xef900000) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 47 | return ptrace(PTRACE_PEEKUSER, proc->pid, off_ip, |
| 48 | 0) ? 2 : 1; |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | return 0; |
| 52 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 53 | |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame^] | 54 | long gimme_arg(enum tof type, struct process *proc, arg_type_info *info) |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 55 | { |
| Steve Fink | 65b53df | 2006-09-25 02:27:08 +0200 | [diff] [blame^] | 56 | int arg_num = info->arg_num; |
| 57 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 58 | if (arg_num == -1) { /* return value */ |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 59 | return ptrace(PTRACE_PEEKUSER, proc->pid, off_r0, 0); |
| 60 | } |
| 61 | |
| 62 | /* deal with the ARM calling conventions */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 63 | if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) { |
| 64 | if (arg_num < 4) { |
| 65 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, |
| 66 | 0); |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 67 | } else { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 68 | return ptrace(PTRACE_PEEKDATA, proc->pid, |
| 69 | proc->stack_pointer + 4 * (arg_num - 4), |
| 70 | 0); |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 71 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 72 | } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) { |
| 73 | if (arg_num < 5) { |
| 74 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, |
| 75 | 0); |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 76 | } else { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 77 | return ptrace(PTRACE_PEEKDATA, proc->pid, |
| 78 | proc->stack_pointer + 4 * (arg_num - 5), |
| 79 | 0); |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 80 | } |
| 81 | } else { |
| 82 | fprintf(stderr, "gimme_arg called with wrong arguments\n"); |
| 83 | exit(1); |
| 84 | } |
| 85 | |
| 86 | return 0; |
| 87 | } |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 88 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 89 | void save_register_args(enum tof type, struct process *proc) |
| 90 | { |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 91 | } |