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