]> sourceware.org Git - frysk.git/commitdiff
Add more tracing to ptrace code (unfortunatly fprintf).
authorAndrew Cagney <cagney@redhat.com>
Fri, 20 Jun 2008 19:07:07 +0000 (15:07 -0400)
committerAndrew Cagney <cagney@redhat.com>
Fri, 20 Jun 2008 19:07:07 +0000 (15:07 -0400)
frysk-sys/frysk/sys/ptrace/ChangeLog
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.

frysk-sys/frysk/sys/ptrace/ChangeLog
frysk-sys/frysk/sys/ptrace/cni/AddressSpace.cxx
frysk-sys/frysk/sys/ptrace/cni/Ptrace.cxx
frysk-sys/frysk/sys/ptrace/cni/Ptrace.hxx
frysk-sys/frysk/sys/ptrace/jni/AddressSpace.cxx
frysk-sys/frysk/sys/ptrace/jni/Ptrace.cxx
frysk-sys/frysk/sys/ptrace/jni/Ptrace.hxx

index 94841632431fe39fd842c8d8fb5c4be77397a5d9..30c1ac0bcc1022480c0a164ce125a9a75a8138ba 100644 (file)
@@ -1,3 +1,12 @@
+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.
index 232e1f3991c74c71118158efcce5b37a27816482..b8d0af7c4b5bd2325b6103010849f724fb2be111 100644 (file)
@@ -37,6 +37,9 @@
 // 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>
@@ -61,21 +64,17 @@ jint
 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;
 }
 
@@ -83,25 +82,20 @@ void
 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);
 }
 
@@ -112,13 +106,11 @@ frysk::sys::ptrace::AddressSpace::transfer(jint op, jint pid, jlong addr,
   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);
@@ -130,37 +122,33 @@ frysk::sys::ptrace::AddressSpace::transfer(jint op, jint pid, jlong addr,
       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");
   }
 }
 
index 4aa12eb863a771f9de4516fe8d79bea7010eef92..3375efd4bc09563bc7d64a20475c04bc4b1f2fd9 100644 (file)
 // 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"
@@ -47,8 +51,8 @@
 #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);
@@ -82,10 +86,14 @@ op_as_string(int op) {
 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;
 }
 
index 78bda4d91e2aca9e44a7a4f22cc2c186b43bc919..1da0f03dd13de0b6c17bf4caffd2ce267072703d 100644 (file)
@@ -38,3 +38,4 @@
 // exception.
 
 extern long ptraceOp(int, int, void*, long);
+extern const char *ptraceOpToString(int op);
index 598d8cc42ef967c84acc9368dd87fc5ad4bd2fee..9600657c0f0d15e91631c71bbe39f4bb4aa50e5b 100644 (file)
@@ -37,6 +37,9 @@
 // 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>
@@ -60,21 +63,17 @@ jint
 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;
 }
 
@@ -82,25 +81,20 @@ void
 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);
 }
 
@@ -114,13 +108,11 @@ frysk::sys::ptrace::AddressSpace::transfer(::jnixx::env env,
   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);
@@ -132,19 +124,17 @@ frysk::sys::ptrace::AddressSpace::transfer(::jnixx::env env,
       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);
@@ -152,9 +142,8 @@ frysk::sys::ptrace::AddressSpace::transfer(::jnixx::env env,
       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();
@@ -162,9 +151,8 @@ frysk::sys::ptrace::AddressSpace::transfer(::jnixx::env env,
     i += wlen;
     addr += wlen;
 
-#if DEBUG
-    fprintf(stderr, "\n");
-#endif
+    if (DEBUG)
+      fprintf(stderr, "\n");
   }
 }
 
index 1a7c13f2850e1350b389da34433f18b34006d124..dce86e58d973cb6c6fd0f1196d8b4c5551e170f0 100644 (file)
 // 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"
@@ -47,8 +51,8 @@
 
 #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);
@@ -82,11 +86,15 @@ op_as_string(int op) {
 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;
 }
 
index be134eff4afd7b42127fe6a79f82b9b55d439511..46e2edd752125c217e55f09de469e561e8f4617c 100644 (file)
@@ -38,3 +38,4 @@
 // exception.
 
 extern long ptraceOp(::jnixx::env, int, int, void*, long);
+extern const char *ptraceOpToString(int op);
This page took 0.04471 seconds and 5 git commands to generate.