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 fcatch to use ProcRunUtil.
Date: Mon, 10 Mar 2008 21:04:00 -0000	[thread overview]
Message-ID: <20080310210401.19852.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  5492baa03cd955076e3b9cc5305def492de72920 (commit)
      from  0bb075af459281dacab34a6711754b1fbc3279fd (commit)

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

- Log -----------------------------------------------------------------
commit 5492baa03cd955076e3b9cc5305def492de72920
Author: Sami Wagiaalla <swagiaal@redhat.com>
Date:   Mon Mar 10 16:29:44 2008 -0400

    swagiaal: converted fcatch to use ProcRunUtil.
    
    frysk-core/frysk/bindir/ChangeLog
    +2008-03-10  Sami Wagiaalla  <swagiaal@redhat.com>
    +
    +	* fcatch.java: Moved the bulk of the code to FCatch.
    +
    
    frysk-core/frysk/debuginfo/ChangeLog
    +2008-03-10  Sami Wagiaalla  <swagiaal@redhat.com>
    +
    +	* DebugInfoStackFactory.java: Added DEFAULT options.
    +
    
    frysk-core/frysk/util/ChangeLog
    +2008-03-10  Sami Wagiaalla  <swagiaal@redhat.com>
    +
    +	* FCatch.java: Now uses ProcRunUtil.
    +	* TestFCatch.java: Deleted.
    +

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

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog                  |    4 +
 frysk-core/frysk/bindir/fcatch.java                |   61 +----
 frysk-core/frysk/debuginfo/ChangeLog               |    4 +
 .../frysk/debuginfo/DebugInfoStackFactory.java     |    7 +
 frysk-core/frysk/util/ChangeLog                    |    5 +
 frysk-core/frysk/util/FCatch.java                  |  328 +++-----------------
 frysk-core/frysk/util/TestFCatch.java              |  320 -------------------
 7 files changed, 74 insertions(+), 655 deletions(-)
 delete mode 100644 frysk-core/frysk/util/TestFCatch.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index a399be4..ab1c7d9 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,7 @@
+2008-03-10  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* fcatch.java: Moved the bulk of the code to FCatch.
+
 2008-03-07  Teresa Thomas  <tthomas@redhat.com>
 
 	* fhpd.java (main): Add event to handle SIGINT.
diff --git a/frysk-core/frysk/bindir/fcatch.java b/frysk-core/frysk/bindir/fcatch.java
index ed5f6cf..cb7f6c2 100644
--- a/frysk-core/frysk/bindir/fcatch.java
+++ b/frysk-core/frysk/bindir/fcatch.java
@@ -39,73 +39,20 @@
 
 package frysk.bindir;
 
-import frysk.util.Util;
-import frysk.util.CommandlineParser;
 import frysk.util.FCatch;
