This is the mail archive of the frysk@sourceware.org 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]

Patch: Implement Info Command


This patch implements a new Multi Level Command called: 'info' into fhpd. This new multi level command attempts to group all the 'information-providing' commands into one command-group. This is so the main top-level command's help does not get unwieldy. The commands auxv, maps and debuginfo registrations have been moved into info command. The regs command registration has been duplicated into info command due to the hpd specifying the regs command should also be a top-level command.

Usage Scenarios:

Usage: info help - will print out all the information sub-commands that info knows about.

Usage: info help <sub-command> - will print out the sub-command's help. E.g. info help regs

Usage: info <sub-command> -help. Same as above. E.g. info regs -help

Usage: info <sub-command> - will execute the sub-command. E.g. info auxv.


Class usage:


To add commands to 'info', simple edit the InfoCommand.java as show in the patch, or call the .add() function.

Known bugs:

An unsolved issue is that info -help does not parse the -help correctly and identifies it as a command. Extending ParameterizedCommand instead of Command leads to the InfoCommand cannibalizing command options that the sub-command should process.

Regards

Phil
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 789cd32..3dfa4e7 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,17 @@
+2007-12-20  Phil Muldoon  <pmuldoon@redhat.com>
+
+	* InfoCommand.java: New. Add auxv, maps, debuginfo.
+	* TopLevelCommand.java(TopLevelCommand): Add InfoCommand.
+	Remove auxv, maps, debuginfo.
+	* TestRegs.java (testRegsCommand): Add 'info regs'
+	to test.	
+	* TestMapsCommand.java (testMapsCommand): Send 'info maps'
+	to expect instead of 'maps'.
+	* TestAuxvCommand.java (testAuxVCoreCommand): Send 'info auxv'
+	to expect instead of 'auxv'.
+	* TestHelp.java (TestHelp): Remove debuginfo, add
+	info to array.
+
 2007-12-18  Rick Moseley  <rmoseley@redhat.com>
 
 	* TestLoadCommand.java: Fix regex symbols.
