trace.c revision 9a2ad351a1c3215dc596ff3e2e3fd4bc24445a6b
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
29syscall_p(struct process * proc, int status, int * sysnum) {
30	if (WIFSTOPPED(status) && 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 = ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */, 0);
37		if (proc->callstack_depth > 0 && proc->callstack[proc->callstack_depth-1].is_syscall) {
38			return 2;
39		}
40		if (*sysnum>=0 && *sysnum<500) {
41			return 1;
42		}
43	}
44	return 0;
45}
46
47long
48gimme_arg(enum tof type, struct process * proc, int arg_num) {
49	if (arg_num==-1) {		/* return value */
50		return ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */, 0);
51	}
52
53	if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
54		if(arg_num <= 5)
55			return ptrace(PTRACE_PEEKUSER, proc->pid, arg_num + 16 /* REG_A0 */, 0);
56		else
57			return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+8*(arg_num-6), 0);
58	} else if (type==LT_TOF_SYSCALL || type==LT_TOF_SYSCALLR) {
59		return ptrace(PTRACE_PEEKUSER, proc->pid, arg_num + 16 /* REG_A0 */, 0);
60	} else {
61		fprintf(stderr, "gimme_arg called with wrong arguments\n");
62		exit(1);
63	}
64	return 0;
65}
66
67void save_register_args(enum tof type, struct process * proc)
68{
69}
70