blob: fe9d8a452e9f84dcdfe69e1450579aa990bda93f [file] [log] [blame]
Juan Cespedesd44c6b81998-09-25 14:48:42 +02001#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
Juan Cespedes504a3852003-02-04 23:24:38 +01005#include <stdlib.h>
Juan Cespedes5e01f651998-03-08 22:31:44 +01006#include <sys/types.h>
7#include <sys/wait.h>
8#include <signal.h>
9#include <sys/ptrace.h>
Juan Cespedes64c6dfb1998-07-14 13:49:47 +020010#include <asm/ptrace.h>
Juan Cespedes5e01f651998-03-08 22:31:44 +010011
12#include "ltrace.h"
13
Juan Cespedes5e0acdb1998-04-04 08:34:07 +020014#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR))
15# define PTRACE_PEEKUSER PTRACE_PEEKUSR
16#endif
17
18#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR))
19# define PTRACE_POKEUSER PTRACE_POKEUSR
20#endif
21
Ian Wienand3219f322006-02-16 06:00:00 +010022void get_arch_dep(struct process *proc)
23{
Juan Cespedes5c3fe062004-06-14 18:08:37 +020024}
25
Juan Cespedes35d70631998-03-15 14:05:40 +010026/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
Juan Cespedes5e01f651998-03-08 22:31:44 +010027 */
Ian Wienand3219f322006-02-16 06:00:00 +010028int syscall_p(struct process *proc, int status, int *sysnum)
29{
30 if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
31 *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ORIG_EAX, 0);
Juan Cespedes21c63a12001-07-07 20:56:56 +020032
33 if (proc->callstack_depth > 0 &&
Ian Wienand3219f322006-02-16 06:00:00 +010034 proc->callstack[proc->callstack_depth - 1].is_syscall) {
Juan Cespedes21c63a12001-07-07 20:56:56 +020035 return 2;
36 }
37
Ian Wienand3219f322006-02-16 06:00:00 +010038 if (*sysnum >= 0) {
Juan Cespedes21c63a12001-07-07 20:56:56 +020039 return 1;
Juan Cespedesf0fdae91998-03-11 00:03:00 +010040 }
41 }
Juan Cespedes35d70631998-03-15 14:05:40 +010042 return 0;
Juan Cespedes5e01f651998-03-08 22:31:44 +010043}
44
Ian Wienand3219f322006-02-16 06:00:00 +010045long gimme_arg(enum tof type, struct process *proc, int arg_num)
46{
47 if (arg_num == -1) { /* return value */
48 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EAX, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +010049 }
50
Ian Wienand3219f322006-02-16 06:00:00 +010051 if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
52 return ptrace(PTRACE_PEEKTEXT, proc->pid,
53 proc->stack_pointer + 4 * (arg_num + 1), 0);
54 } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) {
Juan Cespedes5e01f651998-03-08 22:31:44 +010055#if 0
Ian Wienand3219f322006-02-16 06:00:00 +010056 switch (arg_num) {
57 case 0:
58 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EBX, 0);
59 case 1:
60 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ECX, 0);
61 case 2:
62 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDX, 0);
63 case 3:
64 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ESI, 0);
65 case 4:
66 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDI, 0);
67 default:
68 fprintf(stderr,
69 "gimme_arg called with wrong arguments\n");
70 exit(2);
Juan Cespedes5e01f651998-03-08 22:31:44 +010071 }
72#else
Ian Wienand3219f322006-02-16 06:00:00 +010073 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +010074#endif
75 } else {
76 fprintf(stderr, "gimme_arg called with wrong arguments\n");
77 exit(1);
78 }
79
80 return 0;
81}
Juan Cespedes5c3fe062004-06-14 18:08:37 +020082
Ian Wienand3219f322006-02-16 06:00:00 +010083void save_register_args(enum tof type, struct process *proc)
84{
Juan Cespedes5c3fe062004-06-14 18:08:37 +020085}