-import frysk.proc.Proc;
-import gnu.classpath.tools.getopt.Option;
-import gnu.classpath.tools.getopt.OptionException;
 
 public class fcatch {
 
     FCatch catcher = new FCatch();
 
-    private boolean requestedPid = false;
-
-    private static StringBuffer argString;
+    
+    
 
     private void run(String[] args) {
-	CommandlineParser parser = new CommandlineParser("fcatch") {
-	    protected void validate() throws OptionException {
-		if (!requestedPid && argString == null)
-		    throw new OptionException("no command or PID specified");
-	    }
-
-	    //@Override
-	    public void parseCommand(Proc command) {
-		// FIXME: This concatinatin the string is unnecessary.
-		String[] line = command.getCmdLine();
-		argString = new StringBuffer(line[0]);
-		for (int i = 1; i < line.length; i++)
-		    argString.append(" ").append(line[i]);
-	    }
-
-	};
-	addOptions(parser);
-	parser
-		.setHeader("Usage: fcatch [OPTIONS] -- PATH ARGS || fcatch [OPTIONS] PID");
-
-	parser.parse(args);
-
-	if (argString != null) {
-	    String[] cmd = argString.toString().split("\\s");
-
-	    catcher.trace(cmd, requestedPid);
-	}
-    }
-
-    public void addOptions(CommandlineParser p) {
-	p.add(new Option('p', "pid to trace", "PID") {
-	    public void parsed(String arg) throws OptionException {
-		try {
-		    int pid = Integer.parseInt(arg);
-		    catcher.addProc(Util.getProcFromPid(pid));
-		    requestedPid = true;
-		    if (argString == null)
-			argString = new StringBuffer(pid);
-		    else
-			argString.append(" " + pid);
-
-		} catch (NumberFormatException e) {
-		    OptionException oe = new OptionException(
-			    "couldn't parse pid: " + arg);
-		    oe.initCause(e);
-		    throw oe;
-		}
-	    }
-	});
+	catcher.run(args);
     }
 
+   
     public static void main(String[] args) {
 	fcatch fc = new fcatch();
 	fc.run(args);
diff --git a/frysk-core/frysk/debuginfo/ChangeLog b/frysk-core/frysk/debuginfo/ChangeLog
index df98681..e28b011 100644
--- a/frysk-core/frysk/debuginfo/ChangeLog
+++ b/frysk-core/frysk/debuginfo/ChangeLog
@@ -1,3 +1,7 @@
+2008-03-10  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* DebugInfoStackFactory.java: Added DEFAULT options.
+
 2008-03-03  Andrew Cagney  <cagney@redhat.com>
 
 	* TestObjectDeclarationSearchEngine.java: Use frysk.config.
diff --git a/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java b/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java
index df7b270..8556395 100644
--- a/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java
+++ b/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java
@@ -51,6 +51,13 @@ import frysk.stack.StackFactory;
  */
 public class DebugInfoStackFactory {
 
+    public static final PrintStackOptions DEFAULT = new PrintStackOptions();
+    static{
+	DEFAULT.setPrintParameters(true);
+	DEFAULT.setPrintFullpath(false);
+	DEFAULT.setPrintScopes(false);
+	DEFAULT.setPrintVirtualFrames(true);
+    }
     /**
      * Create an ABI stack backtrace, make the simpler debug-info
      * methods.
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index ef7f858..da5b2ac 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,8 @@
+2008-03-10  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* FCatch.java: Now uses ProcRunUtil.
+	* TestFCatch.java: Deleted.
+
 2008-03-07  Sami Wagiaalla  <swagiaal@redhat.com>
 
 	* ProcRunUtil.java: Renamed ProcRunningUtil to ProcRunUtil.
diff --git a/frysk-core/frysk/util/FCatch.java b/frysk-core/frysk/util/FCatch.java
index 9009213..e080b83 100644
--- a/frysk-core/frysk/util/FCatch.java
+++ b/frysk-core/frysk/util/FCatch.java
@@ -39,246 +39,72 @@
 
 package frysk.util;
 
-import frysk.isa.signals.Signal;
-import java.io.File;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.util.HashSet;
-import java.util.Iterator;
-import frysk.rsl.Log;
+import java.util.HashMap;
+
+import frysk.debuginfo.DebugInfoStackFactory;
+import frysk.isa.signals.Signal;
 import frysk.proc.Action;
-import frysk.proc.Manager;
-import frysk.proc.Proc;
 import frysk.proc.Task;
 import frysk.proc.TaskObserver;
-import frysk.stack.Frame;
-import frysk.stack.StackFactory;
+import frysk.rsl.Log;
+import gnu.classpath.tools.getopt.Option;
 
 public class FCatch {
-    private static final Log fine = Log.fine(FCatch.class);
-
-    private int numTasks = 0;
-
-    //True if we're tracing children as well.
-    boolean traceChildren;
-
-    boolean firstCall = true;
-
-    private StringBuffer stackTrace = new StringBuffer();
-
-    private Blocker blocker;
-
-    private SignalObserver signalObserver;
-
-    private Signal sig;
-
-    private int stacklevel = 0;
-
-    private Task sigTask;
-
-    HashSet signaledTasks = new HashSet();
-
-    Proc proc = null;
-
-
-    Frame[] frames;
-
-    /**
-     * Sets up the attached process.
-     * 
-     * @param command Command line arguments, including executable name
-     * @param attach  Whether to create a new process with the above arguments, or
-     * to attach to an already-running process.
-     */
-    public void trace(String[] command, boolean attach) {
-	fine.log(this, "trace");
-
-	if (attach == true)
-	    init();
-	else {
-	    File exe = new File(command[0]);
-	    // XXX: There is a race between this .exists call, a remove of
-	    // the executable, and the subsequent attempt to exec it.  The
-	    // only robust way to make this work is to detect the failure
-	    // in the Attach observer - when it fails.
-	    if (exe.exists())
-		Manager.host.requestCreateAttachedProc(command,
-			new CatchObserver());
-	    else {
-		System.err.println("fcatch: can't find executable!");
-		System.exit(1);
-	    }
-	}
 
-	// Run the event-loop from within this thread - no need to
-	// multi-thread this application.
-	Manager.eventLoop.run();
-	fine.log(this, "exiting trace");
-    }
-
-    /**
-     * Attaches FCatch to an already running process.
-     */
-    private void init() {
-	fine.log(this, "init");
-	iterateTasks(proc);
-	fine.log(this, "exiting init");
-    }
-
-    /**
-     * Adds a CatchObserver to each of the Tasks belonging to the process.
-     */
-    private void iterateTasks(Proc proc) {
-	Iterator i = proc.getTasks().iterator();
-	while (i.hasNext()) {
-	    ((Task) i.next()).requestAddAttachedObserver(new CatchObserver());
-	}
-    }
-
-    /**
-     * Adds a PID to be traced to this class' HashSet.
-     * 
-     * @param id  The PID to be traced
-     */
-    public void addProc(Proc proc) {
-	fine.log(this, "addProc", proc);
-	this.proc = proc;
-    }
-
-    /**
-     * Builds a stack trace from the incoming blocked task, and appends the output
-     * to this class' StringBuffer. Decrements the numTasks variable to let FCatch
-     * know when to unblock the signaled thread.
-     * 
-     * @param task    The Task to be StackTraced
-     */
-    private void generateStackTrace(Task task) {
-	fine.log(this, "generateStackTrace", task);
-	--this.numTasks;
-	Frame frame = null;
-	try {
-	    frame = StackFactory.createFrame(task);
-	} catch (Exception e) {
-	    e.printStackTrace();
-	}
+    private static final Log fine = Log.fine(FCatch.class);
 
-	StringWriter stringWriter = new StringWriter();
-	PrintWriter printWriter = new PrintWriter(stringWriter);
-	StackFactory.printStack(printWriter, frame);
-	this.stackTrace.append(stringWriter.getBuffer());
+    private PrintWriter printWriter = new PrintWriter(System.out);
+    HashMap signaledTasks = new HashMap();
 
-	fine.log(this, "exiting generateStackTrace", task);
+    private static class SignalStack {
+	Signal signal;
+	String stack;
     }
 
     /**
-     * Returns a String representation of the stack trace thus far.
+     * Builds a stack trace from the incoming blocked task, and appends the
+     * output to this class' StringBuffer. Decrements the numTasks variable to
+     * let FCatch know when to unblock the signaled thread.
      * 
-     * @return The stack trace thus far.
-     */
-    public String getStackTrace() {
-	return this.stackTrace.toString();
-    }
-
-    /**
-     * Prints the stack trace.
+     * @param task
+     *                The Task to be StackTraced
      */
-    public String toString() {
-	String trace = this.stackTrace.toString();
-	System.out.println(trace);
-	return trace;
+    private void printStackTrace(Task task, SignalStack signalStack) {
+	printWriter.println("\n" + task.getProc().getPid() + "."
+		+ task.getTid() + " was terminated with signal "
+		+ signalStack.signal);
+	printWriter.println(signalStack.stack);
+	printWriter.flush();
     }
 
     /**
-     * Depending on the signal, appends the signal type to the stack trace 
-     * StringBuffer and calls generateStackTrace(Task).
-     * If all Tasks have completed their trace, this method unblocks the signaled
-     * thread blocked by a SignaledObserver, and then removes the Blocker
-     * Objects from all the Tasks.
-     * 
-     * @param task    The Task recently blocked.
+     * An observer that sets up things once frysk has set up the requested proc
+     * and attached to it.
      */
-    public synchronized void handleTaskBlock(Task task) {
-	this.signaledTasks.add(task);
-
-	stackTrace.append(sig.toString());
-	stackTrace.append(" detected - dumping stack trace for TID ");
-	stackTrace.append(task.getTid());
-	stackTrace.append("\n");
-	generateStackTrace(task);
+    class CatchObserver implements TaskObserver.Terminated, TaskObserver.Signaled{
 
-	if (numTasks <= 0) {
-	    System.out.println(this.stackTrace.toString());
-	    this.stackTrace = new StringBuffer();
-	    this.stackTrace.append(stacklevel++ + "\n");
-	    sigTask.requestUnblock(signalObserver);
-	    Iterator i = task.getProc().getTasks().iterator();
-	    while (i.hasNext()) {
-		Task t = (Task) i.next();
-		t.requestDeleteInstructionObserver(blocker);
+	public Action updateTerminated(Task task, Signal signal, int value) {
+	    SignalStack signalStack = (SignalStack) signaledTasks.get(task);
+	    if (signalStack != null && signal.equals(signalStack.signal)) {
+		printStackTrace(task, signalStack);
 	    }
-	}
-    }
-
-    /**
-     * An observer that sets up things once frysk has set up
-     * the requested proc and attached to it.
-     */
-    class CatchObserver implements TaskObserver.Attached, TaskObserver.Cloned,
-	    TaskObserver.Terminating, TaskObserver.Terminated {
-	/**
-	 * This Task has been attached to and blocked - attach the rest of this
-	 * Object's implemented Observers to it.
-	 */
-	public Action updateAttached(Task task) {
-	    numTasks = task.getProc().getTasks().size();
-	    fine.log(this, "updateAttached", task);
-	    if (signalObserver == null)
-		signalObserver = new SignalObserver();
-
-	    task.requestAddSignaledObserver(signalObserver);
-	    task.requestAddClonedObserver(this);
-	    task.requestAddTerminatingObserver(this);
-	    task.requestAddTerminatedObserver(this);
-	    task.requestUnblock(this);
-	    return Action.BLOCK;
-	}
-
-	public Action updateClonedParent(Task parent, Task offspring) {
-	    fine.log(this, "updateClonedParent", parent, "offspring",
-		     offspring);
-	    //System.out.println("Cloned.updateParent");
-	    parent.requestUnblock(this);
-	    return Action.BLOCK;
-	}
-
-	/**
-	 * One of the Tasks has forked - make sure that the child is also traced
-	 * properly.
-	 */
-	public Action updateClonedOffspring(Task parent, Task offspring) {
-	    fine.log(this, "updateClonedOffspring", offspring, "parent",
-		     parent);
-	    FCatch.this.numTasks = offspring.getProc().getTasks().size();
-	    SignalObserver sigo = new SignalObserver();
-
-	    offspring.requestAddSignaledObserver(sigo);
-	    offspring.requestAddTerminatingObserver(this);
-	    offspring.requestAddClonedObserver(this);
-	    offspring.requestAddTerminatedObserver(this);
-	    offspring.requestUnblock(this);
-	    return Action.BLOCK;
-	}
-
-	public Action updateTerminating(Task task, Signal signal, int value) {
-	    fine.log(this, "updateTerminating", task, "signal", signal);
 	    return Action.CONTINUE;
 	}
 
-	public Action updateTerminated(Task task, Signal signal, int value) {
-	    fine.log(this, "updateTerminated", task, "signal", signal);
-	    if (--FCatch.this.numTasks <= 0)
-		Manager.eventLoop.requestStop();
-
+	public Action updateSignaled(Task task, Signal signal) {
+	    fine.log(this, "updateSignaled", task, "signal", signal);
+	    
+	    StringWriter stringWriter = new StringWriter();
+	    
+	    DebugInfoStackFactory.printVirtualTaskStackTrace(new PrintWriter(stringWriter), task, DebugInfoStackFactory.DEFAULT);
+	    
+	    SignalStack signalStack = new SignalStack();
+	    signalStack.signal = signal;
+	    signalStack.stack = stringWriter.getBuffer().toString();
+	    signaledTasks.put(task, signalStack);
+	    
 	    return Action.CONTINUE;
 	}
 
@@ -295,71 +121,17 @@ public class FCatch {
 	}
     }
 
-    /**
-     * Intercepts signals to a Task and deals with them appropriately.
-     */
-    class SignalObserver implements TaskObserver.Signaled {
-	/**
-	 * The Task received a signal - block all the other tasks, and
-	 * append to the StringBuffer member of FCatch that this Task
-	 * was signaled.
-	 */
-	public Action updateSignaled(Task task, Signal signal) {
-	    fine.log(this, "updateSignaled", task, "signal", signal);
-	    sigTask = task;
+    public void run(String[] args) {
+	
+	CatchObserver catchObserver = new CatchObserver();
 
-	    FCatch.this.sig = signal;
-	    FCatch.this.numTasks = task.getProc().getTasks().size();
+	ProcRunUtil procRunUtil = new ProcRunUtil("fcatch",
+		"Usage: fcatch [OPTIONS] -- PATH ARGS || fcatch [OPTIONS] PID",
+		args, new TaskObserver[] { catchObserver},
+		new Option[] {}, ProcRunUtil.DEFAULT);
 
-	    if (FCatch.this.numTasks > 1
-		    && FCatch.this.signaledTasks.contains(task)) {
-		FCatch.this.signaledTasks.remove(task);
-		return Action.CONTINUE;
-	    }
+	procRunUtil.start();
 
-	    stackTrace.append("fcatch: from PID " + task.getProc().getPid()
-		    + " TID " + task.getTid() + ":\n");
-	    blocker = new Blocker();
-	    Iterator i = task.getProc().getTasks().iterator();
-	    while (i.hasNext()) {
-		Task t = (Task) i.next();
-		t.requestAddInstructionObserver(blocker);
-	    }
-	    return Action.BLOCK;
-	}
-
-	public void addFailed(Object observable, Throwable w) {
-	    w.printStackTrace();
-	}
-
-	public void addedTo(Object observable) {
-	    fine.log(this, "SignalObserver.addedTo", observable);
-	}
-
-	public void deletedFrom(Object observable) {
-	    fine.log(this, "deletedFrom", observable);
-	}
     }
 
-    /**
-     * Blocks threads; makes sure they get stack traced.
-     */
-    class Blocker implements TaskObserver.Instruction {
-	public Action updateExecuted(Task task) {
-	    handleTaskBlock(task);
-	    return Action.BLOCK;
-	}
-
-	public void addFailed(Object observable, Throwable w) {
-	    w.printStackTrace();
-	}


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


                 reply	other threads:[~2008-03-10 21:04 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=20080310210401.19852.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).