| 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 | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 5 | #include <sys/types.h> |
| 6 | #include <sys/ptrace.h> |
| Juan Cespedes | 64c6dfb | 1998-07-14 13:49:47 +0200 | [diff] [blame] | 7 | #include <asm/ptrace.h> |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 8 | |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 9 | #include "ltrace.h" |
| 10 | |
| Juan Cespedes | 5e0acdb | 1998-04-04 08:34:07 +0200 | [diff] [blame] | 11 | #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) |
| 12 | # define PTRACE_PEEKUSER PTRACE_PEEKUSR |
| 13 | #endif |
| 14 | |
| 15 | #if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) |
| 16 | # define PTRACE_POKEUSER PTRACE_POKEUSR |
| 17 | #endif |
| 18 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame^] | 19 | void * |
| 20 | get_instruction_pointer(struct process *proc) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 21 | return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EIP, 0); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 22 | } |
| 23 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame^] | 24 | void |
| 25 | set_instruction_pointer(struct process *proc, void *addr) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 26 | ptrace(PTRACE_POKEUSER, proc->pid, 4 * EIP, (long)addr); |
| Juan Cespedes | 8f8282f | 2002-03-03 18:58:40 +0100 | [diff] [blame] | 27 | } |
| 28 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame^] | 29 | void * |
| 30 | get_stack_pointer(struct process *proc) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 31 | return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * UESP, 0); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame^] | 34 | void * |
| 35 | get_return_addr(struct process *proc, void *stack_pointer) { |
| Juan Cespedes | 5c3fe06 | 2004-06-14 18:08:37 +0200 | [diff] [blame] | 36 | return (void *)ptrace(PTRACE_PEEKTEXT, proc->pid, stack_pointer, 0); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 37 | } |