aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/Linux/sparc/trace.c
blob: 1452d94d3e1be6b82f64fdc4b42a3b37bec0a9d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <sys/ptrace.h>

#include "ltrace.h"

/* Returns syscall number if `pid' stopped because of a syscall.
 * Returns -1 otherwise
 */
int syscall_p(pid_t pid, int status)
{
#if 0
	if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
		int tmp = ptrace(PTRACE_PEEKUSER, pid, 4*ORIG_EAX);
		if (tmp>=0) {
			return tmp;
		}
	}
#endif
	return -1;
}

void continue_after_breakpoint(struct process *proc, struct breakpoint * sbp, int delete_it)
{
	delete_breakpoint(proc->pid, sbp);
	ptrace(PTRACE_POKEUSER, proc->pid, PT_PC, sbp->addr);
	if (delete_it) {
		continue_process(proc->pid);
	} else {
		proc->breakpoint_being_enabled = sbp;
		ptrace(PTRACE_SINGLESTEP, proc->pid, 0, 0);
	}
}

long gimme_arg(enum tof type, struct process * proc, int arg_num)
{
#if 0
	if (arg_num==-1) {		/* return value */
		return ptrace(PTRACE_PEEKUSER, proc->pid, 4*EAX);
	}

	if (type==LT_TOF_FUNCTION) {
		return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+4*(arg_num+1));
	} else if (type==LT_TOF_SYSCALL) {
#if 0
		switch(arg_num) {
			case 0:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*EBX);
			case 1:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*ECX);
			case 2:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*EDX);
			case 3:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*ESI);
			case 4:	return ptrace(PTRACE_PEEKUSER, proc->pid, 4*EDI);
			default:
				fprintf(stderr, "gimme_arg called with wrong arguments\n");
				exit(2);
		}
#else
		return ptrace(PTRACE_PEEKUSER, proc->pid, 4*arg_num);
#endif
	} else {
		fprintf(stderr, "gimme_arg called with wrong arguments\n");
		exit(1);
	}
#endif
	return 0;
}