trace.c revision 5c3fe0697b202cc7d95e90459de0fb312b297b27
1/*
2** S390 specific part of trace.c
3**
4** Other routines are in ../trace.c and need to be combined
5** at link time with this code.
6**
7** S/390 version
8** Copyright (C) 2001 IBM Poughkeepsie, IBM Corporation
9*/
10
11#if HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#include <sys/types.h>
16#include <sys/wait.h>
17#include <signal.h>
18#include <sys/ptrace.h>
19#include <asm/ptrace.h>
20
21#include "ltrace.h"
22
23#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR))
24# define PTRACE_PEEKUSER PTRACE_PEEKUSR
25#endif
26
27#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR))
28# define PTRACE_POKEUSER PTRACE_POKEUSR
29#endif
30
31void
32get_arch_dep(struct process * proc) {
33}
34
35/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
36 */
37int
38syscall_p(struct process * proc, int status, int * sysnum) {
39	long pswa;
40	long svcinst;
41	long svcno;
42	long svcop;
43
44	if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
45
46		pswa = ptrace(PTRACE_PEEKUSER, proc->pid, PT_PSWADDR, 0);
47		svcinst = ptrace(PTRACE_PEEKTEXT, proc->pid, (char *)(pswa-4),0);
48		svcop = (svcinst >> 8) & 0xFF;
49		svcno = svcinst & 0xFF;
50
51		*sysnum = svcno;
52
53		if (*sysnum == -1) {
54			return 0;
55		}
56		if (svcop == 0 && svcno == 1) {
57			/* Breakpoint was hit... */
58			return 0;
59		}
60		if (svcop == 10 && *sysnum>=0) {
61			/* System call was encountered... */
62			if (proc->callstack_depth > 0 &&
63					proc->callstack[proc->callstack_depth-1].is_syscall) {
64				return 2;
65			} else {
66				return 1;
67			}
68		}
69		else {
70			/* Unknown trap was encountered... */
71			return 0;
72		}
73	}
74	/* Unknown status... */
75	return 0;
76}
77
78long
79gimme_arg(enum tof type, struct process * proc, int arg_num) {
80	switch(arg_num) {
81		case -1: /* return value */
82			return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR2, 0);
83		case 0: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_ORIGGPR2, 0);
84		case 1: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR3, 0);
85		case 2: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR4, 0);
86		case 3: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR5, 0);
87		case 4: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR6, 0);
88		default:
89				fprintf(stderr, "gimme_arg called with wrong arguments\n");
90				exit(2);
91	}
92}
93
94void
95save_register_args(enum tof type, struct process * proc) {
96}
97