trace.c revision 366c2f46d844f040458df9b7e35fc3b8527ed2d3
1#include "config.h"
2
3#include <sys/types.h>
4#include <sys/wait.h>
5#include <signal.h>
6#include <sys/ptrace.h>
7#include <asm/ptrace.h>
8
9#include "proc.h"
10#include "common.h"
11#include "debug.h"
12
13#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR))
14# define PTRACE_PEEKUSER PTRACE_PEEKUSR
15#endif
16
17#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR))
18# define PTRACE_POKEUSER PTRACE_POKEUSR
19#endif
20
21void
22get_arch_dep(Process *proc) {
23}
24
25/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
26 */
27int
28syscall_p(Process *proc, int status, int *sysnum) {
29	if (WIFSTOPPED(status)
30	    && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) {
31		char *ip = get_instruction_pointer(proc) - 4;
32		long x = ptrace(PTRACE_PEEKTEXT, proc->pid, ip, 0);
33		debug(2, "instr: %016lx", x);
34		if ((x & 0xffffffff) != 0x00000083)
35			return 0;
36		*sysnum =
37		    ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */ , 0);
38		if (proc->callstack_depth > 0 &&
39		    proc->callstack[proc->callstack_depth - 1].is_syscall &&
40			proc->callstack[proc->callstack_depth - 1].c_un.syscall == *sysnum) {
41			return 2;
42		}
43		if (*sysnum >= 0 && *sysnum < 500) {
44			return 1;
45		}
46	}
47	return 0;
48}
49
50long
51gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info) {
52	if (arg_num == -1) {	/* return value */
53		return ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */ , 0);
54	}
55
56	if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
57		if (arg_num <= 5)
58			return ptrace(PTRACE_PEEKUSER, proc->pid,
59				      arg_num + 16 /* REG_A0 */ , 0);
60		else
61			return ptrace(PTRACE_PEEKTEXT, proc->pid,
62				      proc->stack_pointer + 8 * (arg_num - 6),
63				      0);
64	} else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) {
65		return ptrace(PTRACE_PEEKUSER, proc->pid,
66			      arg_num + 16 /* REG_A0 */ , 0);
67	} else {
68		fprintf(stderr, "gimme_arg called with wrong arguments\n");
69		exit(1);
70	}
71	return 0;
72}
73
74void
75save_register_args(enum tof type, Process *proc) {
76}
77