Imported Upstream version 0.5.3
[platform/upstream/ltrace.git] / sysdeps / linux-gnu / arm / regs.c
1 #include "config.h"
2
3 #include <sys/types.h>
4 #include <sys/ptrace.h>
5 #include <asm/ptrace.h>
6
7 #include "common.h"
8
9 #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR))
10 # define PTRACE_PEEKUSER PTRACE_PEEKUSR
11 #endif
12
13 #if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR))
14 # define PTRACE_POKEUSER PTRACE_POKEUSR
15 #endif
16
17 #define off_pc 60
18 #define off_lr 56
19 #define off_sp 52
20
21 void *
22 get_instruction_pointer(Process *proc) {
23         return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_pc, 0);
24 }
25
26 void
27 set_instruction_pointer(Process *proc, void *addr) {
28         ptrace(PTRACE_POKEUSER, proc->pid, off_pc, addr);
29 }
30
31 void *
32 get_stack_pointer(Process *proc) {
33         return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_sp, 0);
34 }
35
36 /* really, this is given the *stack_pointer expecting
37  * a CISC architecture; in our case, we don't need that */
38 void *
39 get_return_addr(Process *proc, void *stack_pointer) {
40         long addr = ptrace(PTRACE_PEEKUSER, proc->pid, off_lr, 0);
41
42         proc->thumb_mode = addr & 1;
43         if (proc->thumb_mode)
44                 addr &= ~1;
45         return (void *)addr;
46 }
47
48 void
49 set_return_addr(Process *proc, void *addr) {
50         ptrace(PTRACE_POKEUSER, proc->pid, off_lr, addr);
51 }