diff --git a/frysk-core/frysk/hpd/InfoCommand.java b/frysk-core/frysk/hpd/InfoCommand.java
new file mode 100644
index 0000000..d8529cd
--- /dev/null
+++ b/frysk-core/frysk/hpd/InfoCommand.java
@@ -0,0 +1,76 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2007, 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 java.util.List;
+
+public class InfoCommand extends MultiLevelCommand {
+    
+    private class Help extends Command {
+    	Help() {
+    	    super("Display this help message.", "help [command]",
+    		  "Display help (possibly for a command.)");
+    	}
+    	
+    	public void interpret(CLI cli, Input cmd) {
+    	    InfoCommand.this.help(cli, cmd);
+    	}
+    	
+    	/**
+    	 * Complete the line, throw problem back at the top level
+    	 * command.
+    	 */
+    	int complete(CLI cli, Input buffer, int cursor, List candidates) {
+    	    return InfoCommand.this.complete(cli, buffer, cursor,
+					     candidates);
+    	}
+    }
+    
+    
+    InfoCommand() {
+	super("info command", "info <subcommand>", 
+	      "The info command displays useful information about " +
+	      "various system and process level systems.");
+        add(new Help(), "help");
+    	add(new RegsCommand(),"regs");
+    	add(new DebuginfoCommand(),"debuginfo");
+    	add(new MapsCommand(),"maps");
+    	add(new AuxvCommand(),"auxv");
+    }
+}
diff --git a/frysk-core/frysk/hpd/TestAuxvCommand.java b/frysk-core/frysk/hpd/TestAuxvCommand.java
index 3b566b7..8434d36 100644
--- a/frysk-core/frysk/hpd/TestAuxvCommand.java
+++ b/frysk-core/frysk/hpd/TestAuxvCommand.java
@@ -75,7 +75,7 @@ public class TestAuxvCommand extends TestLib {
     e.send("core " + core.getPath()
 	   + " -noexe\n");
     e.expect("Attached to core file.*");
-    e.send("auxv\n");
+    e.send("info auxv\n");
     Iterator i = buildAuxv.auxvData.iterator();
     while (i.hasNext())
       e.equals((String)i.next());
diff --git a/frysk-core/frysk/hpd/TestHelp.java b/frysk-core/frysk/hpd/TestHelp.java
index fd34afe..cb9414d 100644
--- a/frysk-core/frysk/hpd/TestHelp.java
+++ b/frysk-core/frysk/hpd/TestHelp.java
@@ -56,7 +56,6 @@ public class TestHelp
 	"attach",
 	"break",
 	"core",
-	"debuginfo",
 	"defset",
 	"delete",
 	"detach",
@@ -72,6 +71,7 @@ public class TestHelp
 	"go",
 	"halt",
 	"help",
+	"info",
 	"list",
 	"load",
 	"next",
diff --git a/frysk-core/frysk/hpd/TestMapsCommand.java b/frysk-core/frysk/hpd/TestMapsCommand.java
index 51380af..3ac9e70 100644
--- a/frysk-core/frysk/hpd/TestMapsCommand.java
+++ b/frysk-core/frysk/hpd/TestMapsCommand.java
@@ -52,7 +52,7 @@ public class TestMapsCommand extends TestLib {
         
     e = new HpdTestbed();
     e.send("attach " + proc.getPid() +"\n");
-    e.send("maps\n");
+    e.send("info maps\n");
     for (int i=0; i< liveMaps.length; i++)
       e.equals(liveMaps[i].toString());
     e.close();
diff --git a/frysk-core/frysk/hpd/TestRegs.java b/frysk-core/frysk/hpd/TestRegs.java
index c3e90c2..46add1d 100644
--- a/frysk-core/frysk/hpd/TestRegs.java
+++ b/frysk-core/frysk/hpd/TestRegs.java
@@ -51,20 +51,23 @@ public class TestRegs extends TestLib {
 	File exe = Config.getPkgLibFile("hpd-c");
 	ISA isa = ElfMap.getISA(exe);
 
+	String[] commandSet = {"regs\n", "info regs\n"};
 	// Regs
-	e.send("regs\n");
-
-	// Match the first register (with two values) and the last
-	// register.
-	if (isa == ISA.IA32)
-	    e.expectPrompt("eax:\t[0-9][^\t]*\t0x.*esp:.*");
-	else if (isa == ISA.X8664)
-	    e.expectPrompt("rax:\t[0-9][^\t]*\t0x.*rip:.*");
-	else
-	    fail("Architecture " + isa + " unhandled");
+	for (int i=0; i < commandSet.length; i++) {
+	    e.send(commandSet[i]);
+	    
+	    // Match the first register (with two values) and the last
+	    // register.
+	    if (isa == ISA.IA32)
+		e.expectPrompt("eax:\t[0-9][^\t]*\t0x.*esp:.*");
+	    else if (isa == ISA.X8664)
+		e.expectPrompt("rax:\t[0-9][^\t]*\t0x.*rip:.*");
+	    else
+		fail("Architecture " + isa + " unhandled");
+	}
 	e.close();
     }
-
+    
     public void testRegsBlah() {
 	e = HpdTestbed.attachXXX("hpd-c");
 	e.sendCommandExpectPrompt("regs blah",
diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java
index f85e691..009ec4c 100644
--- a/frysk-core/frysk/hpd/TopLevelCommand.java
+++ b/frysk-core/frysk/hpd/TopLevelCommand.java
@@ -80,12 +80,10 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new AliasCommands.Alias(), "alias");
         add(new AliasCommands.Unalias(), "unalias");
         add(new AttachCommand(), "attach");
-        add(new AuxvCommand(), "auxv");
         add(new BreakpointCommand(), "b|reak");
         add(new CoreCommand(), "core");
         add(new DbgVariableCommands.Set(), "set");
         add(new DbgVariableCommands.Unset(), "unset");
-        add(new DebuginfoCommand(), "debuginfo");
         add(new DetachCommand(), "detach");
         add(new DisassembleCommand(), "disassemble");
         add(new DisplayCommand(), "display");
@@ -95,10 +93,10 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new GoCommand(), "g|o");
         add(new HaltCommand(), "h|alt");
         add(new Help(), "help");
+        add(new InfoCommand(), "info");
         add(new KillCommand(), "k|ill");
         add(new ListCommand(), "l|ist");
         add(new LoadCommand(), "load");
-        add(new MapsCommand(), "maps");
         add(new PeekCommand(), "peek");
 	Command quit = new QuitCommand();
         add(quit, "exit");

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