trace.c revision 3219f320604810532a4938dda8f9dfadb0e840f3
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 get_arch_dep(struct process *proc)
32{
33}
34
35/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
36 */
37int syscall_p(struct process *proc, int status, int *sysnum)
38{
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 =
48		    ptrace(PTRACE_PEEKTEXT, proc->pid, (char *)(pswa - 4), 0);
49		svcop = (svcinst >> 8) & 0xFF;
50		svcno = svcinst & 0xFF;
51
52		*sysnum = svcno;
53
54		if (*sysnum == -1) {
55			return 0;
56		}
57		if (svcop == 0 && svcno == 1) {
58			/* Breakpoint was hit... */
59			return 0;
60		}
61		if (svcop == 10 && *sysnum >= 0) {
62			/* System call was encountered... */
63			if (proc->callstack_depth > 0 &&
64			    proc->callstack[proc->callstack_depth -
65					    1].is_syscall) {
66				return 2;
67			} else {
68				return 1;
69			}
70		} else {
71			/* Unknown trap was encountered... */
72			return 0;
73		}
74	}
75	/* Unknown status... */
76	return 0;
77}
78
79long gimme_arg(enum tof type, struct process *proc, int arg_num)
80{
81	switch (arg_num) {
82	case -1:		/* return value */
83		return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR2, 0);
84	case 0:
85		return ptrace(PTRACE_PEEKUSER, proc->pid, PT_ORIGGPR2, 0);
86	case 1:
87		return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR3, 0);
88	case 2:
89		return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR4, 0);
90	case 3:
91		return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR5, 0);
92	case 4:
93		return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR6, 0);
94	default:
95		fprintf(stderr, "gimme_arg called with wrong arguments\n");
96		exit(2);
97	}
98}
99
100void save_register_args(enum tof type, struct process *proc)
101{
102}
103