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