+2008-06-20 Andrew Cagney <cagney@redhat.com>
+
+ * jni/AddressSpace.cxx: Simplify debug code.
+ * cni/AddressSpace.cxx: Ditto.
+ * jni/Ptrace.hxx (ptraceOpToString(int)): Declare.
+ * cni/Ptrace.hxx (ptraceOpToString(int)): Ditto.
+ * jni/Ptrace.cxx (ptraceOpToString): Rename op_as_string.
+ * cni/Ptrace.cxx (ptraceOpToString): Ditto.
+
2008-05-25 Andrew Cagney <cagney@redhat.com>
* jni/AddressSpace.cxx: Use jbyteArrayElements.
// version and license this file solely under the GPL without
// exception.
+#define DEBUG 0
+
+#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/ptrace.h>
frysk::sys::ptrace::AddressSpace::peek(jint pid, jlong addr) {
union word w;
long paddr = addr & -sizeof(long);
-#if DEBUG
- fprintf(stderr, "peek 0x%lx paddr 0x%lx", (long)addr, paddr);
-#endif
+ if (DEBUG)
+ fprintf(stderr, "peek 0x%lx paddr 0x%lx", (long)addr, paddr);
w.l = ptraceOp(ptPeek, pid, (void*)paddr, 0);
-#if DEBUG
- fprintf(stderr, " word 0x%lx", w.l);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " word 0x%lx", w.l);
int index = addr & (sizeof(long) - 1);
-#if DEBUG
- fprintf(stderr, " index %d", index);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " index %d", index);
uint8_t byte = w.b[index];
-#if DEBUG
- fprintf(stderr, " byte %d/0x%x\n", byte, byte);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " byte %d/0x%x\n", byte, byte);
return byte;
}
frysk::sys::ptrace::AddressSpace::poke(jint pid, jlong addr, jint data) {
// Implement read-modify-write
union word w;
-#if DEBUG
- fprintf(stderr, "poke 0x%x", (int)(data & 0xff));
-#endif
+ if (DEBUG)
+ fprintf(stderr, "poke 0x%x", (int)(data & 0xff));
long paddr = addr & -sizeof(long);
-#if DEBUG
- fprintf(stderr, " addr 0x%lx paddr 0x%lx", (long)addr, paddr);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " addr 0x%lx paddr 0x%lx", (long)addr, paddr);
w.l = ptraceOp(ptPeek, pid, (void*)paddr, 0);
-#if DEBUG
- fprintf(stderr, " word 0x%lx", w.l);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " word 0x%lx", w.l);
int index = addr & (sizeof(long) - 1);
-#if DEBUG
- fprintf (stderr, " index %d", index);
-#endif
+ if (DEBUG)
+ fprintf (stderr, " index %d", index);
w.b[index] = data;
-#if DEBUG
- fprintf(stderr, " word 0x%lx\n", w.l);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " word 0x%lx\n", w.l);
ptraceOp(ptPoke, pid, (void*)(addr & -sizeof(long)), w.l);
}
verifyBounds(bytes, offset, length);
// Somewhat more clueful implementation
for (jlong i = 0; i < length;) {
-#if DEBUG
- fprintf(stderr,
- "transfer pid %d addr 0x%lx length %d offset %d op %d (%s)",
- (int)pid, (long)addr, (int)length, (int)offset,
- (int)op, op_as_string(op));
-#endif
-
+ if (DEBUG)
+ fprintf(stderr,
+ "transfer pid %d addr 0x%lx length %d offset %d op %d (%s) ...",
+ (int)pid, (long)addr, (int)length, (int)offset,
+ (int)op, ptraceOpToString(op));
union word w;
unsigned long waddr = addr & -sizeof(long);
unsigned long woff = (addr - waddr);
wend = woff + remaining;
long wlen = wend - woff;
-#if DEBUG
- fprintf(stderr,
- " i %ld waddr 0x%lx woff %lu wend %lu remaining %lu wlen %lu",
- (long)i, waddr, woff, wend, remaining, wlen);
-#endif
+ if (DEBUG)
+ fprintf(stderr,
+ " i %ld waddr 0x%lx woff %lu wend %lu remaining %lu wlen %lu ...",
+ (long)i, waddr, woff, wend, remaining, wlen);
// Either a peek; or a partial write requiring read/modify/write.
if (op == ptPeek || woff != 0 || wend != sizeof(long)) {
- w.l = ptraceOp(ptPeek, pid, (void*)waddr, 0);
-#if DEBUG
- fprintf(stderr, " peek 0x%lx", w.l);
-#endif
- }
+ w.l = ptraceOp(ptPeek, pid, (void*)waddr, 0);
+ if (DEBUG)
+ fprintf(stderr, " peek 0x%lx ...", w.l);
+ }
// extract or modify
if (op == ptPeek)
memcpy(offset + i + elements(bytes), &w.b[woff], wlen);
else {
memcpy(&w.b[woff], offset + i + elements(bytes), wlen);
-#if DEBUG
- fprintf(stderr, " poke 0x%lx", w.l);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " poke 0x%lx ...", w.l);
w.l = ptraceOp(ptPoke, pid, (void*)waddr, w.l);
}
i += wlen;
addr += wlen;
-#if DEBUG
- fprintf(stderr, "\n");
-#endif
+ if (DEBUG)
+ fprintf(stderr, "\n");
}
}
// version and license this file solely under the GPL without
// exception.
+#define DEBUG 0
+
+#include <stdio.h>
+#include <string.h>
#include <errno.h>
#include <sys/ptrace.h>
#include "linux.ptrace.h"
#include "frysk/sys/ptrace/Ptrace.h"
#include "frysk/sys/ptrace/cni/Ptrace.hxx"
-static const char*
-op_as_string(int op) {
+const char*
+ptraceOpToString(int op) {
switch(op) {
#define OP(NAME) case NAME: return #NAME
OP(PTRACE_ATTACH);
long
ptraceOp(int op, int pid, void* addr, long data) {
errno = 0;
- long result = ::ptrace ((enum __ptrace_request) op, pid, addr, data);
- if (errno != 0)
+ long result = ::ptrace((enum __ptrace_request) op, pid, addr, data);
+ if (errno != 0) {
+ int err = errno;
+ if (DEBUG)
+ fprintf(stderr, "throwing %s\n", strerror(err));
throwErrno(errno, "ptrace", "op 0x%x (%s), pid %d, addr 0x%lx, data 0x%lx",
- op, op_as_string(op), pid, (long)addr, data);
+ op, ptraceOpToString(op), pid, (long)addr, data);
+ }
return result;
}
// exception.
extern long ptraceOp(int, int, void*, long);
+extern const char *ptraceOpToString(int op);
// version and license this file solely under the GPL without
// exception.
+#define DEBUG 0
+
+#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/ptrace.h>
frysk::sys::ptrace::AddressSpace::peek(::jnixx::env env, jint pid, jlong addr) {
union word w;
long paddr = addr & -sizeof(long);
-#if DEBUG
- fprintf(stderr, "peek 0x%lx paddr 0x%lx", (long)addr, paddr);
-#endif
+ if (DEBUG)
+ fprintf(stderr, "peek 0x%lx paddr 0x%lx", (long)addr, paddr);
w.l = ptraceOp(env, GetPtPeek(env), pid, (void*)paddr, 0);
-#if DEBUG
- fprintf(stderr, " word 0x%lx", w.l);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " word 0x%lx", w.l);
int index = addr & (sizeof(long) - 1);
-#if DEBUG
- fprintf(stderr, " index %d", index);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " index %d", index);
uint8_t byte = w.b[index];
-#if DEBUG
- fprintf(stderr, " byte %d/0x%x\n", byte, byte);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " byte %d/0x%x\n", byte, byte);
return byte;
}
frysk::sys::ptrace::AddressSpace::poke(::jnixx::env env, jint pid, jlong addr, jint data) {
// Implement read-modify-write
union word w;
-#if DEBUG
- fprintf(stderr, "poke 0x%x", (int)(data & 0xff));
-#endif
+ if (DEBUG)
+ fprintf(stderr, "poke 0x%x", (int)(data & 0xff));
long paddr = addr & -sizeof(long);
-#if DEBUG
- fprintf(stderr, " addr 0x%lx paddr 0x%lx", (long)addr, paddr);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " addr 0x%lx paddr 0x%lx", (long)addr, paddr);
w.l = ptraceOp(env, GetPtPeek(env), pid, (void*)paddr, 0);
-#if DEBUG
- fprintf(stderr, " word 0x%lx", w.l);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " word 0x%lx", w.l);
int index = addr & (sizeof(long) - 1);
-#if DEBUG
- fprintf (stderr, " index %d", index);
-#endif
+ if (DEBUG)
+ fprintf (stderr, " index %d", index);
w.b[index] = data;
-#if DEBUG
- fprintf(stderr, " word 0x%lx\n", w.l);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " word 0x%lx\n", w.l);
ptraceOp(env, GetPtPoke(env), pid, (void*)(addr & -sizeof(long)), w.l);
}
verifyBounds(env, byteArray, offset, length);
// Somewhat more clueful implementation
for (jlong i = 0; i < length;) {
-#if DEBUG
- fprintf(stderr,
- "transfer pid %d addr 0x%lx length %d offset %d op %d (%s)",
- (int)pid, (long)addr, (int)length, (int)offset,
- (int)op, op_as_string(op));
-#endif
-
+ if (DEBUG)
+ fprintf(stderr,
+ "transfer pid %d addr 0x%lx length %d offset %d op %d (%s) ...",
+ (int)pid, (long)addr, (int)length, (int)offset,
+ (int)op, ptraceOpToString(op));
union word w;
unsigned long waddr = addr & -sizeof(long);
unsigned long woff = (addr - waddr);
wend = woff + remaining;
long wlen = wend - woff;
-#if DEBUG
- fprintf(stderr,
- " i %ld waddr 0x%lx woff %lu wend %lu remaining %lu wlen %lu",
- (long)i, waddr, woff, wend, remaining, wlen);
-#endif
+ if (DEBUG)
+ fprintf(stderr,
+ " i %ld waddr 0x%lx woff %lu wend %lu remaining %lu wlen %lu ...",
+ (long)i, waddr, woff, wend, remaining, wlen);
// Either a peek; or a partial write requiring read/modify/write.
if (op == ptPeek || woff != 0 || wend != sizeof(long)) {
- w.l = ptraceOp(env, ptPeek, pid, (void*)waddr, 0);
-#if DEBUG
- fprintf(stderr, " peek 0x%lx", w.l);
-#endif
- }
+ w.l = ptraceOp(env, ptPeek, pid, (void*)waddr, 0);
+ if (DEBUG)
+ fprintf(stderr, " peek 0x%lx ...", w.l);
+ }
// extract or modify
jbyteArrayElements bytes = jbyteArrayElements(env, byteArray);
memcpy(offset + i + bytes.elements(), &w.b[woff], wlen);
else {
memcpy(&w.b[woff], offset + i + bytes.elements(), wlen);
-#if DEBUG
- fprintf(stderr, " poke 0x%lx", w.l);
-#endif
+ if (DEBUG)
+ fprintf(stderr, " poke 0x%lx ...", w.l);
w.l = ptraceOp(env, ptPoke, pid, (void*)waddr, w.l);
}
bytes.release();
i += wlen;
addr += wlen;
-#if DEBUG
- fprintf(stderr, "\n");
-#endif
+ if (DEBUG)
+ fprintf(stderr, "\n");
}
}
// version and license this file solely under the GPL without
// exception.
+#define DEBUG 0
+
+#include <stdio.h>
+#include <string.h>
#include <errno.h>
#include <sys/ptrace.h>
#include "linux.ptrace.h"
#include "jnixx/exceptions.hxx"
-static const char*
-op_as_string(int op) {
+const char*
+ptraceOpToString(int op) {
switch(op) {
#define OP(NAME) case NAME: return #NAME
OP(PTRACE_ATTACH);
long
ptraceOp(::jnixx::env env, int op, int pid, void* addr, long data) {
errno = 0;
- long result = ::ptrace ((enum __ptrace_request) op, pid, addr, data);
- if (errno != 0)
+ long result = ::ptrace((enum __ptrace_request) op, pid, addr, data);
+ if (errno != 0) {
+ int err = errno;
+ if (DEBUG)
+ fprintf(stderr, "throwing %s\n", strerror(err));
errnoException(env, errno, "ptrace",
"op 0x%x (%s), pid %d, addr 0x%lx, data 0x%lx",
- op, op_as_string(op), pid, (long)addr, data);
+ op, ptraceOpToString(op), pid, (long)addr, data);
+ }
return result;
}
// exception.
extern long ptraceOp(::jnixx::env, int, int, void*, long);
+extern const char *ptraceOpToString(int op);