public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Add more tracing to ptrace code (unfortunatly fprintf).
Date: Fri, 20 Jun 2008 19:10:00 -0000	[thread overview]
Message-ID: <20080620191030.25537.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  50ae71ea90cbbb3d8822fa7929a08322247cd24c (commit)
      from  9147b4bdb1a382b221dcdc340365ebd3f411f694 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 50ae71ea90cbbb3d8822fa7929a08322247cd24c
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Jun 20 15:07:07 2008 -0400

    Add more tracing to ptrace code (unfortunatly fprintf).
    
    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.

-----------------------------------------------------------------------

Summary of changes:
 frysk-sys/frysk/sys/ptrace/ChangeLog            |    9 +++
 frysk-sys/frysk/sys/ptrace/cni/AddressSpace.cxx |   88 ++++++++++-------------
 frysk-sys/frysk/sys/ptrace/cni/Ptrace.cxx       |   18 ++++--
 frysk-sys/frysk/sys/ptrace/cni/Ptrace.hxx       |    1 +
 frysk-sys/frysk/sys/ptrace/jni/AddressSpace.cxx |   88 ++++++++++-------------
 frysk-sys/frysk/sys/ptrace/jni/Ptrace.cxx       |   18 ++++--
 frysk-sys/frysk/sys/ptrace/jni/Ptrace.hxx       |    1 +
 7 files changed, 113 insertions(+), 110 deletions(-)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/sys/ptrace/ChangeLog b/frysk-sys/frysk/sys/ptrace/ChangeLog
index 9484163..30c1ac0 100644
--- a/frysk-sys/frysk/sys/ptrace/ChangeLog
+++ b/frysk-sys/frysk/sys/ptrace/ChangeLog
@@ -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.
diff --git a/frysk-sys/frysk/sys/ptrace/cni/AddressSpace.cxx b/frysk-sys/frysk/sys/ptrace/cni/AddressSpace.cxx
index 232e1f3..b8d0af7 100644
--- a/frysk-sys/frysk/sys/ptrace/cni/AddressSpace.cxx
+++ b/frysk-sys/frysk/sys/ptrace/cni/AddressSpace.cxx
@@ -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");
   }
 }
 
diff --git a/frysk-sys/frysk/sys/ptrace/cni/Ptrace.cxx b/frysk-sys/frysk/sys/ptrace/cni/Ptrace.cxx
index 4aa12eb..3375efd 100644
--- a/frysk-sys/frysk/sys/ptrace/cni/Ptrace.cxx
+++ b/frysk-sys/frysk/sys/ptrace/cni/Ptrace.cxx
@@ -37,6 +37,10 @@
 // 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;
 }
 
diff --git a/frysk-sys/frysk/sys/ptrace/cni/Ptrace.hxx b/frysk-sys/frysk/sys/ptrace/cni/Ptrace.hxx
index 78bda4d..1da0f03 100644
--- a/frysk-sys/frysk/sys/ptrace/cni/Ptrace.hxx
+++ b/frysk-sys/frysk/sys/ptrace/cni/Ptrace.hxx
@@ -38,3 +38,4 @@
 // exception.
 
 extern long ptraceOp(int, int, void*, long);
+extern const char *ptraceOpToString(int op);
diff --git a/frysk-sys/frysk/sys/ptrace/jni/AddressSpace.cxx b/frysk-sys/frysk/sys/ptrace/jni/AddressSpace.cxx
index 598d8cc..9600657 100644
--- a/frysk-sys/frysk/sys/ptrace/jni/AddressSpace.cxx
+++ b/frysk-sys/frysk/sys/ptrace/jni/AddressSpace.cxx
@@ -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");
   }
 }
 
diff --git a/frysk-sys/frysk/sys/ptrace/jni/Ptrace.cxx b/frysk-sys/frysk/sys/ptrace/jni/Ptrace.cxx
index 1a7c13f..dce86e5 100644
--- a/frysk-sys/frysk/sys/ptrace/jni/Ptrace.cxx
+++ b/frysk-sys/frysk/sys/ptrace/jni/Ptrace.cxx
@@ -37,6 +37,10 @@
 // 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;
 }
 
diff --git a/frysk-sys/frysk/sys/ptrace/jni/Ptrace.hxx b/frysk-sys/frysk/sys/ptrace/jni/Ptrace.hxx
index be134ef..46e2edd 100644
--- a/frysk-sys/frysk/sys/ptrace/jni/Ptrace.hxx
+++ b/frysk-sys/frysk/sys/ptrace/jni/Ptrace.hxx
@@ -38,3 +38,4 @@
 // exception.
 
 extern long ptraceOp(::jnixx::env, int, int, void*, long);
+extern const char *ptraceOpToString(int op);


hooks/post-receive
--
frysk system monitor/debugger


                 reply	other threads:[~2008-06-20 19:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080620191030.25537.qmail@sourceware.org \
    --to=cagney@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).