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 | 504a385 | 2003-02-04 23:24:38 +0100 | [diff] [blame] | 5 | #include <stdlib.h> |
Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 6 | #include <sys/types.h> |
| 7 | #include <sys/wait.h> |
| 8 | #include <signal.h> |
| 9 | #include <sys/ptrace.h> |
Juan Cespedes | 64c6dfb | 1998-07-14 13:49:47 +0200 | [diff] [blame] | 10 | #include <asm/ptrace.h> |
Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 11 | |
| 12 | #include "ltrace.h" |
| 13 | |
Juan Cespedes | 5e0acdb | 1998-04-04 08:34:07 +0200 | [diff] [blame] | 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 | |
Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 22 | void |
Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 23 | get_arch_dep(Process *proc) { |
Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 24 | } |
| 25 | |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 26 | /* Returns 1 if syscall, 2 if sysret, 0 otherwise. |
Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 27 | */ |
Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 28 | int |
Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 29 | syscall_p(Process *proc, int status, int *sysnum) { |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 30 | if (WIFSTOPPED(status) |
| 31 | && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) { |
| 32 | *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ORIG_EAX, 0); |
Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 33 | |
| 34 | if (proc->callstack_depth > 0 && |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 35 | proc->callstack[proc->callstack_depth - 1].is_syscall) { |
Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 36 | return 2; |
| 37 | } |
| 38 | |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 39 | if (*sysnum >= 0) { |
Juan Cespedes | 21c63a1 | 2001-07-07 20:56:56 +0200 | [diff] [blame] | 40 | return 1; |
Juan Cespedes | f0fdae9 | 1998-03-11 00:03:00 +0100 | [diff] [blame] | 41 | } |
| 42 | } |
Juan Cespedes | 35d7063 | 1998-03-15 14:05:40 +0100 | [diff] [blame] | 43 | return 0; |
Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 46 | long |
Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 47 | gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info) { |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 48 | if (arg_num == -1) { /* return value */ |
| 49 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EAX, 0); |
Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 52 | if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) { |
| 53 | return ptrace(PTRACE_PEEKTEXT, proc->pid, |
| 54 | proc->stack_pointer + 4 * (arg_num + 1), 0); |
| 55 | } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) { |
Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 56 | #if 0 |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 57 | switch (arg_num) { |
| 58 | case 0: |
| 59 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EBX, 0); |
| 60 | case 1: |
| 61 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ECX, 0); |
| 62 | case 2: |
| 63 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDX, 0); |
| 64 | case 3: |
| 65 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ESI, 0); |
| 66 | case 4: |
| 67 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDI, 0); |
| 68 | default: |
| 69 | fprintf(stderr, |
| 70 | "gimme_arg called with wrong arguments\n"); |
| 71 | exit(2); |
Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 72 | } |
| 73 | #else |
Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 74 | return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, 0); |
Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 75 | #endif |
| 76 | } else { |
| 77 | fprintf(stderr, "gimme_arg called with wrong arguments\n"); |
| 78 | exit(1); |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 83 | |
Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 84 | void |
Juan Cespedes | a8909f7 | 2009-04-28 20:02:41 +0200 | [diff] [blame] | 85 | save_register_args(enum tof type, Process *proc) { |
Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 86 | } |