trace.c revision 2d45b1a8e26a36a9f85dc49e721c4390ca93dc40
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 "ltrace.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 get_arch_dep(struct process *proc)
23{
24}
25
26/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
27 */
28int syscall_p(struct process *proc, int status, int *sysnum)
29{
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			return 2;
42		}
43		if (*sysnum >= 0 && *sysnum < 500) {
44			return 1;
45		}
46	}
47	return 0;
48}
49
50long gimme_arg(enum tof type, struct process *proc, int arg_num)
51{
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 save_register_args(enum tof type, struct process *proc)
75{
76}
77