blob: 88a9527c897c131952bb3e96f5ba75915b3c321e [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
Juan Cespedesf1350522008-12-16 18:19:58 +010022void
Juan Cespedesa8909f72009-04-28 20:02:41 +020023get_arch_dep(Process *proc) {
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 */
Juan Cespedesf1350522008-12-16 18:19:58 +010028int
Juan Cespedesa8909f72009-04-28 20:02:41 +020029syscall_p(Process *proc, int status, int *sysnum) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +010030 if (WIFSTOPPED(status)
31 && WSTOPSIG(status) == (SIGTRAP | proc->tracesysgood)) {
32 *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ORIG_EAX, 0);
Juan Cespedes21c63a12001-07-07 20:56:56 +020033
34 if (proc->callstack_depth > 0 &&
Ian Wienand2d45b1a2006-02-20 22:48:07 +010035 proc->callstack[proc->callstack_depth - 1].is_syscall) {
Juan Cespedes21c63a12001-07-07 20:56:56 +020036 return 2;
37 }
38
Ian Wienand2d45b1a2006-02-20 22:48:07 +010039 if (*sysnum >= 0) {
Juan Cespedes21c63a12001-07-07 20:56:56 +020040 return 1;
Juan Cespedesf0fdae91998-03-11 00:03:00 +010041 }
42 }
Juan Cespedes35d70631998-03-15 14:05:40 +010043 return 0;
Juan Cespedes5e01f651998-03-08 22:31:44 +010044}
45
Juan Cespedesf1350522008-12-16 18:19:58 +010046long
Juan Cespedesa8909f72009-04-28 20:02:41 +020047gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +010048 if (arg_num == -1) { /* return value */
49 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EAX, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +010050 }
51
Ian Wienand2d45b1a2006-02-20 22:48:07 +010052 if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
53 return ptrace(PTRACE_PEEKTEXT, proc->pid,
54 proc->stack_pointer + 4 * (arg_num + 1), 0);
55 } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) {
Juan Cespedes5e01f651998-03-08 22:31:44 +010056#if 0
Ian Wienand2d45b1a2006-02-20 22:48:07 +010057 switch (arg_num) {
58 case 0:
59 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EBX, 0);
60 case 1:
61 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ECX, 0);
62 case 2:
63 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDX, 0);
64 case 3:
65 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ESI, 0);
66 case 4:
67 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDI, 0);
68 default:
69 fprintf(stderr,
70 "gimme_arg called with wrong arguments\n");
71 exit(2);
Juan Cespedes5e01f651998-03-08 22:31:44 +010072 }
73#else
Ian Wienand2d45b1a2006-02-20 22:48:07 +010074 return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, 0);
Juan Cespedes5e01f651998-03-08 22:31:44 +010075#endif
76 } else {
77 fprintf(stderr, "gimme_arg called with wrong arguments\n");
78 exit(1);
79 }
80
81 return 0;
82}
Juan Cespedes5c3fe062004-06-14 18:08:37 +020083
Juan Cespedesf1350522008-12-16 18:19:58 +010084void
Juan Cespedesa8909f72009-04-28 20:02:41 +020085save_register_args(enum tof type, Process *proc) {
Juan Cespedes5c3fe062004-06-14 18:08:37 +020086}