1 /*
2 * This file is part of ltrace.
3 * Copyright (C) 2013 Petr Machata, Red Hat Inc.
4 * Copyright (C) 2004,2008,2009 Juan Cespedes
5 * Copyright (C) 2006 Ian Wienand
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23 #include "config.h"
24
25 #include <sys/types.h>
26 #include "ptrace.h"
27 #include "proc.h"
28 #include "common.h"
29
30 void *
get_instruction_pointer(struct process * proc)31 get_instruction_pointer(struct process *proc)
32 {
33 proc_archdep *a = (proc_archdep *) (proc->arch_ptr);
34 if (a->valid)
35 return (void *)a->regs.pc;
36 return (void *)-1;
37 }
38
39 void
set_instruction_pointer(struct process * proc,void * addr)40 set_instruction_pointer(struct process *proc, void *addr)
41 {
42 proc_archdep *a = (proc_archdep *) (proc->arch_ptr);
43 if (a->valid)
44 a->regs.pc = (long)addr;
45 }
46
47 void *
get_stack_pointer(struct process * proc)48 get_stack_pointer(struct process *proc)
49 {
50 proc_archdep *a = (proc_archdep *) (proc->arch_ptr);
51 if (a->valid)
52 return (void *)a->regs.u_regs[UREG_I5];
53 return (void *)-1;
54 }
55
56 void *
get_return_addr(struct process * proc,void * stack_pointer)57 get_return_addr(struct process *proc, void *stack_pointer)
58 {
59 proc_archdep *a = (proc_archdep *) (proc->arch_ptr);
60 unsigned int t;
61 if (!a->valid)
62 return (void *)-1;
63 /* Work around structure returns */
64 t = ptrace(PTRACE_PEEKTEXT, proc->pid, a->regs.u_regs[UREG_I6] + 8, 0);
65 if (t < 0x400000)
66 return (void *)a->regs.u_regs[UREG_I6] + 12;
67 return (void *)a->regs.u_regs[UREG_I6] + 8;
68 }
69