public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: swagiaal: added test for fcatch following forks.
@ 2008-02-29 13:39 swagiaal
  0 siblings, 0 replies; only message in thread
From: swagiaal @ 2008-02-29 13:39 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  2b60d77fb3bba566afc5c88022e55a3cfdbfbbd3 (commit)
       via  0b2af9485792c745fa25db1ba8683b8a4db936ad (commit)
      from  d7701802422b53a81f7f3b56c6fbb829fac24a11 (commit)

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

- Log -----------------------------------------------------------------
commit 2b60d77fb3bba566afc5c88022e55a3cfdbfbbd3
Author: Sami Wagiaalla <swagiaal@redhat.com>
Date:   Fri Feb 29 08:35:20 2008 -0500

    swagiaal: added test for fcatch following forks.
    
    frysk-core/frysk/bindir/ChangeLog
    +2008-02-29  Sami Wagiaalla  <swagiaal@redhat.com>
    +
    +	* TestFcatch.java (testFcatchFollowsForks): new test.
    +

commit 0b2af9485792c745fa25db1ba8683b8a4db936ad
Author: Sami Wagiaalla <swagiaal@redhat.com>
Date:   Thu Feb 28 23:52:11 2008 -0500

    swagiaal: implemented used and tested ProcRunningUtil, added ferror.
    
    frysk-core/frysk/bindir/ChangeLog
    +2008-02-28  Sami Wagiaalla  <swagiaal@redhat.com>
    +
    +	* ferror.java: new command line utility.
    +	* ferror.xml: new file.
    +	* TestFerror.java: New test.
    +
    
    frysk-core/frysk/pkglibdir/ChangeLog
    +2008-02-28  Sami Wagiaalla  <swagiaal@lredhat.com>
    +
    +	* funit-3forks.c: New test program.
    +
    
    frysk-core/frysk/util/ChangeLog
    +2008-02-28  Sami Wagiaalla  <swagiaal@redhat.com>
    +
    +	* ProcRunningUtil.java: Framework for all commandline
    +	utilites which keep the process running.
    +

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

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog                  |   10 +
 frysk-core/frysk/bindir/TestFcatch.java            |   14 +
 .../bindir/{TestFhpd.java => TestFerror.java}      |   68 +++--
 frysk-core/frysk/bindir/ferror.java                |   82 ++++++
 frysk-core/frysk/bindir/{fcatch.xml => ferror.xml} |   21 +-
 frysk-core/frysk/pkglibdir/ChangeLog               |    8 +
 .../pkglibdir/{funit-vfork.c => funit-3forks.c}    |   43 ++--
 frysk-core/frysk/util/ChangeLog                    |    5 +
 frysk-core/frysk/util/ProcRunningUtil.java         |  298 ++++++++++++++++++++
 9 files changed, 485 insertions(+), 64 deletions(-)
 copy frysk-core/frysk/bindir/{TestFhpd.java => TestFerror.java} (69%)
 mode change 100755 => 100644
 create mode 100644 frysk-core/frysk/bindir/ferror.java
 copy frysk-core/frysk/bindir/{fcatch.xml => ferror.xml} (86%)
 copy frysk-core/frysk/pkglibdir/{funit-vfork.c => funit-3forks.c} (86%)
 create mode 100644 frysk-core/frysk/util/ProcRunningUtil.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index 087b7af..1ba5299 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,13 @@
+2008-02-29  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* TestFcatch.java (testFcatchFollowsForks): new test.
+
+2008-02-28  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* ferror.java: new command line utility.
+	* ferror.xml: new file.
+	* TestFerror.java: New test.
+
 2008-02-28  Andrew Cagney  <cagney@redhat.com>
 
 	* fcatch.java: Delete unused logger.
diff --git a/frysk-core/frysk/bindir/TestFcatch.java b/frysk-core/frysk/bindir/TestFcatch.java
index 1602173..2d76460 100644
--- a/frysk-core/frysk/bindir/TestFcatch.java
+++ b/frysk-core/frysk/bindir/TestFcatch.java
@@ -53,4 +53,18 @@ public class TestFcatch extends TestLib {
 	// just look for main.
 	e.expect(" in main ");
     }
+    
+    public void testFcatchFollowsForks() {
+	if(unresolved(4536)){
+	    return;
+	}
+	TearDownExpect e = new TearDownExpect(new String[] {
+		Config.getBinFile("fcatch").getAbsolutePath(),
+		Config.getPkgLibFile("funit-3forks").getAbsolutePath()
+	    });
+	// just look for main.
+	e.expect(" in main ");
+    }
+    
+    
 }
