public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: swagiaal@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: swagiaal: Converted fstep to ProcRunUtil.
Date: Wed, 19 Mar 2008 19:37:00 -0000	[thread overview]
Message-ID: <20080319193725.5875.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  bb46ac6e3f62e6ec77509f6d563453a3e7df405f (commit)
      from  84e6afb1e5439f82a59dc7aa131c37e35cf237e1 (commit)

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

- Log -----------------------------------------------------------------
commit bb46ac6e3f62e6ec77509f6d563453a3e7df405f
Author: Sami Wagiaalla <swagiaal@redhat.com>
Date:   Wed Mar 19 15:36:13 2008 -0400

    swagiaal: Converted fstep to ProcRunUtil.
    
    frysk-core/frysk/bindir/ChangeLog
    +2008-03-19  Sami Wagiaalla  <swagiaal@redhat.com>
    +
    +	* fstep.java: Now uses ProcRunUtil.
    +
    
    frysk-core/frysk/util/ChangeLog
    +2008-03-19  Sami Wagiaalla  <swagiaal@redhat.com>
    +
    +	* ProcRunUtil.java: remove observationAdded()/Realized().
    +

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

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog      |    4 +
 frysk-core/frysk/bindir/fstep.java     |   96 ++++++++++---------------------
 frysk-core/frysk/util/ChangeLog        |    4 +
 frysk-core/frysk/util/ProcRunUtil.java |   47 +++++++---------
 4 files changed, 59 insertions(+), 92 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index 3606ba8..d9cf717 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,7 @@
+2008-03-19  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* fstep.java: Now uses ProcRunUtil.
+
 2008-03-17  Andrew Cagney  <cagney@redhat.com>
 
 	* fstep.java: Update; using TaskAttachedObserverXXX.
diff --git a/frysk-core/frysk/bindir/fstep.java b/frysk-core/frysk/bindir/fstep.java
index 6fa722a..44b9a83 100644
--- a/frysk-core/frysk/bindir/fstep.java
+++ b/frysk-core/frysk/bindir/fstep.java
@@ -39,26 +39,25 @@
 
 package frysk.bindir;
 
-import frysk.isa.signals.Signal;
-import frysk.proc.FindProc;
-import java.util.List;
-import frysk.proc.Auxv;
-import frysk.proc.Manager;
-import frysk.util.CommandlineParser;
 import inua.eio.ByteBuffer;
-import frysk.proc.TaskObserver;
-import lib.opcodes.Disassembler;
-import java.util.HashMap;
+
 import java.util.ArrayList;
-import gnu.classpath.tools.getopt.OptionException;
-import gnu.classpath.tools.getopt.Option;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
+
+import lib.opcodes.Disassembler;
+import frysk.isa.signals.Signal;
 import frysk.proc.Action;
-import frysk.proc.Proc;
+import frysk.proc.Auxv;
+import frysk.proc.Manager;
 import frysk.proc.Task;
-import frysk.proc.TaskAttachedObserverXXX;
+import frysk.proc.TaskObserver;
+import frysk.util.ProcRunUtil;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
 
-public class fstep implements TaskAttachedObserverXXX,
+public class fstep implements ProcRunUtil.NewTaskObserver,
   TaskObserver.Code,
   TaskObserver.Instruction,
   TaskObserver.Terminated
@@ -76,7 +75,7 @@ public class fstep implements TaskAttachedObserverXXX,
   private static int instrs;
 
   // The command to execute
-  static String[] command;
+//  static String[] command;
 
   // The process id to trace
   static int pid;
@@ -89,15 +88,7 @@ public class fstep implements TaskAttachedObserverXXX,
     sample = 0;
     instrs = 1;
 
