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
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(struct process * proc) {
23}
24
25/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
26 */
27int
28syscall_p(struct process * proc, int status, int * sysnum) {
29	int depth;
30
31	if (WIFSTOPPED(status) && WSTOPSIG(status)==(SIGTRAP | proc->tracesysgood)) {
32		*sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_ORIG_D0, 0);
33		if (*sysnum == -1) return 0;
34		if (*sysnum>=0) {
35			depth = proc->callstack_depth;
36			if (depth>0 &&
37					proc->callstack[depth-1].is_syscall &&
38					proc->callstack[depth-1].c_un.syscall==*sysnum) {
39				return 2;
40			} else {
41				return 1;
42			}
43		}
44	}
45	return 0;
46}
47
48long
49gimme_arg(enum tof type, struct process * proc, int arg_num) {
50	if (arg_num==-1) {		/* return value */
51		return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D0, 0);
52	}
53
54	if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
55		return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+4*(arg_num+1), 0);
56	} else if (type==LT_TOF_SYSCALL || type==LT_TOF_SYSCALLR) {
57#if 0
58		switch(arg_num) {
59			case 0:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D1, 0);
60			case 1:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D2, 0);
61			case 2:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D3, 0);
62			case 3:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D4, 0);
63			case 4:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D5, 0);
64			default:
65				fprintf(stderr, "gimme_arg called with wrong arguments\n");
66				exit(2);
67		}
68#else
69		/* That hack works on m68k, too */
70		return ptrace(PTRACE_PEEKUSER, proc->pid, 4*arg_num, 0);
71#endif
72	} else {
73		fprintf(stderr, "gimme_arg called with wrong arguments\n");
74		exit(1);
75	}
76
77	return 0;
78}
79
80void
81save_register_args(enum tof type, struct process * proc) {
82}
83