This is the mail archive of the frysk-cvs@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[SCM] master: Refactor fdebuginfo to use ProcStopUtil.


The branch, master has been updated
       via  24d8dca03611b748442112923bd6aeb02c9b249d (commit)
       via  7cb4834ca3b796e6f2a9cd7f79e5a447503c011c (commit)
      from  8f244478a0a028b9c88e66823411302dab3bd4fb (commit)

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

- Log -----------------------------------------------------------------
commit 24d8dca03611b748442112923bd6aeb02c9b249d
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Wed Feb 6 15:28:40 2008 -0500

    Refactor fdebuginfo to use ProcStopUtil.
    
    frysk-core/frysk/bindir/ChangeLog
    2008-02-06  Teresa Thomas  <tthomas@redhat.com>
    
    	* fdebuginfo.java (main): Use ProcStopUtil.
    	* TestFdebuginfo.java (testNoArguments): Update.

commit 7cb4834ca3b796e6f2a9cd7f79e5a447503c011c
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Wed Feb 6 15:24:46 2008 -0500

    Framework for frysk utilities that requires tasks to be stopped.
    
    frysk-core/frysk/util/ChangeLog
    2008-02-06  Teresa Thomas  <tthomas@redhat.com>
    
    	* ProcStopUtil.java: New.
    
    frysk-core/frysk/event/ChangeLog
    2008-02-06  Teresa Thomas  <tthomas@redhat.com>
    
    	* ProcEvent.java: New.

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

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog                  |    5 +
 frysk-core/frysk/bindir/TestFdebuginfo.java        |    2 +-
 frysk-core/frysk/bindir/fdebuginfo.java            |  117 ++------------
 frysk-core/frysk/event/ChangeLog                   |    4 +
 .../frysk/event/{Event.java => ProcEvent.java}     |   12 +-
 frysk-core/frysk/util/ChangeLog                    |    6 +-
 .../fdebuginfo.java => util/ProcStopUtil.java}     |  173 ++++++++++++--------
 7 files changed, 136 insertions(+), 183 deletions(-)
 copy frysk-core/frysk/event/{Event.java => ProcEvent.java} (93%)
 copy frysk-core/frysk/{bindir/fdebuginfo.java => util/ProcStopUtil.java} (59%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index 9e23ebb..67d09d3 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-06  Teresa Thomas  <tthomas@redhat.com>
+
+	* fdebuginfo.java: Refactor, use ProcStopUtil.
+	* TestFdebuginfo.java (testNoArguments): Update.
+
 2008-02-04  Tim Moore  <timoore@redhat.com>
 
 	* fhpd.java (main): Use ObservingTerminal instead of PtyTerminal.
diff --git a/frysk-core/frysk/bindir/TestFdebuginfo.java b/frysk-core/frysk/bindir/TestFdebuginfo.java
index 1ca9caa..899250a 100644
--- a/frysk-core/frysk/bindir/TestFdebuginfo.java
+++ b/frysk-core/frysk/bindir/TestFdebuginfo.java
@@ -67,7 +67,7 @@ public class TestFdebuginfo extends TestLib {
 	TearDownExpect e = new TearDownExpect(new String[] { 
 		Config.getBinFile("fdebuginfo").getAbsolutePath ()
 	});
-	e.expect("ERROR: No argument provided");      
+	e.expect("ERROR: No argument provided.");      
     }    
 
     public void testBadArguments() {
diff --git a/frysk-core/frysk/bindir/fdebuginfo.java b/frysk-core/frysk/bindir/fdebuginfo.java
index 40f3e8f..161f2a6 100644
--- a/frysk-core/frysk/bindir/fdebuginfo.java
+++ b/frysk-core/frysk/bindir/fdebuginfo.java
@@ -1,7 +1,6 @@
-
 //This file is part of the program FRYSK.
 
-//Copyright  2007 Red Hat Inc.
+//Copyright  2008 Red Hat Inc.
 
 //FRYSK is free software; you can redistribute it and/or modify it
 //under the terms of the GNU General Public License as published by
@@ -40,96 +39,31 @@
 
 package frysk.bindir;
 
-import java.io.File;
-
-import frysk.event.Event;
-import frysk.proc.Host;
-import frysk.proc.Manager;
-import frysk.proc.ProcBlockAction;
-import frysk.proc.ProcId;
+import frysk.event.ProcEvent;
 import frysk.proc.Proc;
-import frysk.proc.ProcObserver;
 import frysk.proc.Task;
-import frysk.proc.dead.LinuxExeHost;
 
-import frysk.util.CommandlineParser;
-import frysk.util.CoreExePair;
-import frysk.util.Util;
 import frysk.util.DebuginfoPaths;
+import frysk.util.ProcStopUtil;
 
 public final class fdebuginfo
-{
-    private static CommandlineParser parser;
-
+{    
     /**
      * Entry function for fdebuginfo
-     * 
-     * @param args - pid of the process(es) or corefile
+     * @param args - pid of the process(es)/corefile/executable
      */  
     public static void main(String[] args)
     {
-	// Parse command line. Check if argument provided.
-	parser = new CommandlineParser("fdebuginfo")
-	{
-	    //@Override 
-	    public void parseCores (CoreExePair[] coreExePairs)
-	    {
-		for (int i = 0; i < coreExePairs.length; i++)
-		{       
-		    Proc proc = Util.getProcFromCoreExePair(coreExePairs[i]);
-		    new PrintDebuginfoEvent (proc).execute();
-		}  
-		System.exit(0);  
-	    }
-
-	    //@Override
-	    public void parsePids (ProcId[] pids)
-	    { 
-		for (int i= 0; i< pids.length; i++)
-		{       
-		    Proc proc = Util.getProcFromPid(pids[i]);
-		    new ProcBlockAction(proc, new PrintDebuginfoAction(proc));
-		    Manager.eventLoop.run();
-		}  
-		System.exit(0);
-	    }
-
-	    //@Override
-	    public void parseCommand(String[] command) {
-		File exeFile = new File(command[0]);
-		if (!exeFile.exists() || !exeFile.canRead()
-			|| !exeFile.isFile()) {
-		    System.err.println ("File does not exist or is " +
-		                        "not readable or is not a file.");
-		} else {
-		    Manager.eventLoop.start();
-		    Host exeHost = new LinuxExeHost(Manager.eventLoop, exeFile);
-		    Proc exeProc = Util.getProcFromExeFile(exeHost);
-		    new PrintDebuginfoEvent(exeProc).execute();
-		}
-		System.exit(0);
-	    }
-	};
-
-	parser.setHeader("Usage: fdebuginfo <PID> || fdebuginfo <EXEFILE> " +
-			 "|| fdebuginfo <COREFILE> [<EXEFILE>]");
-	parser.parse(args);
-
-	//Pid not found
-	System.err.println("ERROR: No argument provided");
-	parser.printHelp();
-	System.exit(1);   
+	ProcStopUtil fdebuginfo = new ProcStopUtil("fdebuginfo", args, 
+		                                    new PrintDebuginfoEvent());
+	fdebuginfo.setUsage("Usage: fdebuginfo <PID> || fdebuginfo <EXEFILE> " +
+	                    "|| fdebuginfo <COREFILE> [<EXEFILE>]");   
+        fdebuginfo.execute();
     }   
     
-    private static class PrintDebuginfoEvent implements Event
+    private static class PrintDebuginfoEvent implements ProcEvent
     {
-	private Proc proc = null;
-	
-	public PrintDebuginfoEvent(Proc proc) {
-	    this.proc = proc;
-	}
-
-	public void execute() {
+	public void execute(Proc proc) {
 	    /* Get and print the debuginfo install paths.
 	     */
 	    Task task  = proc.getMainTask();
@@ -137,31 +71,6 @@ public final class fdebuginfo
 	    String dInfo = dbg.getDebuginfo();          
 	    if (dInfo!=null)
 		System.out.print(dInfo); 
-	    System.exit(0);
 	}	
     }
-    
-    private static class PrintDebuginfoAction implements ProcObserver.ProcAction 
-    {
-	private Proc proc;
-
-	public PrintDebuginfoAction(Proc proc) {
-	    this.proc = proc;
-	}
-
-	public void allExistingTasksCompleted() {
-	    Manager.eventLoop.add(new PrintDebuginfoEvent(this.proc));
-	}
-	public void taskAddFailed(Object task, Throwable w) {
-	}
-	public void existingTask(Task task) {
-	}
-	public void addFailed(Object observable, Throwable w) {
-	}
-	public void addedTo(Object observable) {
-	}
-	public void deletedFrom(Object observable) {
-	}
-    }
-}
-
+}
\ No newline at end of file
diff --git a/frysk-core/frysk/event/ChangeLog b/frysk-core/frysk/event/ChangeLog
index 491323f..b1870c2 100644
--- a/frysk-core/frysk/event/ChangeLog
+++ b/frysk-core/frysk/event/ChangeLog
@@ -1,3 +1,7 @@
+2008-02-06  Teresa Thomas  <tthomas@redhat.com>
+
+	* ProcEvent.java: New.
+
 2008-01-23  Andrew Cagney  <cagney@redhat.com>
 
 	* WaitEventLoop.java: Use Signal.toString().
diff --git a/frysk-core/frysk/event/Event.java b/frysk-core/frysk/event/ProcEvent.java
similarity index 93%
copy from frysk-core/frysk/event/Event.java
copy to frysk-core/frysk/event/ProcEvent.java
index 39a25f4..265dc65 100644
--- a/frysk-core/frysk/event/Event.java
+++ b/frysk-core/frysk/event/ProcEvent.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, Red Hat Inc.
+// Copyright 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -39,12 +39,12 @@
 
 package frysk.event;
 
+import frysk.proc.Proc;
+
 /**
- * The event interface.
+ * The proc event interface.
  */
-
-public interface Event
+public interface ProcEvent
 {
-    // Deliver the event to who ever is interested.
-    void execute ();
+    void execute (Proc proc);
 }
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index 668add8..d8d2699 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,7 @@
+2008-02-06  Teresa Thomas  <tthomas@redhat.com>
+
+	* ProcStopUtil.java: New.
+
 2008-02-05  Andrew Cagney  <cagney@redhat.com>
 
 	* X8664LinuxElfCorefile.java: Move to frysk.isa.corefiles.
@@ -11,7 +15,7 @@
 2008-02-04  Tim Moore  <timoore@redhat.com>
 
 	* ObservingTerminal.java: New file.
-
+	
 2008-01-25  Andrew Cagney  <cagney@redhat.com>
 
 	* TestCoredumpAction.java (testElfCoreHeader()): Fetch the ISA
diff --git a/frysk-core/frysk/bindir/fdebuginfo.java b/frysk-core/frysk/util/ProcStopUtil.java
similarity index 59%
copy from frysk-core/frysk/bindir/fdebuginfo.java
copy to frysk-core/frysk/util/ProcStopUtil.java
index 40f3e8f..57a5b5b 100644
--- a/frysk-core/frysk/bindir/fdebuginfo.java
+++ b/frysk-core/frysk/util/ProcStopUtil.java
@@ -1,7 +1,6 @@
-
 //This file is part of the program FRYSK.
 
-//Copyright  2007 Red Hat Inc.
+//Copyright 2008, Red Hat Inc.
 
 //FRYSK is free software; you can redistribute it and/or modify it
 //under the terms of the GNU General Public License as published by
@@ -38,119 +37,135 @@
 //version and license this file solely under the GPL without
 //exception.
 
-package frysk.bindir;
+package frysk.util;
 
 import java.io.File;
 
 import frysk.event.Event;
+import frysk.event.ProcEvent;
+import frysk.proc.dead.LinuxExeHost;
 import frysk.proc.Host;
 import frysk.proc.Manager;
+import frysk.proc.Proc;
 import frysk.proc.ProcBlockAction;
 import frysk.proc.ProcId;
-import frysk.proc.Proc;
 import frysk.proc.ProcObserver;
 import frysk.proc.Task;
-import frysk.proc.dead.LinuxExeHost;
-
 import frysk.util.CommandlineParser;
-import frysk.util.CoreExePair;
 import frysk.util.Util;
-import frysk.util.DebuginfoPaths;
-
-public final class fdebuginfo
+import gnu.classpath.tools.getopt.Option;
+
+/**
+ * Framework to be used for frysk utilities that,
+ * a) Accept pids, executable paths, core files &
+ * b) Require tasks to be stopped,
+ * 
+ * Utilities must define a event.ProcEvent to execute.
+ */
+public class ProcStopUtil
 {
-    private static CommandlineParser parser;
-
-    /**
-     * Entry function for fdebuginfo
-     * 
-     * @param args - pid of the process(es) or corefile
-     */  
-    public static void main(String[] args)
-    {
-	// Parse command line. Check if argument provided.
-	parser = new CommandlineParser("fdebuginfo")
+    private Proc proc;
+    private String[] args;
+    private CommandlineParser parser;
+    
+    public ProcStopUtil (String utilName, String[] args, 
+	                  final ProcEvent procEvent) {
+	this.args = args;
+	parser = new CommandlineParser (utilName) 
 	{
+	    //@Override
+	    public void parsePids (ProcId[] pids)
+	    { 
+		for (int i= 0; i< pids.length; i++)  {                  
+		    proc = Util.getProcFromPid(pids[i]);
+		    failIfProcNull(proc);
+	            UtilEvent utilEvent = new UtilEvent (proc, procEvent);
+		    new ProcBlockAction(proc, new UtilAction(proc, utilEvent));
+		    Manager.eventLoop.run();
+		}
+	    }
+	    
 	    //@Override 
 	    public void parseCores (CoreExePair[] coreExePairs)
 	    {
 		for (int i = 0; i < coreExePairs.length; i++)
 		{       
-		    Proc proc = Util.getProcFromCoreExePair(coreExePairs[i]);
-		    new PrintDebuginfoEvent (proc).execute();
-		}  
-		System.exit(0);  
-	    }
-
-	    //@Override
-	    public void parsePids (ProcId[] pids)
-	    { 
-		for (int i= 0; i< pids.length; i++)
-		{       
-		    Proc proc = Util.getProcFromPid(pids[i]);
-		    new ProcBlockAction(proc, new PrintDebuginfoAction(proc));
-		    Manager.eventLoop.run();
+		    proc = Util.getProcFromCoreExePair(coreExePairs[i]);
+		    failIfProcNull(proc);
+		    procEvent.execute(proc);
 		}  
-		System.exit(0);
 	    }
-
+	    
 	    //@Override
 	    public void parseCommand(String[] command) {
 		File exeFile = new File(command[0]);
 		if (!exeFile.exists() || !exeFile.canRead()
 			|| !exeFile.isFile()) {
 		    System.err.println ("File does not exist or is " +
-		                        "not readable or is not a file.");
+		    "not readable or is not a file.");
+		    System.exit(1);
 		} else {
 		    Manager.eventLoop.start();
 		    Host exeHost = new LinuxExeHost(Manager.eventLoop, exeFile);
-		    Proc exeProc = Util.getProcFromExeFile(exeHost);
-		    new PrintDebuginfoEvent(exeProc).execute();
+		    proc = Util.getProcFromExeFile(exeHost);
+		    failIfProcNull(proc);
+		    procEvent.execute(proc);
 		}
-		System.exit(0);
 	    }
 	};
+    }
 
-	parser.setHeader("Usage: fdebuginfo <PID> || fdebuginfo <EXEFILE> " +
-			 "|| fdebuginfo <COREFILE> [<EXEFILE>]");
+    /**
+     * Use to set the usage of utility.
+     * 
+     * @param usage - String that describes the usage of
+     *                tool.
+     */
+    public void setUsage (String usage) {
+	parser.setHeader(usage);
+    }
+    
+    /**
+     * Use to add options to the utility.
+     * 
+     * @param option - Option object that defines the
+     *                 option.
+     */
+    public void addOption (Option option) {
+	parser.add (option);
+    }
+    
+    public void execute () {
 	parser.parse(args);
 
-	//Pid not found
-	System.err.println("ERROR: No argument provided");
-	parser.printHelp();
-	System.exit(1);   
-    }   
+	// If we got here and args is null, we didn't find a pid.
+	if (args.length < 1) {
+	    System.err.println("ERROR: No argument provided.");
+	    parser.printHelp();
+	}
+    }
     
-    private static class PrintDebuginfoEvent implements Event
-    {
-	private Proc proc = null;
-	
-	public PrintDebuginfoEvent(Proc proc) {
-	    this.proc = proc;
+    private void failIfProcNull (Proc proc) {
+	if (proc == null) {
+	    System.err.println("ERROR: Invalid argument.");
+	    // Exit if no proc found.
+	    System.exit(1);
 	}
-
-	public void execute() {
-	    /* Get and print the debuginfo install paths.
-	     */
-	    Task task  = proc.getMainTask();
-	    DebuginfoPaths dbg = new DebuginfoPaths(task);
-	    String dInfo = dbg.getDebuginfo();          
-	    if (dInfo!=null)
-		System.out.print(dInfo); 
-	    System.exit(0);
-	}	
     }
     
-    private static class PrintDebuginfoAction implements ProcObserver.ProcAction 
+    private static class UtilAction 
+    implements ProcObserver.ProcAction 
     {
-	private Proc proc;
+	protected Proc proc;
+	private Event event;
 
-	public PrintDebuginfoAction(Proc proc) {
+	public UtilAction(Proc proc, Event event) {
 	    this.proc = proc;
+	    this.event = event;
 	}
 
 	public void allExistingTasksCompleted() {
-	    Manager.eventLoop.add(new PrintDebuginfoEvent(this.proc));
+	    Manager.eventLoop.add(event);
 	}
 	public void taskAddFailed(Object task, Throwable w) {
 	}
@@ -163,5 +178,21 @@ public final class fdebuginfo
 	public void deletedFrom(Object observable) {
 	}
     }
-}
-
+    
+    private static class UtilEvent
+    implements Event
+    {
+	private Proc proc = null;
+	private ProcEvent event = null;
+	
+	public UtilEvent(Proc proc, ProcEvent event) {
+	    this.proc = proc;
+	    this.event = event;
+	}
+	
+	public void execute() {
+	    event.execute(proc);
+	    System.exit(0);
+	}
+    }
+}
\ No newline at end of file


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]