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: Add GenerateCoreCommand and tests.


The branch, master has been updated
       via  055478076287a6987a66166bb9d9ebe40ff0e012 (commit)
      from  9feb25bcf5110af8f27e0125b6fa1bcc3fd10577 (commit)

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

- Log -----------------------------------------------------------------
commit 055478076287a6987a66166bb9d9ebe40ff0e012
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Fri Jan 11 18:33:05 2008 +0000

    Add GenerateCoreCommand and tests.
    
    2008-01-11  Phil Muldoon  <pmuldoon@redhat.com>
    
            * TopLevelCommand.java (TopLevelCommand): Add dump command.
            * GenerateCoreCommand.java: New.
            * TestGenerareCoreCommand.java: New.
    
    2008-01-11  Phil Muldoon  <pmuldoon@redhat.com>
    
            * DeadProc.java (DeadProc): Make public.
            * LinuxCoreProc.java (constructEnhancedMapMetadata): Check that
            linkmap address != 0.

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

Summary of changes:
 frysk-core/frysk/hpd/ChangeLog                     |    6 +
 .../{LoadCommand.java => GenerateCoreCommand.java} |  123 ++++++++++-------
 frysk-core/frysk/hpd/TestGenerateCoreCommand.java  |  145 ++++++++++++++++++++
 frysk-core/frysk/hpd/TopLevelCommand.java          |    2 +-
 frysk-core/frysk/proc/dead/ChangeLog               |    6 +
 frysk-core/frysk/proc/dead/DeadProc.java           |    2 +-
 frysk-core/frysk/proc/dead/LinuxCoreProc.java      |    3 +
 7 files changed, 233 insertions(+), 54 deletions(-)
 copy frysk-core/frysk/hpd/{LoadCommand.java => GenerateCoreCommand.java} (52%)
 create mode 100644 frysk-core/frysk/hpd/TestGenerateCoreCommand.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 8adafc8..dae538f 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,9 @@
+2008-01-11  Phil Muldoon  <pmuldoon@redhat.com>
+
+	* TopLevelCommand.java (TopLevelCommand): Add dump command.
+	* GenerateCoreCommand.java: New.
+	* TestGenerareCoreCommand.java: New. 
+
 2008-01-10  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* ParameterizedCommand.java (help): Print help if longCommands >0 ! >1.
diff --git a/frysk-core/frysk/hpd/LoadCommand.java b/frysk-core/frysk/hpd/GenerateCoreCommand.java
similarity index 52%
copy from frysk-core/frysk/hpd/LoadCommand.java
copy to frysk-core/frysk/hpd/GenerateCoreCommand.java
index b330da9..1f5016c 100644
--- a/frysk-core/frysk/hpd/LoadCommand.java
+++ b/frysk-core/frysk/hpd/GenerateCoreCommand.java
@@ -1,6 +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,68 +40,87 @@
 package frysk.hpd;
 
 import java.io.File;
+import java.util.HashMap;
 import java.util.Iterator;
-import frysk.debuginfo.DebugInfo;
-import frysk.debuginfo.DebugInfoFrame;
-import frysk.debuginfo.DebugInfoStackFactory;
-import frysk.proc.Host;
-import frysk.proc.dead.LinuxExeHost;
-import frysk.proc.Manager;
+import java.util.List;
+
 import frysk.proc.Proc;
 import frysk.proc.Task;
-import java.util.List;
+import frysk.proc.dead.DeadProc;
+import frysk.util.LinuxElfCorefile;
+import frysk.util.LinuxElfCorefileFactory;
 
