regs.c revision 5c3fe0697b202cc7d95e90459de0fb312b297b27
1#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
9#include "ltrace.h"
10
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
19void *
20get_instruction_pointer(struct process * proc) {
21	return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_NIP, 0);
22}
23
24void
25set_instruction_pointer(struct process * proc, long addr) {
26	ptrace(PTRACE_POKEUSER, proc->pid, 4*PT_NIP, addr);
27}
28
29void *
30get_stack_pointer(struct process * proc) {
31	return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_R1, 0);
32}
33
34void *
35get_return_addr(struct process * proc, void * stack_pointer) {
36	return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_LNK, 0);
37}
38