blob: 88caca7d3729b9d6f6d474dbc8918fa5e610bf18 [file] [log] [blame]
Juan Cespedesd44c6b81998-09-25 14:48:42 +02001#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
Juan Cespedes5c3fe062004-06-14 18:08:37 +020021void
22get_arch_dep(struct process * proc) {
23}
24
Juan Cespedesd44c6b81998-09-25 14:48:42 +020025/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
26 */
Juan Cespedesb1dd77d2002-03-03 00:22:06 +010027int
28syscall_p(struct process * proc, int status, int * sysnum) {
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +020029 int depth;
30
Juan Cespedesd44c6b81998-09-25 14:48:42 +020031 if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
32 *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_ORIG_D0, 0);
33 if (*sysnum == -1) return 0;
34 if (*sysnum>=0) {
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +020035 depth = proc->callstack_depth;
36 if (depth>0 &&
37 proc->callstack[depth-1].is_syscall &&
38 proc->callstack[depth-1].c_un.syscall==*sysnum) {
Juan Cespedesd44c6b81998-09-25 14:48:42 +020039 return 2;
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +020040 } else {
41 return 1;
Juan Cespedesd44c6b81998-09-25 14:48:42 +020042 }
43 }
44 }
45 return 0;
46}
47
Juan Cespedesb1dd77d2002-03-03 00:22:06 +010048long
49gimme_arg(enum tof type, struct process * proc, int arg_num) {
Juan Cespedesd44c6b81998-09-25 14:48:42 +020050 if (arg_num==-1) { /* return value */
51 return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D0, 0);
52 }
53
Juan Cespedes5c3fe062004-06-14 18:08:37 +020054 if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
Juan Cespedesd44c6b81998-09-25 14:48:42 +020055 return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+4*(arg_num+1), 0);
Juan Cespedes5c3fe062004-06-14 18:08:37 +020056 } else if (type==LT_TOF_SYSCALL || type==LT_TOF_SYSCALLR) {
Juan Cespedesd44c6b81998-09-25 14:48:42 +020057#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}
Juan Cespedes5c3fe062004-06-14 18:08:37 +020079
80void
81save_register_args(enum tof type, struct process * proc) {
82}