-/**
- * LoadCommand handles the "load path-to-executable" command on the fhpd
- * commandline.
- *
- */
+public class GenerateCoreCommand extends ParameterizedCommand {
 
-public class LoadCommand extends ParameterizedCommand {
+    	String corefileName = "core";
+	LinuxElfCorefile coreFile = null;
 
-    LoadCommand() {
-	super("load", "load path-to-executable", "load an executable file");
-    }
+	File exeFile = null;
 
-    public void interpret(CLI cli, Input cmd, Object options) {
-	if (cmd.size() > 2) {
-	    throw new InvalidCommandException("Too many parameters");
-	} else if (cmd.size() < 1) {
-            throw new InvalidCommandException("missing arguments");
-        }
-        
-	File executableFile = new File(cmd.parameter(0));
-
-	if (!executableFile.exists() || !executableFile.canRead()
-		|| !executableFile.isFile()) {
-	    throw new InvalidCommandException
-		("File does not exist or is not readable or is not a file.");
+	boolean writeAllMaps = false;
+
+	GenerateCoreCommand() {
+		super("Generate a Corefile.", "dump [ -a ]",
+				"Generates and writes a corefile");
+
+		add(new CommandOption("a", "Write all segments, do not elide.") {
+			void parse(String argument, Object options) {
+				writeAllMaps = true;
+			}
+		});
+
+		add(new CommandOption("o", "Optional corefile name", "name") {
+			void parse(String argument, Object options) {
+				corefileName = argument;
+			}
+		});
 	}
 
-	Host exeHost = new LinuxExeHost(Manager.eventLoop, executableFile);
-	Proc exeProc = frysk.util.Util.getProcFromExeFile(exeHost);
-	
-	int procID = cli.idManager.reserveProcID();
-	cli.idManager.manageProc(exeProc, procID);
-	
-	Iterator foo = cli.targetset.getTasks();
-	while (foo.hasNext()) {
-	    Task task = (Task) foo.next();
-	    if (task.getTid() == exeProc.getMainTask().getTid()) {
-		DebugInfoFrame frame = DebugInfoStackFactory
-			.createDebugInfoStackTrace(task);
-		cli.setTaskFrame(task, frame);
-		cli.setTaskDebugInfo(task, new DebugInfo(
-			frame));
+	void interpret(CLI cli, Input cmd, Object options) {
+	    
+	    int processCount = 0;
+	    HashMap procList = new HashMap();
+	    PTSet ptset = cli.getCommandPTSet(cmd);
+	    Iterator taskDataIterator = ptset.getTaskData();
+	    if (taskDataIterator.hasNext() == false) {
+		cli.addMessage("Cannot find main task. Cannot print out create core.", 
+				Message.TYPE_ERROR);
+		return;
+	    }
+
+	    
+	    while (taskDataIterator.hasNext()) {
+		
+		Proc proc = ((TaskData) taskDataIterator.next()).getTask().getProc();
+		if (!procList.containsValue(proc)) {
+		    procList.put(proc,proc);
+		    processCount++;
+		}
+	    }
+
+	    Iterator procIterator = procList.values().iterator();
+
+	    while (procIterator.hasNext()) {
+
+		Proc mainProc = ((Proc)procIterator.next());
+		if (mainProc instanceof DeadProc) {
+		    cli.addMessage("Process has to be alive (not core or not started) to dump core.", Message.TYPE_WARNING);
+		    continue;
+		}
+		cli.addMessage("Generating corefile '"+corefileName+"."+
+				mainProc.getPid()+"' for process: " + 
+				mainProc.getPid(), Message.TYPE_NORMAL);
+		Task[] tasks = (Task[]) mainProc.getTasks().toArray(new Task[mainProc.getTasks().size()]);
+		coreFile = LinuxElfCorefileFactory.getCorefile(mainProc, tasks);
+		
+		if (writeAllMaps)
+		    coreFile.setWriteAllMaps(true);
+		
+		coreFile.setName(corefileName);
+		
+		coreFile.constructCorefile();
 	    }
 	}
-	synchronized (cli) {
-	    cli.getLoadedProcs().put(exeProc, new Integer(procID));
-	}
-    
-    cli.addMessage("Loaded executable file: " + cmd.parameter(0),
-		Message.TYPE_NORMAL);
-    }
 
     int completer(CLI cli, Input input, int cursor, List completions) {
 	return CompletionFactory.completeFileName(cli, input, cursor,
diff --git a/frysk-core/frysk/hpd/TestGenerateCoreCommand.java b/frysk-core/frysk/hpd/TestGenerateCoreCommand.java
new file mode 100644
index 0000000..c7ebb7f
--- /dev/null
+++ b/frysk-core/frysk/hpd/TestGenerateCoreCommand.java
@@ -0,0 +1,145 @@
+// 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.hpd;
+
+import frysk.expunit.EndOfFileException;
+import frysk.expunit.Match;
+import frysk.expunit.Regex;
+import frysk.expunit.TimeoutException;
+import frysk.junit.TestCase;
+import frysk.testbed.TearDownFile;
+
+/**
+ * This class tests the "load" command basics of both loading a correct
+ * executable and trying to load a non-existent executable.
+ */
+
+public class TestGenerateCoreCommand extends TestLib {
+
+    
+    public void testGenerateCoreCommand() {
+	HpdTestbed h = HpdTestbed.start("funit-hello");
+	h.send("dump\n");
+	try {
+	    h.expect(new Match[] {
+			 new Regex("Generating corefile 'core.([0-9]+)") {
+			     public void execute() {
+				 int pid = Integer.parseInt(group(1));
+				 TearDownFile core = new TearDownFile("core."+pid);
+				 core.getClass();
+			     }
+			 }
+		     });
+	} catch (EndOfFileException e) {
+	    TestCase.fail("Expecting: Generating corefile ... got: <EOF>");
+	} catch (TimeoutException t) {
+	    TestCase.fail("Expecting: Generating corefile ... got: <TIMEOUT>");
+	}
+
+	h.close();
+    }
+
+    public void testGenerateCoreAllMapsCommand() {
+	HpdTestbed h = HpdTestbed.start("funit-hello");
+	h.send("dump -a\n");
+	try {
+	    h.expect(new Match[] {
+			 new Regex("Generating corefile 'core.([0-9]+)") {
+			     public void execute() {
+				 int pid = Integer.parseInt(group(1));
+				 TearDownFile core = new TearDownFile("core."+pid);
+				 core.getClass();
+			     }
+			 }
+		     });
+	} catch (EndOfFileException e) {
+	    TestCase.fail("Expecting: Generating corefile ... got: <EOF>");
+	} catch (TimeoutException t) {
+	    TestCase.fail("Expecting: Generating corefile ... got: <TIMEOUT>");
+	}
+
+	h.close();
+    }
+
+    public void testGenerateRenamedCoreCommand() {
+	HpdTestbed h = HpdTestbed.start("funit-hello", "1");
+	h.send("dump -o testname\n");
+	try {
+	    h.expect(new Match[] {
+			 new Regex("Generating corefile 'testname.([0-9]+)") {
+			     public void execute() {
+				 int pid = Integer.parseInt(group(1));
+				 TearDownFile core = new TearDownFile("testname."+pid);
+				 core.getClass();
+			     }
+			 }
+		     });
+	} catch (EndOfFileException e) {
+	    TestCase.fail("Expecting: Generating corefile ... got: <EOF>");
+	} catch (TimeoutException t) {
+	    TestCase.fail("Expecting: Generating corefile ... got: <TIMEOUT>");
+	}
+
+	h.close();
+    }
+
+    public void testGenerateRenamedAllMapsCoreCommand() {
+	HpdTestbed h = HpdTestbed.start("funit-fib-clone", "1");
+	h.send("dump -a -o testname\n");
+	try {
+	    h.expect(new Match[] {
+			 new Regex("Generating corefile 'testname.([0-9]+)") {
+			     public void execute() {
+				 int pid = Integer.parseInt(group(1));
+				 TearDownFile core = new TearDownFile("testname."+pid);
+				 core.getClass();
+			     }
+			 }
+		     });
+	} catch (EndOfFileException e) {
+	    TestCase.fail("Expecting: Generating corefile ... got: <EOF>");
+	} catch (TimeoutException t) {
+	    TestCase.fail("Expecting: Generating corefile ... got: <TIMEOUT>");
+	}
+
+	h.close();
+    }
+
+}
diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java
index 009ec4c..af6e2b4 100644
--- a/frysk-core/frysk/hpd/TopLevelCommand.java
+++ b/frysk-core/frysk/hpd/TopLevelCommand.java
@@ -82,6 +82,7 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new AttachCommand(), "attach");
         add(new BreakpointCommand(), "b|reak");
         add(new CoreCommand(), "core");
+        add(new GenerateCoreCommand(), "dump");
         add(new DbgVariableCommands.Set(), "set");
         add(new DbgVariableCommands.Unset(), "unset");
         add(new DetachCommand(), "detach");
@@ -114,7 +115,6 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new StepNextCommand(), "n|ext");
         add(new StepNextiCommand(), "nexti");
         add(new WhatCommand(), "what");
-
         add(new WhichsetsCommand(), "whichsets");
         add(new ViewsetCommand(), "viewset");
         add(new DefsetCommand(), "defset");
diff --git a/frysk-core/frysk/proc/dead/ChangeLog b/frysk-core/frysk/proc/dead/ChangeLog
index 1b27dda..8d0ed30 100644
--- a/frysk-core/frysk/proc/dead/ChangeLog
+++ b/frysk-core/frysk/proc/dead/ChangeLog
@@ -1,3 +1,9 @@
+2008-01-11  Phil Muldoon  <pmuldoon@redhat.com>
+
+	* DeadProc.java (DeadProc): Make public.
+	* LinuxCoreProc.java (constructEnhancedMapMetadata): Check that
+	linkmap address != 0.
+
 2008-01-07  Andrew Cagney  <cagney@redhat.com>
 
 	* LinuxCoreHost.java (sendRefresh(ProcId,FindProc)): Delete.
diff --git a/frysk-core/frysk/proc/dead/DeadProc.java b/frysk-core/frysk/proc/dead/DeadProc.java
index cf0b24b..3e8c373 100644
--- a/frysk-core/frysk/proc/dead/DeadProc.java
+++ b/frysk-core/frysk/proc/dead/DeadProc.java
@@ -52,7 +52,7 @@ import frysk.proc.ProcEvent;
  * observers.
  */
 
-abstract class DeadProc extends Proc {
+public abstract class DeadProc extends Proc {
     DeadProc(Host host, Proc parent, ProcId id) {
 	super(host, parent, id);
     }
diff --git a/frysk-core/frysk/proc/dead/LinuxCoreProc.java b/frysk-core/frysk/proc/dead/LinuxCoreProc.java
index ca66266..039490c 100644
--- a/frysk-core/frysk/proc/dead/LinuxCoreProc.java
+++ b/frysk-core/frysk/proc/dead/LinuxCoreProc.java
@@ -359,6 +359,9 @@ public class LinuxCoreProc extends DeadProc {
 	// From that segment address, find linkmap table.
 	long linkmapAddress = getLinkmapAddress(dynamicTuple);
 
+	// No link map = no libraries loaded (core at entry point)
+	if (linkmapAddress == 0)
+	    return basicMetaData;
 
 	// Edge case: Save interp name as it is not included the linkmap
 	// as it is loaded by the kernel.


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]