blob: 19d9572e11df05ae14483bbb469e4dc40e6e680a [file] [log] [blame]
Juan Cespedesd44c6b81998-09-25 14:48:42 +02001#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
Juan Cespedes5e01f651998-03-08 22:31:44 +01005#include <sys/types.h>
6#include <sys/ptrace.h>
Juan Cespedes64c6dfb1998-07-14 13:49:47 +02007#include <asm/ptrace.h>
Juan Cespedes5e01f651998-03-08 22:31:44 +01008
Juan Cespedes5c3fe062004-06-14 18:08:37 +02009#include "ltrace.h"
10
Juan Cespedes5e0acdb1998-04-04 08:34:07 +020011#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 Cespedesf1350522008-12-16 18:19:58 +010019void *
20get_instruction_pointer(struct process *proc) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +010021 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EIP, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +010022}
23
Juan Cespedesf1350522008-12-16 18:19:58 +010024void
25set_instruction_pointer(struct process *proc, void *addr) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +010026 ptrace(PTRACE_POKEUSER, proc->pid, 4 * EIP, (long)addr);
Juan Cespedes8f8282f2002-03-03 18:58:40 +010027}
28
Juan Cespedesf1350522008-12-16 18:19:58 +010029void *
30get_stack_pointer(struct process *proc) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +010031 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * UESP, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +010032}
33
Juan Cespedesf1350522008-12-16 18:19:58 +010034void *
35get_return_addr(struct process *proc, void *stack_pointer) {
Juan Cespedes5c3fe062004-06-14 18:08:37 +020036 return (void *)ptrace(PTRACE_PEEKTEXT, proc->pid, stack_pointer, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +010037}