blob: d953d284c79eb585901139d0c094929769e70283 [file] [log] [blame]
Juan Cespedesd44c6b81998-09-25 14:48:42 +02001#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <sys/types.h>
6#include <sys/ptrace.h>
7#include <asm/ptrace.h>
8
Juan Cespedes5464e8d2004-07-16 18:00:50 +02009#include "ltrace.h"
Juan Cespedes5c3fe062004-06-14 18:08:37 +020010
Juan Cespedesd44c6b81998-09-25 14:48:42 +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
Ian Wienand3219f322006-02-16 06:00:00 +010019void *get_instruction_pointer(struct process *proc)
20{
21 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_PC, 0);
Juan Cespedesd44c6b81998-09-25 14:48:42 +020022}
23
Ian Wienand3219f322006-02-16 06:00:00 +010024void set_instruction_pointer(struct process *proc, void *addr)
25{
26 ptrace(PTRACE_POKEUSER, proc->pid, 4 * PT_PC, addr);
Juan Cespedes8f8282f2002-03-03 18:58:40 +010027}
28
Ian Wienand3219f322006-02-16 06:00:00 +010029void *get_stack_pointer(struct process *proc)
30{
31 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_USP, 0);
Juan Cespedesd44c6b81998-09-25 14:48:42 +020032}
33
Ian Wienand3219f322006-02-16 06:00:00 +010034void *get_return_addr(struct process *proc, void *stack_pointer)
35{
Juan Cespedes5c3fe062004-06-14 18:08:37 +020036 return (void *)ptrace(PTRACE_PEEKTEXT, proc->pid, stack_pointer, 0);
Juan Cespedesd44c6b81998-09-25 14:48:42 +020037}