-    final CommandlineParser parser = new CommandlineParser("fstep")
-    {
-
-      public void parseCommand(Proc command) {
-	  fstep.command = command.getCmdLine();
-      }
-      
-    };
-    parser.add(new Option("sample", 's',
+    Option sampleOption = new Option("sample", 's',
 			  "how often to print the current instruction",
 			  "samples")
       {
@@ -115,9 +106,9 @@ public class fstep implements TaskAttachedObserverXXX,
 	      throw ex;
 	    }
 	}
-      });
+      };
 
-    parser.add(new Option("instructions", 'i',
+    Option instructionsOption = new Option("instructions", 'i',
 			  "how many instructions to print at each step/sample",
 			  "instructions")
       {
@@ -135,9 +126,9 @@ public class fstep implements TaskAttachedObserverXXX,
 	      throw ex;
 	    }
 	}
-      });
+      };
 
-    parser.add(new Option("pid", 'p',
+    Option pidOptions = new Option("pid", 'p',
 			  "the running process to step",
 			  "pid")
       {
@@ -155,40 +146,14 @@ public class fstep implements TaskAttachedObserverXXX,
 	      throw ex;
 	    }
 	}
-      });
-
-    parser.parse(args);
-    if ((command == null || command.length == 0)
-	&& pid == 0)
-      {
-	System.err.println("fstep: Neither command line nor pid provided");
-	parser.printHelp();
-	System.exit(-1);
-      }
-    if (command != null && command.length != 0 && pid != 0)
-      {
-	System.err.println("fstep: Provide either a command line or a pid");
-	parser.printHelp();
-	System.exit(-1);
-      }
+      };
 
     final fstep step = new fstep();
-    if (pid != 0) {
-	Manager.host.requestProc(pid, new FindProc() {
-	    public void procFound(Proc proc) {
-		Task mainTask = proc.getMainTask();
-		mainTask.requestAddAttachedObserver(step);
-	    }
-	    public void procNotFound(int pid) {
-		System.err.println("no such process: " + pid);
-		parser.printHelp();
-		System.exit(-1);
-	    }});
-      }
-    else
-      Manager.host.requestCreateAttachedProc(command, step);
     
