}
/*
- * Generic ptrace wrapper which tracks ESRCH errors
- * by setting tcp->ptrace_errno to ESRCH.
+ * Generic ptrace wrapper which tracks ptrace errors
+ * by setting tcp->ptrace_errno.
*
* We assume that ESRCH indicates likely process death (SIGKILL?),
* modulo bugs where process somehow ended up not stopped.
* Unfortunately kernel uses ESRCH for that case too. Oh well.
- *
- * Currently used by upeek() only.
- * TODO: use this in all other ptrace() calls while decoding.
*/
+static const char *
+str_PTRACE_xxx(int request)
+{
+ const char *s;
+ static char msg[sizeof(int) * 3 + sizeof("PTRACE_<%d>")];
+
+ s = xlookup(ptrace_cmds, request);
+ if (s)
+ return s;
+ sprintf(msg, "PTRACE_<%d>", request);
+ return msg;
+}
+
long
-do_ptrace(int request, struct tcb *tcp, void *addr, void *data)
+do_ptrace(int request, struct tcb *tcp, void *addr, long data)
{
+ int err;
long l;
errno = 0;
l = ptrace(request, tcp->pid, addr, data);
- /* Non-ESRCH errors might be our invalid reg/mem accesses,
- * we do not record them. */
- if (errno == ESRCH)
- tcp->ptrace_errno = ESRCH;
+ err = errno;
+ if (err) {
+ tcp->ptrace_errno = err;
+ if (err != ESRCH) {
+ fprintf(stderr, "strace: ptrace(%s,%u,%p,%lu): %s\n",
+ str_PTRACE_xxx(request),
+ (int) tcp->pid, addr, data, strerror(err));
+ errno = err; /* fprintf can clobber it, restore */
+ }
+ return -1;
+ }
+ return l;
+}
+
+static long
+do_ptrace_peekdata(struct tcb *tcp, void *addr, int started)
+{
+ int err;
+ long l;
+
+ errno = 0;
+ l = ptrace(PTRACE_PEEKDATA, tcp->pid, addr, 0);
+ err = errno;
+ if (err) {
+ if (started && (err == EPERM || err == EIO)) {
+ /* Ran into 'end of memory' - not an error.
+ * NB: errno is nonzero, caller uses this to detect
+ * "end of string" condition.
+ */
+ return 0;
+ }
+ /* If error happens at first call, we have a bogus address. */
+ if (addr != NULL && err != EIO) {
+ if (err != ESRCH) {
+ fprintf(stderr, "strace: ptrace(PTRACE_PEEKDATA,%u,%p,0): %s\n",
+ (int) tcp->pid, addr, strerror(err));
+ errno = err; /* fprintf can clobber it, restore */
+ }
+ tcp->ptrace_errno = err;
+ return -1;
+ }
+ }
return l;
}
+#ifdef SUNOS4
+static long
+do_ptrace5(int request, struct tcb *tcp, void *addr, long data, char *data2)
+{
+ int err;
+ long l;
+
+ errno = 0;
+ l = ptrace(request, tcp->pid, addr, data, data2);
+ err = errno;
+ if (err) {
+ tcp->ptrace_errno = err;
+ if (err != ESRCH) {
+ fprintf(stderr, "strace: ptrace(%s,%u,%p,%lu,%p): %s\n",
+ str_PTRACE_xxx(request),
+ (int) tcp->pid, addr, data, data2, strerror(err));
+ errno = err; /* fprintf can clobber it, restore */
+ }
+ return -1;
+ }
+ return l;
+}
+#endif
+
/*
* Used when we want to unblock stopped traced process.
* Should be only used with PTRACE_CONT, PTRACE_DETACH and PTRACE_SYSCALL.
* Otherwise prints error message and returns -1.
*/
int
-ptrace_restart(int op, struct tcb *tcp, int sig)
+ptrace_restart(int request, struct tcb *tcp, int sig)
{
int err;
- const char *msg;
errno = 0;
- ptrace(op, tcp->pid, (void *) 1, (void *) (long) sig);
+ ptrace(request, tcp->pid, (void *) 1, (long) sig);
err = errno;
if (!err || err == ESRCH)
return 0;
tcp->ptrace_errno = err;
- msg = "SYSCALL";
- if (op == PTRACE_CONT)
- msg = "CONT";
- if (op == PTRACE_DETACH)
- msg = "DETACH";
- fprintf(stderr, "strace: ptrace(PTRACE_%s,1,%d): %s\n",
- msg, sig, strerror(err));
+ fprintf(stderr, "strace: ptrace(%s,%u,1,%d): %s\n",
+ str_PTRACE_xxx(request),
+ (int)tcp->pid, sig, strerror(err));
+ errno = err; /* fprintf can clobber it, restore */
return -1;
}
umoven(struct tcb *tcp, long addr, int len, char *laddr)
{
#ifdef LINUX
- int pid = tcp->pid;
int n, m;
int started = 0;
union {
/* addr not a multiple of sizeof(long) */
n = addr - (addr & -sizeof(long)); /* residue */
addr &= -sizeof(long); /* residue */
- errno = 0;
- u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
- if (errno) {
- if (started && (errno==EPERM || errno==EIO)) {
- /* Ran into 'end of memory' - stupid "printpath" */
- return 0;
- }
- /* But if not started, we had a bogus address. */
- if (addr != 0 && errno != EIO && errno != ESRCH)
- perror("ptrace: umoven");
- return -1;
- }
+ u.val = do_ptrace_peekdata(tcp, (char *) addr, started);
+ if (errno)
+ return u.val; /* 0 or -1 */
started = 1;
memcpy(laddr, &u.x[n], m = MIN(sizeof(long) - n, len));
addr += sizeof(long), laddr += m, len -= m;
}
while (len) {
- errno = 0;
- u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
- if (errno) {
- if (started && (errno==EPERM || errno==EIO)) {
- /* Ran into 'end of memory' - stupid "printpath" */
- return 0;
- }
- if (addr != 0 && errno != EIO && errno != ESRCH)
- perror("ptrace: umoven");
- return -1;
- }
+ u.val = do_ptrace_peekdata(tcp, (char *) addr, started);
+ if (errno)
+ return u.val; /* 0 or -1 */
started = 1;
memcpy(laddr, u.x, m = MIN(sizeof(long), len));
addr += sizeof(long), laddr += m, len -= m;
/* addr not a multiple of sizeof(long) */
n = addr - (addr & -sizeof(long)); /* residue */
addr &= -sizeof(long); /* residue */
- errno = 0;
- u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
- if (errno) {
- if (errno != ESRCH)
- perror("umoven");
+ u.val = do_ptrace(PTRACE_PEEKDATA, tcp, (char *) addr, 0);
+ if (errno)
return -1;
- }
memcpy(laddr, &u.x[n], m = MIN(sizeof(long) - n, len));
addr += sizeof(long), laddr += m, len -= m;
}
while (len) {
- errno = 0;
- u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
- if (errno) {
- if (errno != ESRCH)
- perror("umoven");
+ u.val = do_ptrace(PTRACE_PEEKDATA, tcp, (char *) addr, 0);
+ if (errno)
return -1;
- }
memcpy(laddr, u.x, m = MIN(sizeof(long), len));
addr += sizeof(long), laddr += m, len -= m;
}
while (len) {
n = MIN(len, PAGSIZ);
n = MIN(n, ((addr + PAGSIZ) & PAGMASK) - addr);
- if (ptrace(PTRACE_READDATA, pid,
- (char *) addr, len, laddr) < 0) {
- if (errno != ESRCH) {
- perror("umoven: ptrace(PTRACE_READDATA, ...)");
- abort();
- }
+ if (do_ptrace5(PTRACE_READDATA, tcp, (char *) addr, len, laddr) < 0) {
return -1;
}
len -= n;
}
#else /* !USE_PROCFS */
int started = 0;
- int pid = tcp->pid;
int i, n, m;
union {
long val;
/* addr not a multiple of sizeof(long) */
n = addr - (addr & -sizeof(long)); /* residue */
addr &= -sizeof(long); /* residue */
- errno = 0;
- u.val = ptrace(PTRACE_PEEKDATA, pid, (char *)addr, 0);
- if (errno) {
- if (started && (errno==EPERM || errno==EIO)) {
- /* Ran into 'end of memory' - stupid "printpath" */
- return 0;
- }
- if (addr != 0 && errno != EIO && errno != ESRCH)
- perror("umovestr");
- return -1;
- }
+ u.val = do_ptrace_peekdata(tcp, (char *)addr, started);
+ if (errno)
+ return u.val; /* 0 or -1 */
started = 1;
memcpy(laddr, &u.x[n], m = MIN(sizeof(long)-n,len));
while (n & (sizeof(long) - 1))
addr += sizeof(long), laddr += m, len -= m;
}
while (len) {
- errno = 0;
- u.val = ptrace(PTRACE_PEEKDATA, pid, (char *)addr, 0);
- if (errno) {
- if (started && (errno==EPERM || errno==EIO)) {
- /* Ran into 'end of memory' - stupid "printpath" */
- return 0;
- }
- if (addr != 0 && errno != EIO && errno != ESRCH)
- perror("umovestr");
- return -1;
- }
+ u.val = do_ptrace_peekdata(tcp, (char *)addr, started);
+ if (errno)
+ return u.val; /* 0 or -1 */
started = 1;
memcpy(laddr, u.x, m = MIN(sizeof(long), len));
for (i = 0; i < sizeof(long); i++)
#ifdef SUNOS4
static int
-uload(cmd, pid, addr, len, laddr)
-int cmd;
-int pid;
-long addr;
-int len;
-char *laddr;
+uload(int cmd, struct tcb *tcp, long addr, int len, char *laddr)
{
# if 0
int n;
while (len) {
n = MIN(len, PAGSIZ);
n = MIN(n, ((addr + PAGSIZ) & PAGMASK) - addr);
- if (ptrace(cmd, pid, (char *)addr, n, laddr) < 0) {
- perror("uload: ptrace(PTRACE_WRITE, ...)");
+ if (do_ptrace5(cmd, tcp, (char *)addr, n, laddr) < 0) {
return -1;
}
len -= n;
/* addr not a multiple of sizeof(long) */
n = addr - (addr & -sizeof(long)); /* residue */
addr &= -sizeof(long);
- errno = 0;
- u.val = ptrace(peek, pid, (char *) addr, 0);
- if (errno) {
- perror("uload: POKE");
+ u.val = do_ptrace(peek, tcp, (char *) addr, 0);
+ if (errno)
return -1;
- }
- memcpy(&u.x[n], laddr, m = MIN(sizeof(long) - n, len));
- if (ptrace(poke, pid, (char *)addr, u.val) < 0) {
- perror("uload: POKE");
+ m = MIN(sizeof(long) - n;
+ memcpy(&u.x[n], laddr, m, len));
+ if (do_ptrace(poke, tcp, (char *)addr, u.val) < 0) {
return -1;
}
- addr += sizeof(long), laddr += m, len -= m;
+ addr += sizeof(long);
+ laddr += m;
+ len -= m;
}
+ errno = 0;
while (len) {
if (len < sizeof(long))
- u.val = ptrace(peek, pid, (char *) addr, 0);
- memcpy(u.x, laddr, m = MIN(sizeof(long), len));
- if (ptrace(poke, pid, (char *) addr, u.val) < 0) {
- perror("uload: POKE");
+ u.val = do_ptrace(peek, tcp, (char *) addr, 0);
+ m = MIN(sizeof(long), len);
+ memcpy(u.x, laddr, m);
+ if (errno || do_ptrace(poke, tcp, (char *) addr, u.val) < 0) {
return -1;
}
- addr += sizeof(long), laddr += m, len -= m;
+ addr += sizeof(long);
+ laddr += m;
+ len -= m;
}
# endif
return 0;
}
-int
-tload(pid, addr, len, laddr)
-int pid;
-int addr, len;
-char *laddr;
-{
- return uload(PTRACE_WRITETEXT, pid, addr, len, laddr);
-}
-
-int
-dload(pid, addr, len, laddr)
-int pid;
-int addr;
-int len;
-char *laddr;
+static int
+tload(struct tcb *tcp, int addr, int len, char *laddr)
{
- return uload(PTRACE_WRITEDATA, pid, addr, len, laddr);
+ return uload(PTRACE_WRITETEXT, tcp, addr, len, laddr);
}
#endif /* SUNOS4 */
#ifndef USE_PROCFS
int
-upeek(tcp, off, res)
-struct tcb *tcp;
-long off;
-long *res;
+upeek(struct tcb *tcp, long off, long *res)
{
long val;
off += 1024;
}
# endif /* SUNOS4_KERNEL_ARCH_KLUDGE */
- errno = 0;
val = do_ptrace(PTRACE_PEEKUSER, tcp, (char *) off, 0);
- if (val == -1 && errno) {
- if (errno != ESRCH) {
- char buf[60];
- sprintf(buf,"upeek: ptrace(PTRACE_PEEKUSER,%d,%lu,0)", tcp->pid, off);
- perror(buf);
- }
+ if (errno)
return -1;
- }
*res = val;
return 0;
}
return -1;
# elif defined(SPARC) || defined(SPARC64)
struct regs regs;
- if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)®s,0) < 0)
+ if (do_ptrace(PTRACE_GETREGS, tcp, (char *) ®s, 0) < 0)
return -1;
pc = regs.r_pc;
# elif defined(S390) || defined(S390X)
- if(upeek(tcp,PT_PSWADDR,&pc) < 0)
+ if (upeek(tcp, PT_PSWADDR, &pc) < 0)
return -1;
# elif defined(HPPA)
- if(upeek(tcp,PT_IAOQ0,&pc) < 0)
+ if (upeek(tcp, PT_IAOQ0, &pc) < 0)
return -1;
# elif defined(SH)
- if (upeek(tcp, 4*REG_PC ,&pc) < 0)
+ if (upeek(tcp, 4*REG_PC, &pc) < 0)
return -1;
# elif defined(SH64)
if (upeek(tcp, REG_PC ,&pc) < 0)
*/
struct regs regs;
- if (ptrace(PTRACE_GETREGS, tcp->pid, (char *) ®s, 0) < 0) {
- perror("getpc: ptrace(PTRACE_GETREGS, ...)");
+ if (do_ptrace(PTRACE_GETREGS, tcp, (char *) ®s, 0) < 0)
return -1;
- }
return regs.r_pc;
#endif /* SUNOS4 */
# elif defined(S390) || defined(S390X)
long psw;
- if(upeek(tcp,PT_PSWADDR,&psw) < 0) {
+ if (upeek(tcp, PT_PSWADDR, &psw) < 0) {
PRINTBADPC;
return;
}
tprintf("[%08lx] ", pc);
# elif defined(SPARC) || defined(SPARC64)
struct regs regs;
- if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)®s,0) < 0) {
+ if (do_ptrace(PTRACE_GETREGS, tcp, (char *) ®s, 0) < 0) {
PRINTBADPC;
return;
}
# elif defined(HPPA)
long pc;
- if(upeek(tcp,PT_IAOQ0,&pc) < 0) {
+ if (upeek(tcp, PT_IAOQ0, &pc) < 0) {
tprintf ("[????????] ");
return;
}
#ifdef SUNOS4
struct regs regs;
- if (ptrace(PTRACE_GETREGS, tcp->pid, (char *) ®s, 0) < 0) {
- perror("printcall: ptrace(PTRACE_GETREGS, ...)");
+ if (do_ptrace(PTRACE_GETREGS, tcp, (char *) ®s, 0) < 0) {
PRINTBADPC;
return;
}
req = PTRACE_POKEUSER;
} else
ap = ia64_rse_skip_regs(*state, 0);
- errno = 0;
- ptrace(req, tcp->pid, ap, val);
- return errno ? -1 : 0;
+ if (do_ptrace(req, tcp, ap, val) < 0)
+ return -1;
+ return 0;
}
static int
req = PTRACE_POKEUSER;
} else
ap = ia64_rse_skip_regs(*state, 1);
- errno = 0;
- ptrace(req, tcp->pid, ap, val);
- return errno ? -1 : 0;
+ if (do_ptrace(req, tcp, ap, val) < 0)
+ return -1;
+ return 0;
}
/* ia64 does not return the input arguments from functions (and syscalls)
typedef struct regs arg_setup_state;
# define arg_setup(tcp, state) \
- (ptrace (PTRACE_GETREGS, tcp->pid, (char *) (state), 0))
+ (do_ptrace(PTRACE_GETREGS, tcp, (char *) (state), 0))
# define arg_finish_change(tcp, state) \
- (ptrace (PTRACE_SETREGS, tcp->pid, (char *) (state), 0))
+ (do_ptrace(PTRACE_SETREGS, tcp, (char *) (state), 0))
# define get_arg0(tcp, state, valp) (*(valp) = (state)->r_o0, 0)
# define get_arg1(tcp, state, valp) (*(valp) = (state)->r_o1, 0)
(upeek ((tcp), arg1_offset, (valp)))
static int
-set_arg0 (struct tcb *tcp, void *cookie, long val)
+set_arg0(struct tcb *tcp, void *cookie, long val)
{
- return ptrace (PTRACE_POKEUSER, tcp->pid, (char*)arg0_offset, val);
+ return do_ptrace(PTRACE_POKEUSER, tcp, (char*)arg0_offset, val);
}
static int
-set_arg1 (struct tcb *tcp, void *cookie, long val)
+set_arg1(struct tcb *tcp, void *cookie, long val)
{
- return ptrace (PTRACE_POKEUSER, tcp->pid, (char*)arg1_offset, val);
+ return do_ptrace(PTRACE_POKEUSER, tcp, (char*)arg1_offset, val);
}
# endif /* architectures */
fprintf(stderr, "PANIC: TCB already set in pid %u\n", tcp->pid);
return -1;
}
- if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
- perror("setbpt: ptrace(PTRACE_GETREGS, ...)");
+ if (do_ptrace(PTRACE_GETREGS, tcp, (char *)®s, 0) < 0) {
return -1;
}
tcp->baddr = regs.r_o7 + 8;
- errno = 0;
- tcp->inst[0] = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *)tcp->baddr, 0);
- if(errno) {
- perror("setbpt: ptrace(PTRACE_PEEKTEXT, ...)");
+ tcp->inst[0] = do_ptrace(PTRACE_PEEKTEXT, tcp, (char *)tcp->baddr, 0);
+ if (errno)
return -1;
- }
/*
* XXX - BRUTAL MODE ON
inst <<= 32;
inst |= (tcp->inst[0] & 0xffffffffUL);
# endif
- ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, inst);
- if(errno) {
- perror("setbpt: ptrace(PTRACE_POKETEXT, ...)");
+ if (do_ptrace(PTRACE_POKETEXT, tcp, (char *) tcp->baddr, inst) < 0)
return -1;
- }
tcp->flags |= TCB_BPTSET;
# else /* !SPARC && !SPARC64 */
if (debug)
fprintf(stderr, "[%d] setting bpt at %lx\n",
tcp->pid, tcp->baddr);
- tcp->inst[0] = ptrace(PTRACE_PEEKTEXT, tcp->pid,
- (char *) tcp->baddr, 0);
- if (errno) {
- perror("setbpt: ptrace(PTRACE_PEEKTEXT, ...)");
+ tcp->inst[0] = do_ptrace(PTRACE_PEEKTEXT, tcp, (char *) tcp->baddr, 0);
+ if (errno)
return -1;
- }
- ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, LOOP);
- if (errno) {
- perror("setbpt: ptrace(PTRACE_POKETEXT, ...)");
+ if (do_ptrace(PTRACE_POKETEXT, tcp, (char *) tcp->baddr, LOOP) < 0)
return -1;
- }
tcp->flags |= TCB_BPTSET;
} else {
/*
/* store "ri" in low two bits */
tcp->baddr = addr | ((ipsr >> 41) & 0x3);
- errno = 0;
- tcp->inst[0] = ptrace(PTRACE_PEEKTEXT, pid, (char *) addr + 0,
- 0);
- tcp->inst[1] = ptrace(PTRACE_PEEKTEXT, pid, (char *) addr + 8,
- 0);
- if (errno) {
- perror("setbpt: ptrace(PTRACE_PEEKTEXT, ...)");
+ tcp->inst[0] = do_ptrace(PTRACE_PEEKTEXT, tcp, (char *) addr + 0, 0);
+ if (!errno)
+ tcp->inst[1] = do_ptrace(PTRACE_PEEKTEXT, tcp, (char *) addr + 8, 0);
+ if (errno)
return -1;
- }
- errno = 0;
- ptrace(PTRACE_POKETEXT, pid, (char *) addr + 0, LOOP0);
- ptrace(PTRACE_POKETEXT, pid, (char *) addr + 8, LOOP1);
- if (errno) {
- perror("setbpt: ptrace(PTRACE_POKETEXT, ...)");
+ if (do_ptrace(PTRACE_POKETEXT, tcp, (char *) addr + 0, LOOP0) < 0
+ || do_ptrace(PTRACE_POKETEXT, tcp, (char *) addr + 8, LOOP1) < 0
+ ) {
return -1;
}
tcp->flags |= TCB_BPTSET;
# endif
if (debug)
fprintf(stderr, "[%d] setting bpt at %lx\n", tcp->pid, tcp->baddr);
- tcp->inst[0] = ptrace(PTRACE_PEEKTEXT, tcp->pid, (char *) tcp->baddr, 0);
- if (errno) {
- perror("setbpt: ptrace(PTRACE_PEEKTEXT, ...)");
+ tcp->inst[0] = do_ptrace(PTRACE_PEEKTEXT, tcp, (char *) tcp->baddr, 0);
+ if (errno)
return -1;
- }
- ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, LOOP);
- if (errno) {
- perror("setbpt: ptrace(PTRACE_POKETEXT, ...)");
+ if (do_ptrace(PTRACE_POKETEXT, tcp, (char *) tcp->baddr, LOOP) < 0) {
return -1;
}
tcp->flags |= TCB_BPTSET;
fprintf(stderr, "PANIC: TCB already set in pid %u\n", tcp->pid);
return -1;
}
- if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
- perror("setbpt: ptrace(PTRACE_GETREGS, ...)");
+ if (do_ptrace(PTRACE_GETREGS, tcp, (char *)®s, 0) < 0) {
return -1;
}
tcp->baddr = regs.r_o7 + 8;
- if (ptrace(PTRACE_READTEXT, tcp->pid, (char *)tcp->baddr,
- sizeof tcp->inst, (char *)tcp->inst) < 0) {
- perror("setbpt: ptrace(PTRACE_READTEXT, ...)");
+ if (do_ptrace5(PTRACE_READTEXT, tcp, (char *)tcp->baddr,
+ sizeof tcp->inst, (char *)tcp->inst, "READTEXT") < 0) {
return -1;
}
* generated by out PTRACE_ATTACH.
* Of cause, if we evaporate ourselves in the middle of all this...
*/
- if (ptrace(PTRACE_WRITETEXT, tcp->pid, (char *) tcp->baddr,
+ if (do_ptrace5(PTRACE_WRITETEXT, tcp, (char *) tcp->baddr,
sizeof loopdeloop, (char *) loopdeloop) < 0) {
- perror("setbpt: ptrace(PTRACE_WRITETEXT, ...)");
return -1;
}
tcp->flags |= TCB_BPTSET;
fprintf(stderr, "PANIC: TCB not set in pid %u\n", tcp->pid);
return -1;
}
- errno = 0;
- ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, tcp->inst[0]);
- if(errno) {
- perror("clearbtp: ptrace(PTRACE_POKETEXT, ...)");
+ if (do_ptrace(PTRACE_POKETEXT, tcp, (char *) tcp->baddr, tcp->inst[0]) < 0) {
return -1;
}
tcp->flags &= ~TCB_BPTSET;
fprintf(stderr, "PANIC: TCB not set in pid %u\n", tcp->pid);
return -1;
}
- errno = 0;
- ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, tcp->inst[0]);
- if (errno) {
- perror("clearbtp: ptrace(PTRACE_POKETEXT, ...)");
+ if (do_ptrace(PTRACE_POKETEXT, tcp, (char *) tcp->baddr, tcp->inst[0]) < 0) {
return -1;
}
tcp->flags &= ~TCB_BPTSET;
return -1;
/* restore original bundle: */
- errno = 0;
- ptrace(PTRACE_POKETEXT, pid, (char *) addr + 0, tcp->inst[0]);
- ptrace(PTRACE_POKETEXT, pid, (char *) addr + 8, tcp->inst[1]);
- if (errno) {
- perror("clearbpt: ptrace(PTRACE_POKETEXT, ...)");
+ if (do_ptrace(PTRACE_POKETEXT, tcp, (char *) addr + 0, tcp->inst[0]) < 0
+ || do_ptrace(PTRACE_POKETEXT, tcp, (char *) addr + 8, tcp->inst[1]) < 0
+ ) {
return -1;
}
/* restore original "ri" in ipsr: */
ipsr = (ipsr & ~(0x3ul << 41)) | ((tcp->baddr & 0x3) << 41);
- errno = 0;
- ptrace(PTRACE_POKEUSER, pid, (char *) PT_CR_IPSR, ipsr);
- if (errno) {
- perror("clrbpt: ptrace(PTRACE_POKEUSER, ...)");
+ if (do_ptrace(PTRACE_POKEUSER, tcp, (char *) PT_CR_IPSR, ipsr) < 0) {
return -1;
}
fprintf(stderr, "PANIC: TCB not set in pid %u\n", tcp->pid);
return -1;
}
- errno = 0;
- ptrace(PTRACE_POKETEXT, tcp->pid, (char *) tcp->baddr, tcp->inst[0]);
- if (errno) {
- perror("clearbtp: ptrace(PTRACE_POKETEXT, ...)");
+ if (do_ptrace(PTRACE_POKETEXT, tcp, (char *) tcp->baddr, tcp->inst[0]) < 0) {
return -1;
}
tcp->flags &= ~TCB_BPTSET;
* safe to set both IAOQ0 and IAOQ1 to that so the PSW N bit
* has no significant effect.
*/
- ptrace(PTRACE_POKEUSER, tcp->pid, (void *)PT_IAOQ0, iaoq);
- ptrace(PTRACE_POKEUSER, tcp->pid, (void *)PT_IAOQ1, iaoq);
+ if (do_ptrace(PTRACE_POKEUSER, tcp, (void *)PT_IAOQ0, iaoq) < 0
+ || do_ptrace(PTRACE_POKEUSER, tcp, (void *)PT_IAOQ1, iaoq) < 0
+ ) {
+ return -1;
+ }
# elif defined(SH)
if (upeek(tcp, 4*REG_PC, &pc) < 0)
return -1;
fprintf(stderr, "PANIC: TCB not set in pid %u\n", tcp->pid);
return -1;
}
- if (ptrace(PTRACE_WRITETEXT, tcp->pid, (char *) tcp->baddr,
+ if (do_ptrace5(PTRACE_WRITETEXT, tcp, (char *) tcp->baddr,
sizeof tcp->inst, (char *) tcp->inst) < 0) {
- perror("clearbtp: ptrace(PTRACE_WRITETEXT, ...)");
return -1;
}
tcp->flags &= ~TCB_BPTSET;
* Since we don't have a single instruction breakpoint, we may have
* to adjust the program counter after removing our `breakpoint'.
*/
- if (ptrace(PTRACE_GETREGS, tcp->pid, (char *)®s, 0) < 0) {
- perror("clearbpt: ptrace(PTRACE_GETREGS, ...)");
+ if (do_ptrace(PTRACE_GETREGS, tcp, (char *)®s, 0) < 0) {
return -1;
}
- if ((regs.r_pc < tcp->baddr) ||
- (regs.r_pc > tcp->baddr + 4)) {
+ if ((regs.r_pc < tcp->baddr) || (regs.r_pc > tcp->baddr + 4)) {
/* The breakpoint has not been reached yet */
if (debug)
fprintf(stderr,
regs.r_pc, tcp->baddr);
regs.r_pc = tcp->baddr;
- if (ptrace(PTRACE_SETREGS, tcp->pid, (char *)®s, 0) < 0) {
- perror("clearbpt: ptrace(PTRACE_SETREGS, ...)");
+ if (do_ptrace(PTRACE_SETREGS, tcp, (char *)®s, 0) < 0) {
return -1;
}
# endif /* LOOPA */
fprintf(stderr, "out of memory\n");
return -1;
}
- if (umoven(tcp, (int)ld.ld_symbols+(int)N_TXTADDR(hdr),
+ if (umoven(tcp, (int)ld.ld_symbols + (int)N_TXTADDR(hdr),
(int)ld.ld_symb_size, strtab) < 0)
goto err;
* Write entire symbol table back to avoid
* memory alignment bugs in ptrace
*/
- if (tload(pid, (int)ld.ld_symbols+(int)N_TXTADDR(hdr),
+ if (tload(tcp, (int)ld.ld_symbols + (int)N_TXTADDR(hdr),
(int)ld.ld_symb_size, strtab) < 0)
goto err;