diff --git a/frysk-core/frysk/bindir/TestFhpd.java b/frysk-core/frysk/bindir/TestFerror.java
old mode 100755
new mode 100644
similarity index 69%
copy from frysk-core/frysk/bindir/TestFhpd.java
copy to frysk-core/frysk/bindir/TestFerror.java
index f52fe7e..f63fca6
--- a/frysk-core/frysk/bindir/TestFhpd.java
+++ b/frysk-core/frysk/bindir/TestFerror.java
@@ -40,43 +40,47 @@
 package frysk.bindir;
 
 import frysk.Config;
-import frysk.testbed.TestLib;
 import frysk.testbed.TearDownExpect;
+import frysk.testbed.TestLib;
+import frysk.proc.Task;
+import frysk.testbed.SlaveOffspring;
 
-/**
- * This performs a "sniff" test of Fstack, confirming basic
- * functionality of the command line interface.
- *
- * For more specific tests see frysk.hpd.
- */
-
-public class TestFhpd extends TestLib {
-    private final String prompt = "\\(fhpd\\) ";
+public class TestFerror extends TestLib {
 
-    public void testHpdPid () {
-	TearDownExpect child = new TearDownExpect(Config.getPkgLibFile("hpd-c"));
-	TearDownExpect e = new TearDownExpect(new String[] { 
-		Config.getBinFile("fhpd").getPath(), 
-		child.getPid().toString() 
-	    });
-	e.expect("Attached to process.*\n" + prompt);
+    public void testFerrorTracesExecutables () {
+	TearDownExpect e = new TearDownExpect(new String[] {
+		Config.getBinFile("ferror").getAbsolutePath(),
+		"-e",
+		"fork",
+		"--",
+		Config.getPkgLibFile("funit-3forks").getAbsolutePath()});
+	e.expect("Tracing");
+	e.expect(".*main.*");
     }
-  
-    public void testHpdCommand () {
-	TearDownExpect e = new TearDownExpect(new String[] { 
-		Config.getBinFile("fhpd").getPath(), 
-		Config.getPkgLibFile("hpd-c").getPath() 
-	    });
-	e.expect("Loaded executable file.*" + prompt);
+
+    public void testFerrorTracesPID () {
+	SlaveOffspring child = SlaveOffspring.createChild();
+	Task task = child.findTaskUsingRefresh(true);
+	TearDownExpect e = new TearDownExpect(new String[] {
+		Config.getBinFile("ferror").getAbsolutePath(),
+		"-e",
+		"clone",
+		"--",
+		Integer.toString(task.getProc().getPid())});
+	e.expect("Tracing");
+	child.assertSendAddCloneWaitForAcks();
+	e.expect(".*main.*");
     }
-  
-    public void testHpdCore ()  {
+
+    public void testFerrorFollowsForks() {
 	TearDownExpect e = new TearDownExpect(new String[] {
-		Config.getBinFile("fhpd").getPath(),
-		Config.getPkgDataFile("test-core-x86").getPath(),
-		"-noexe"
-	    });
-	e.expect("Attached to core file.*");
+		Config.getBinFile("ferror").getAbsolutePath(),
+		"-e",
+		"fork3",
+		"--",
+		Config.getPkgLibFile("funit-3forks").getAbsolutePath()});
+	e.expect("Tracing");
+	e.expect(".*main.*");
     }
-    
+
 }
diff --git a/frysk-core/frysk/bindir/ferror.java b/frysk-core/frysk/bindir/ferror.java
new file mode 100644
index 0000000..52906bc
--- /dev/null
+++ b/frysk-core/frysk/bindir/ferror.java
@@ -0,0 +1,82 @@
+package frysk.bindir;
+
+import frysk.debuginfo.DebugInfoStackFactory;
+import frysk.debuginfo.PrintStackOptions;
+import frysk.isa.syscalls.Syscall;
+import frysk.proc.Action;
+import frysk.proc.Task;
+import frysk.proc.TaskObserver;
+import frysk.proc.TaskObserver.Syscalls;
+import frysk.util.ProcRunningUtil;
+import gnu.classpath.tools.getopt.Option;
+import gnu.classpath.tools.getopt.OptionException;
+
+import java.io.PrintWriter;
+
+public class ferror {
+    
+    static final PrintWriter printWriter = new PrintWriter(System.out);
+    
+    private static String errorString;
+    public static void main (String[] args)
+    {
+       Option option = new Option('e', "--error", "error string to catch in double quotes -e \"<error string>\""){
+
+	public void parsed(String argument) throws OptionException {
+	    errorString = argument;
+	}  
+       };
+	
+       ProcRunningUtil procRunningUtil = 
+	   new ProcRunningUtil("ferror",
+		   "ferror -e \"<error string>\" -- <executbale|PID> [ARGS]",
+		   args, 
+		   new TaskObserver[]{syscallObserver},new Option[]{option} , ProcRunningUtil.DEFAULT);
+       procRunningUtil.start();
+    }
+
+    
+    static Syscalls syscallObserver = new Syscalls(){
+
+      public Action updateSyscallExit (Task task)
+      {
+        return Action.CONTINUE;
+      }
+
+      public void addFailed (Object observable, Throwable w){}
+      public void addedTo (Object observable){
+	  Task task = (Task) observable;
+	  printWriter.println("Tracing " + task.getProc().getPid() + "." + task.getTid());
+	  printWriter.flush();
+      }
+      public void deletedFrom (Object observable){}
+
+      public Action updateSyscallEnter(Task task, Syscall syscall) {
+  	if(syscall.getName().equals("write")){
+  	        long address = syscall.getArguments(task, 2);
+  	        
+  	        StringBuffer x = new StringBuffer ();
+  	        task.getMemory().get (address, 200, x);
+  	        String xString = new String(x);
+  	        
+  	        if(xString.contains(errorString)){
+  	          printWriter.println("Process is trying to output " + errorString);
+  	          
+  	          printWriter.println("Stack trace:\n");
+  	          PrintStackOptions options = new PrintStackOptions();
+
+  	          options.setPrintFullpath(false);
+  	          options.setPrintParameters(true);
+  	          options.setPrintVirtualFrames(true);
+  	          options.setPrintLibrary(true);
+
+  	          DebugInfoStackFactory.printTaskStackTrace(printWriter, task, options);
+  	          
+  	        }
+  	        
+  	      }
+  	      return Action.CONTINUE;
+      }
+      
+    };
+}
diff --git a/frysk-core/frysk/bindir/fcatch.xml b/frysk-core/frysk/bindir/ferror.xml
similarity index 86%
copy from frysk-core/frysk/bindir/fcatch.xml
copy to frysk-core/frysk/bindir/ferror.xml
index 9e5e027..a1c43e9 100644
--- a/frysk-core/frysk/bindir/fcatch.xml
+++ b/frysk-core/frysk/bindir/ferror.xml
@@ -48,26 +48,26 @@
 
 <!-- http://docbook.sourceforge.net/snapshots/xsl/manpages/README -->
 
-<refentry id="fcatch">
+<refentry id="ferror">
 
   <refentryinfo>
-    <title>fcatch</title>
-    <date>December 22 2006</date>
+    <title>ferror</title>
+    <date>Feb 28 2008</date>
   </refentryinfo>
   
   <refmeta>
-    <refentrytitle>fcatch</refentrytitle>
+    <refentrytitle>ferror</refentrytitle>
     <manvolnum>1</manvolnum>
   </refmeta>
 
   <refnamediv>
-    <refname>fcatch</refname>
-    <refpurpose>Runs the frysk application crash and signal stack tracing utility</refpurpose>
+    <refname>ferror</refname>
+    <refpurpose> print stack trace when the given error is printed by the traced program</refpurpose>
   </refnamediv>
   
   <refsynopsisdiv>
     <cmdsynopsis>
-      <command>fcatch [OPTIONS] -- PATH ARGS</command>
+      <command>ferror -e "ERROR" -- [EXECUTABLE|PID] [ARGS]</command>
       <!-- arg choice="opt">
         <option>-list of options</option>
       </arg -->
@@ -77,9 +77,7 @@
   <refsect1>
     <title>DESCRIPTION</title>
 
-    <para><function>fcatch</function> Runs the frysk application crash stack tracing utility</para>
-
-    <para>fcatch is a small utility that uses the frysk engine to generate stack backtraces from an application crash, or upon receiving a variety of signals.</para>
+    <para><function>ferror</function> Using the Frysk back end it runs an application and waits for the process to output the given error string, then produces a stack trace at that point</para>
 
     <!-- variablelist>
       <varlistentry>
@@ -115,8 +113,7 @@
   
   <refsect1>
     <title>EXAMPLE</title>
-    <screen>fcatch /usr/bin/foo</screen>
-    <screen>fcatch -p [PID]</screen>
+    <screen>ferror -e "No such file or directory" -- ls fake</screen>
   </refsect1>
    
   <!-- refsect1>
diff --git a/frysk-core/frysk/pkglibdir/ChangeLog b/frysk-core/frysk/pkglibdir/ChangeLog
index 0960eaa..0d85a8b 100644
--- a/frysk-core/frysk/pkglibdir/ChangeLog
+++ b/frysk-core/frysk/pkglibdir/ChangeLog
@@ -1,3 +1,11 @@
+2008-02-29  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* funit-3forks.c: The last fork sigfaults.
+
+2008-02-28  Sami Wagiaalla  <swagiaal@lredhat.com>
+
+	* funit-3forks.c: New test program.
+
 2008-02-19  Stan Cox  <scox@redhat.com>
 
 	* funit-type-class.cxx (class_accessibility): New.
diff --git a/frysk-core/frysk/pkglibdir/funit-vfork.c b/frysk-core/frysk/pkglibdir/funit-3forks.c
similarity index 86%
copy from frysk-core/frysk/pkglibdir/funit-vfork.c
copy to frysk-core/frysk/pkglibdir/funit-3forks.c
index d40b923..29619ae 100644
--- a/frysk-core/frysk/pkglibdir/funit-vfork.c
+++ b/frysk-core/frysk/pkglibdir/funit-3forks.c
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007 Red Hat Inc.
+// Copyright 2005, 2006, 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
@@ -36,31 +36,34 @@
 // modification, you must delete this exception statement from your
 // version and license this file solely under the GPL without
 // exception.
+/* Use processes to compute a Fibonacci number.  */
 
-#include <sys/types.h>
-#include <sys/wait.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
+#include <sys/wait.h>
+#include <sys/types.h>
 #include <unistd.h>
 
-int
-main(void)
+int main ()
 {
-  pid_t pid = vfork();
-  if (pid == -1)
-    {
-      perror ("vfork");
-      exit (1);
-    }
-  else if (pid == 0)
-    {
-      puts ("child");
-      _exit (1);
-    }
-  else
-    {
-      waitpid (pid, NULL, 0);
-      puts ("child done");
+  printf ("fork1\n");
+  int i = fork();
+  
+  if(i == 0){
+    printf ("fork2\n");
+    i = fork();
+
+    if(i == 0){
+      printf ("fork3\n");
+      i = fork();
+
+      if(i == 0){
+	int* a= 0;
+	a[0] = 0;
+      }
+      
     }
+  }
   return 0;
 }
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index f6f97ac..b7ef1d7 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-28  Sami Wagiaalla  <swagiaal@redhat.com>
+
+	* ProcRunningUtil.java: Framework for all commandline
+	utilites which keep the process running.
+
 2008-02-28  Andrew Cagney  <cagney@redhat.com>
 
 	* FCatch.java: Use frysk.rsl.
diff --git a/frysk-core/frysk/util/ProcRunningUtil.java b/frysk-core/frysk/util/ProcRunningUtil.java
new file mode 100644
index 0000000..c775544
--- /dev/null
+++ b/frysk-core/frysk/util/ProcRunningUtil.java
@@ -0,0 +1,298 @@
+// This file is part of the program FRYSK.
+//
+// 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
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.util;
+
+import java.util.ArrayList;
+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.TaskObserver.Attached;
+import frysk.proc.TaskObserver.Cloned;
+import frysk.proc.TaskObserver.Execed;
+import frysk.proc.TaskObserver.Forked;
+import frysk.proc.TaskObserver.Instruction;
+import frysk.proc.TaskObserver.Signaled;
+import frysk.proc.TaskObserver.Syscalls;
+import frysk.proc.TaskObserver.Terminated;
+import frysk.proc.TaskObserver.Terminating;
+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 ProcRunningUtil {
+
+    ForkedObserver forkedObserver = new ForkedObserver();
+
+    AttachedObserver attachedObserver = new AttachedObserver();
+
+    private RunningUtilOptions options;
+    private TaskObserver[] observers;
+
+    public static class RunningUtilOptions {
+	boolean followForks = true;
+    }
+    
+    public static final RunningUtilOptions DEFAULT = new RunningUtilOptions();
+    
+    public ProcRunningUtil(String utilName, String usage, String[] args,
+	    TaskObserver[] observers, Option[] customOptions,
+	    RunningUtilOptions options) {
+
+	this.options = options;
+	this.observers = observers;
+
+	//Set up commandline parser
+	CommandlineParser parser = new CommandlineParser(utilName) {
+	    // @Override
+	    public void parsePids(Proc[] procs) {
+		for (int i = 0; i < procs.length; i++) {
+		    addObservers(procs[i]);
+		}
+	    }
+
+	    // @Override
+	    public void parseCommand(Proc command) {
+
+		//Exctact arguments and executable from give Proc object
+		ArrayList commandAndArguments;
+		String[] line = command.getCmdLine();
+		commandAndArguments = new ArrayList();
+		for (int i = 0; i < line.length; i++){
+		    commandAndArguments.add(line[i]);
+		}
+		
+		//Create a live process using the extracted command.
+		// attachedObserver will handle adding of the remaining
+		// observers.
+		Manager.host.requestCreateAttachedProc(


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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-29 13:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-29 13:39 [SCM] master: swagiaal: added test for fcatch following forks swagiaal

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).