-    Manager.eventLoop.run();
+    Option[] options = new Option[]{sampleOption, instructionsOption, pidOptions};
+    
+    ProcRunUtil procRunUtil = new ProcRunUtil("fstep", "fstep <PID|EXEC> [OPTIONS]", args, step , options, ProcRunUtil.DEFAULT);
+    procRunUtil.start();
   }
 
   /**
@@ -223,8 +188,7 @@ public class fstep implements TaskAttachedObserverXXX,
     }
   }
 
-  // TaskAttachedObserverXXX interface
-  public Action updateAttached(Task task)
+  public void notifyNewTask(Task task)
   {
     // We only need one disassembler since all Tasks share their memory.
     if (disassembler == null)
@@ -241,8 +205,8 @@ public class fstep implements TaskAttachedObserverXXX,
     // then we want to start stepping at the actual start of the
     // process (and not inside the dynamic linker).
     long startAddress = 0;
-    if (command != null && command.length != 0)
-      {
+//    if (command != null && command.length != 0)
+//      {
 	Auxv[] auxv = task.getProc().getAuxv ();
 	for (int i = 0; i < auxv.length; i++)
 	  {
@@ -252,7 +216,9 @@ public class fstep implements TaskAttachedObserverXXX,
 		break;
 	      }
 	  }
-      }
+//      }
+    
+//    System.out.println("fstep.updateAttached() startAddress 0x" + Long.toHexString(startAddress));
 
     if (startAddress == 0)
       {
@@ -262,7 +228,7 @@ public class fstep implements TaskAttachedObserverXXX,
       }
     else
       task.requestAddCodeObserver(this, startAddress);
-    return Action.BLOCK;
+    
   }
 
   // TaskObserver.Code interface
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index 1ddb337..66884f6 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,7 @@
+2008-03-19  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* ProcRunUtil.java: remove observationAdded()/Realized().
+
 2008-03-18  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* CommandlineParser.java (CommandlineParser): Trim
diff --git a/frysk-core/frysk/util/ProcRunUtil.java b/frysk-core/frysk/util/ProcRunUtil.java
index 1eaaf4b..f46db8d 100644
--- a/frysk-core/frysk/util/ProcRunUtil.java
+++ b/frysk-core/frysk/util/ProcRunUtil.java
@@ -39,17 +39,17 @@
 
 package frysk.util;
 
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
+
 import frysk.proc.Action;
 import frysk.proc.Manager;
 import frysk.proc.Proc;
 import frysk.proc.ProcObserver;
 import frysk.proc.ProcTasksObserver;
 import frysk.proc.Task;
-import frysk.proc.TaskObserver;
 import frysk.proc.TaskAttachedObserverXXX;
+import frysk.proc.TaskObserver;
 import frysk.proc.TaskObserver.Cloned;
 import frysk.proc.TaskObserver.Execed;
 import frysk.proc.TaskObserver.Forked;
@@ -75,11 +75,24 @@ public class ProcRunUtil {
     private RunningUtilOptions options;
     private TaskObserver[] observers;
 
+    private NewTaskObserver newTaskObserver;
+
+    public static interface NewTaskObserver{
+	void notifyNewTask(Task task);
+    }
+    
     public static class RunningUtilOptions {
 	boolean followForks = true;
     }
     
     public static final RunningUtilOptions DEFAULT = new RunningUtilOptions();
+
+    public ProcRunUtil(String utilName, String usage, String[] args,
+	    NewTaskObserver newTaskObserver, Option[] customOptions,
+	    RunningUtilOptions options) {
+	this(utilName, usage, args, new TaskObserver[]{}, customOptions, options);
+	this.newTaskObserver = newTaskObserver;
+    }
     
     public ProcRunUtil(String utilName, String usage, String[] args,
 	    TaskObserver[] observers, Option[] customOptions,
@@ -122,36 +135,14 @@ public class ProcRunUtil {
 	}
 	if(options.followForks){
 	    this.addTaskObserver(forkedObserver, task);
-	    observationRequested(task);
 	}
     }
     
-    private HashMap observationCounters = new HashMap();
-    synchronized private void observationRequested(Task task) {
-	Integer i = (Integer)observationCounters.get(task);
-	if (i == null)
-	    i = new Integer(1);
-	else
-	    i = new Integer(i.intValue() + 1);
-	observationCounters.put(task, i);
-    }
-
-    synchronized private void observationRealized(Task task) {
-	Integer i = (Integer)observationCounters.get(task);
-	// must be non-null
-	int j = i.intValue();
-	if (j == 1) {
-	    // Store a dummy into the map to detect errors.
-	    observationCounters.put(task, new Object());
-	    task.requestUnblock(attachedObserver);
-	}
-	else
-	    observationCounters.put(task, new Integer(--j));
-    }
-
     class ForkedObserver implements TaskObserver.Forked {
 	public Action updateForkedOffspring(Task parent, Task offspring) {
+	    newTaskObserver.notifyNewTask(offspring);
 	    addObservers(offspring.getProc());
+	    offspring.requestUnblock(this);
 	    return Action.BLOCK;
 	}
 
@@ -163,7 +154,6 @@ public class ProcRunUtil {
 	}
 
 	public void addedTo(Object observable) {
-	    observationRealized((Task) observable);
 	}
 
 	public void deletedFrom(Object observable) {
@@ -174,11 +164,14 @@ public class ProcRunUtil {
 	private Set procs = new HashSet();
 
 	public synchronized Action updateAttached(Task task) {
+	    newTaskObserver.notifyNewTask(task);
+		
 	    Proc proc = task.getProc();
 	    if (!procs.contains(proc)) {
 		procs.add(proc);
 		addObservers(proc);
 	    }
+	    task.requestUnblock(this);
 	    return Action.BLOCK;
 	}
 


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


                 reply	other threads:[~2008-03-19 19:37 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=20080319193725.5875.qmail@sourceware.org \
    --to=swagiaal@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).