6 #include <sys/ptrace.h>
7 #include <asm/ptrace.h>
11 #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR))
12 # define PTRACE_PEEKUSER PTRACE_PEEKUSR
15 #if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR))
16 # define PTRACE_POKEUSER PTRACE_POKEUSR
21 \addtogroup mipsel Mipsel specific functions.
23 These are the functions that it looks like I need to implement in
24 order to get ltrace to work on our target.
30 \param proc The process that had an event.
32 Called by \c next_event() right after the return from wait.
34 Most targets just return here. A couple use proc->arch_ptr for a
38 get_arch_dep(Process *proc) {
42 \param proc Process that had event.
43 \param status From \c wait()
44 \param sysnum 0-based syscall number.
45 \return 1 if syscall, 2 if sysret, 0 otherwise.
47 Called by \c next_event() after the call to get_arch_dep()
49 It seems that the ptrace call trips twice on a system call, once
50 just before the system call and once when it returns. Both times,
51 the pc points at the instruction just after the mipsel "syscall"
54 There are several possiblities for system call sets, each is offset
55 by a base from the others. On our system, it looks like the base
56 for the system calls is 4000.
59 syscall_p(Process *proc, int status, int *sysnum) {
60 if (WIFSTOPPED(status)
61 && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) {
62 /* get the user's pc (plus 8) */
63 long pc = (long)get_instruction_pointer(proc);
64 /* fetch the SWI instruction */
65 int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0);
66 int num = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 8, 0);
69 On a mipsel, syscall looks like:
70 24040fa1 li v0, 0x0fa1 # 4001 --> _exit syscall
77 *sysnum = (num & 0xFFFF) - 4000;
78 /* if it is a syscall, return 1 or 2 */
79 if (proc->callstack_depth > 0 &&
80 proc->callstack[proc->callstack_depth - 1].is_syscall &&
81 proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
92 \param type Function/syscall call or return.
93 \param proc The process that had an event.
94 \param arg_num -1 for return value,
95 \return The argument to fetch.
97 A couple of assumptions.
99 - Type is LT_TOF_FUNCTIONR or LT_TOF_SYSCALLR if arg_num==-1. These
100 types are only used in calls for output_right(), which only uses -1
102 - Type is LT_TOF_FUNCTION or LT_TOF_SYSCALL for args 0...4.
103 - I'm only displaying the first 4 args (Registers a0..a3). Good
106 Mipsel conventions seem to be:
107 - syscall parameters: r4...r9
108 - syscall return: if(!a3){ return v0;} else{ errno=v0;return -1;}
109 - function call: r4..r7. Not sure how to get arg number 5.
110 - function return: v0
112 The argument registers are wiped by a call, so it is a mistake to ask
113 for arguments on a return. If ltrace does this, we will need to cache
114 arguments somewhere on the call.
116 I'm not doing any floating point support here.
120 gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info) {
122 debug(2,"type %d arg %d",type,arg_num);
123 if (type == LT_TOF_FUNCTION || type == LT_TOF_SYSCALL){
125 ret=ptrace(PTRACE_PEEKUSER,proc->pid,off_a0+arg_num,0);
126 debug(2,"ret = %#lx",ret);
129 // If we need this, I think we can look at [sp+16] for arg_num==4.
135 fprintf(stderr,"args on return?");
137 if(type == LT_TOF_FUNCTIONR) {
138 return ptrace(PTRACE_PEEKUSER,proc->pid,off_v0,0);
140 if (type == LT_TOF_SYSCALLR) {
141 unsigned a3=ptrace(PTRACE_PEEKUSER, proc->pid,off_a3,0);
142 unsigned v0=ptrace(PTRACE_PEEKUSER, proc->pid,off_v0,0);
148 fprintf(stderr, "gimme_arg called with wrong arguments\n");
153 \param type Type of call/return
154 \param proc Process to work with.
156 Called by \c output_left(), which is called on a syscall or
159 The other architectures stub this out, but seems to be the place to
160 stash off the arguments on a call so we have them on the return.
164 save_register_args(enum tof type, Process *proc) {