[SCM] master: Eliminate call to CLI.printUsage in FocusCommand.

cagney@sourceware.org cagney@sourceware.org
Fri Nov 9 01:22:00 GMT 2007


The branch, master has been updated
       via  56fdb833280afc1291dc06a9a393f825bead5d06 (commit)
       via  d6ea34b1e8d84d5a00f56a2a2a53192bc13ed82d (commit)
       via  309eec77f9ee936fe2139ed010c9f6b258393c5a (commit)
       via  1616ff612ae89cf4f062d1e5b103bf7a5807255a (commit)
      from  d9bd1560c585138ab990d7ad0b65b3d9e6ad8ce1 (commit)

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

- Log -----------------------------------------------------------------
commit 56fdb833280afc1291dc06a9a393f825bead5d06
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Nov 8 19:19:00 2007 -0500

    Eliminate call to CLI.printUsage in FocusCommand.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-08  Andrew Cagney  <cagney@redhat.com>
    
    	* FocusCommand.java: Eliminate call to CLI.printUsage.

commit d6ea34b1e8d84d5a00f56a2a2a53192bc13ed82d
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Nov 8 19:04:43 2007 -0500

    Refactor viewset and whichsets to extend ParameterizedCommand.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-08  Andrew Cagney  <cagney@redhat.com>
    
    	* ViewsetCommand.java: Extend ParameterizedCommand.
    	* WhichsetsCommand.java: Eliminate call to CLI.printUsage.

commit 309eec77f9ee936fe2139ed010c9f6b258393c5a
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Nov 8 18:32:08 2007 -0500

    Clean up plocation, ptype, defset, frame, set; to extend ParameterizedCommand.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-08  Andrew Cagney  <cagney@redhat.com>
    
    	* PlocationCommand.java: Extend ParameterizedCommand.
    	* PtypeCommand.java: Ditto.
    	* DefsetCommand.java: Eliminate call to CLI.printUsage.
    	* FrameCommands.java: Ditto.
    	* SetCommand.java: Ditto.

commit 1616ff612ae89cf4f062d1e5b103bf7a5807255a
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Nov 8 17:41:06 2007 -0500

    WhichCommand and FrameCommands extend ParameterizedCommands.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-08  Andrew Cagney  <cagney@redhat.com>
    
    	* WhereCommand.java: Extend ParameterizedCommand.
    	* FrameCommands.java: Ditto.

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

Summary of changes:
 frysk-core/frysk/hpd/ChangeLog             |   14 +++++
 frysk-core/frysk/hpd/DefsetCommand.java    |   49 +++++++---------
 frysk-core/frysk/hpd/FocusCommand.java     |   43 +++++++-------
 frysk-core/frysk/hpd/FrameCommands.java    |   37 ++++++------
 frysk-core/frysk/hpd/PlocationCommand.java |   50 +++++----------
 frysk-core/frysk/hpd/PtypeCommand.java     |   48 +++++----------
 frysk-core/frysk/hpd/SetCommand.java       |   83 ++++++++++++++-------------
 frysk-core/frysk/hpd/ViewsetCommand.java   |   88 ++++++++++++++--------------
 frysk-core/frysk/hpd/WhereCommand.java     |   60 ++++++++++----------
 frysk-core/frysk/hpd/WhichsetsCommand.java |   67 ++++++++++-----------
 10 files changed, 258 insertions(+), 281 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 9c2e773..f56cb87 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,5 +1,19 @@
 2007-11-08  Andrew Cagney  <cagney@redhat.com>
 
+	* FocusCommand.java: Eliminate call to CLI.printUsage.
+
+	* ViewsetCommand.java: Extend ParameterizedCommand.
+	* WhichsetsCommand.java: Eliminate call to CLI.printUsage.
+
+	* PlocationCommand.java: Extend ParameterizedCommand.
+	* PtypeCommand.java: Ditto.
+	* DefsetCommand.java: Eliminate call to CLI.printUsage.
+	* FrameCommands.java: Ditto.
+	* SetCommand.java: Ditto.
+
+	* WhereCommand.java: Extend ParameterizedCommand.
+	* FrameCommands.java: Ditto.
+	
 	* CLI.java (doAttach(Task)): Delete.
 	(doAttach(Proc)): Replace doAttach(int,Proc,Task).
 	* RunCommand.java: Update.
diff --git a/frysk-core/frysk/hpd/DefsetCommand.java b/frysk-core/frysk/hpd/DefsetCommand.java
index 6d57a71..e3759d3 100644
--- a/frysk-core/frysk/hpd/DefsetCommand.java
+++ b/frysk-core/frysk/hpd/DefsetCommand.java
@@ -43,20 +43,17 @@ import java.util.List;
 
 class DefsetCommand extends ParameterizedCommand {
 
-    private static final String full = "Associates a logical name with a "
-	    + "group of threads and/or processes,\n"
-	    + "creating a user-defined set. Once a user-defined set has been\n"
-	    + "established, it can be used (enclosed in brackets) as a p/t set "
-	    + "prefix\n"
-	    + "or as the argument to a focus command, providing a shorthand "
-	    + "way of\n"
-	    + "referring to potentially complex groupings of processes and "
-	    + "threads. ";
-
     DefsetCommand() {
 	super("defset",
 	      "Assign a set name to a group of processes/threads",
-	      "defset set-name p/t-set", full);
+	      "defset set-name p/t-set",
+	      ("Associates a logical name with a group of threads and/or"
+	       + " processes, creating a user-defined set.  Once a"
+	       + " user-defined set has been established, it can be used"
+	       + " (enclosed in brackets) as a p/t set prefix or as the"
+	       + " argument to a focus command, providing a shorthand"
+	       + " way of referring to potentially complex groupings"
+	       + " of processes and threads."));
     }
 
     public void interpret(CLI cli, Input cmd, Object options) {
@@ -64,23 +61,21 @@ class DefsetCommand extends ParameterizedCommand {
 	String setnot = null;
 	PTSet set = null;
 
-	if (cmd.size() == 2) {
-	    setname = cmd.parameter(0);
-	    if (!setname.matches("\\w+"))
-		throw new InvalidCommandException
-		    ("Set name must be alphanumeric.");
-	    setnot = cmd.parameter(1);
-	    if (!cli.builtinPTSets.containsKey(setnot)) {
-		set = cli.createSet(setnot);
-		cli.namedPTSets.put(setname, set);
-	    } else {
-		cli.addMessage(
-			"The set name is reserved for a predefined set.",
-			Message.TYPE_ERROR);
-	    }
+	if (cmd.size() != 2)
+	    throw new InvalidCommandException("Wrong number of parameters");
+	setname = cmd.parameter(0);
+	if (!setname.matches("\\w+"))
+	    throw new InvalidCommandException
+		("Set name must be alphanumeric.");
+	setnot = cmd.parameter(1);
+	if (!cli.builtinPTSets.containsKey(setnot)) {
+	    set = cli.createSet(setnot);
+	    cli.namedPTSets.put(setname, set);
 	} else {
-	    cli.printUsage(cmd);
-	}
+	    cli.addMessage(
+			   "The set name is reserved for a predefined set.",
+			   Message.TYPE_ERROR);
+	    }
     }
 
     int complete(CLI cli, PTSet ptset, String incomplete, int base,
diff --git a/frysk-core/frysk/hpd/FocusCommand.java b/frysk-core/frysk/hpd/FocusCommand.java
index 9717e7e..8d2bbe9 100644
--- a/frysk-core/frysk/hpd/FocusCommand.java
+++ b/frysk-core/frysk/hpd/FocusCommand.java
@@ -47,34 +47,33 @@ import frysk.proc.Task;
 import java.util.List;
 
 class FocusCommand extends ParameterizedCommand {
-    private static String full = "Changes the current p/t set. As a "
-	    + "consequence, subsequent commands will\n"
-	    + "apply to just the threads specified in the argument of this\n"
-	    + "command. When no argument is specified, the command lists the "
-	    + "threads in\n" + "the current p/t set. ";
 
     FocusCommand() {
 	super("focus", "Change the current process/thread set.",
-	      "focus [p/t-set]", full);
+	      "focus [p/t-set]",
+	      ("Changes the current p/t set. As a consequence, subsequent"
+	       + " commands will apply to just the threads specified in"
+	       + " the argument of this command.  When no argument is"
+	       + " specified, the command lists the threads in the"
+	       + " current p/t set."));
     }
 
-    public void interpret(CLI cli, Input cmd, Object options) {
-	if (cmd.size() <= 1) {
-	    if (cmd.size() == 1) {
-		cli.targetset = cli.createSet(cmd.parameter(0));
-	    	Iterator i = cli.targetset.getTasks();
-	    	while (i.hasNext()) {
-	    	    Task task = (Task) i.next();
-	    	    DebugInfoFrame frame = DebugInfoStackFactory
-			.createVirtualStackTrace(task);
-	    	    cli.setTaskFrame(task, frame);
-	    	    cli.setTaskDebugInfo(task, new DebugInfo(frame));
-	    	}
-	    } else {
-		cli.execCommand("viewset");
+    public void interpret(CLI cli, Input input, Object options) {
+	switch (input.size()) {
+	default:
+	    throw new InvalidCommandException("wrong number of arguments");
+	case 0:
+	    cli.execCommand("viewset");
+	    break;
+	case 1:
+	    cli.targetset = cli.createSet(input.parameter(0));
+	    for (Iterator i = cli.targetset.getTasks(); i.hasNext(); ) {
+		Task task = (Task) i.next();
+		DebugInfoFrame frame = DebugInfoStackFactory
+		    .createVirtualStackTrace(task);
+		cli.setTaskFrame(task, frame);
+		cli.setTaskDebugInfo(task, new DebugInfo(frame));
 	    }
-	} else {
-	    cli.printUsage(cmd);
 	}
     }
 
diff --git a/frysk-core/frysk/hpd/FrameCommands.java b/frysk-core/frysk/hpd/FrameCommands.java
index 043d49d..a87e0ff 100644
--- a/frysk-core/frysk/hpd/FrameCommands.java
+++ b/frysk-core/frysk/hpd/FrameCommands.java
@@ -40,33 +40,32 @@
 package frysk.hpd;
 
 import java.util.Iterator;
-
+import java.util.List;
 import frysk.debuginfo.DebugInfoFrame;
 import frysk.proc.Task;
 
-class FrameCommands extends Command {
-
-    private static final String full = "The up (down) command modifies the "
-	    + "current frame location(s) by adding\n"
-	    + "(subtracting) num-levels. Call stack movements are all "
-	    + "relative, so up\n"
-	    + "effectively \"moves up\" (or back) in the call stack, to a "
-	    + "frame that\n"
-	    + "has existed longer, while down \"moves down\" in the call "
-	    + "stack,\n" + "following the progress of program execution.";
+class FrameCommands extends ParameterizedCommand {
 
     FrameCommands(String name) {
-	super(name, "Move " + name
-	      + " one or more levels in the call stack", name
-	      + " [num-levels]", full);
+	super(name,
+	      ("Move " + name + " one or more levels in the call stack"),
+	      (name + " [num-levels]"),
+	      ("The up (down) command modifies the current frame"
+	       + " location(s) by adding (subtracting) num-levels.  Call"
+	       + " stack movements are all relative, so up effectively"
+	       + " \"moves up\" (or back) in the call stack, to a frame"
+	       + " that has existed longer, while down \"moves down\" in"
+	       + " the call stack, following the progress of program"
+	       + " execution."));
     }
 
-    public void interpret(CLI cli, Input cmd) {
+    int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		 List candidates) {
+	return -1;
+    }
+
+    public void interpret(CLI cli, Input cmd, Object options) {
 	PTSet ptset = cli.getCommandPTSet(cmd);
-	if (cmd.size() == 1 && cmd.parameter(0).equals("-help")) {
-	    cli.printUsage(cmd);
-	    return;
-	}
 	int level = 1;
 	boolean down = true;
 
diff --git a/frysk-core/frysk/hpd/PlocationCommand.java b/frysk-core/frysk/hpd/PlocationCommand.java
index 33d5272..225cc09 100644
--- a/frysk-core/frysk/hpd/PlocationCommand.java
+++ b/frysk-core/frysk/hpd/PlocationCommand.java
@@ -42,47 +42,25 @@ package frysk.hpd;
 import java.util.Iterator;
 import frysk.proc.Task;
 import frysk.value.Value;
+import java.util.List;
 
-class PlocationCommand
-    extends Command
-{
+class PlocationCommand extends ParameterizedCommand {
     PlocationCommand() {
-	super("plocation", "Display the location of a program variable or expression.",
-	      "plocation expression [-name] [-index]", "The plocation command " +
-	      "evaluates and displays the type of an expression. The debugger\n" +
-	      "interprets the expression by looking up the value(s) associated with\n" +
-	      "each symbol and applying the operators." +
-	      "Output is \"LocationType LocationName - Size byte(s)\"");
+	super("plocation",
+	      "Display the location of a program variable or expression.",
+	      "plocation <expression>",
+	      ("The plocation command evaluates and displays the type of an"
+	       + " expression. The debugger interprets the expression"
+	       + " by looking up the value(s) associated with each symbol"
+	       + " and applying the operators.  Output is"
+	       + " \"LocationType LocationName - Size byte(s)\""));
     }
 
-    public void interpret(CLI cli, Input cmd) {
+    public void interpret(CLI cli, Input cmd, Object options) {
         PTSet ptset = cli.getCommandPTSet(cmd);
-	if (cmd.size() == 1 && cmd.parameter(0).equals("-help")) {
-	    cli.printUsage(cmd);
-	    return;
-        }
-	if (cmd.size() == 0
-	    || ((cmd.parameter(0)).equals("-help"))) {
-	    cli.printUsage(cmd);
-	    return;
-        }
         // What's left of the command line.
 	String sInput = cmd.stringValue();
 
-	if (sInput.length() == 0) {
-	    cli.printUsage(cmd);
-	    return;
-	}
-
-	if (cmd.getAction().compareTo("assign") == 0) {
-	    int i = sInput.indexOf(' ');
-	    if (i == -1) {
-		cli.printUsage(cmd);          
-		return;
-	    }
-	    sInput = sInput.substring(0, i) + "=" + sInput.substring(i);
-	}        
-
 	Value result = null;
         Iterator taskDataIter = ptset.getTaskData();
         boolean doWithoutTask = !taskDataIter.hasNext();
@@ -110,4 +88,10 @@ class PlocationCommand
                            Message.TYPE_ERROR);
         }
     }
+
+    int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		 List completions) {
+	return CompletionFactory.completeExpression(cli, ptset, incomplete,
+						    base, completions);
+    }
 }
diff --git a/frysk-core/frysk/hpd/PtypeCommand.java b/frysk-core/frysk/hpd/PtypeCommand.java
index 5bee5be..2cf892a 100644
--- a/frysk-core/frysk/hpd/PtypeCommand.java
+++ b/frysk-core/frysk/hpd/PtypeCommand.java
@@ -39,49 +39,27 @@
      
 package frysk.hpd;
 
+import java.util.List;
 import java.util.Iterator;
 import frysk.proc.Task;
 import frysk.value.Value;
 
-class PtypeCommand
-    extends Command
-{
+class PtypeCommand extends ParameterizedCommand {
     PtypeCommand() {
-	super("ptype", "Display the type of a program variable or expression.",
-	      "ptype expression [-name] [-index]", "The ptype command " +
-	      "evaluates and displays the type of an expression. The debugger\n" +
-	      "interprets the expression by looking up the value(s) associated with\n" +
-	      "each symbol and applying the operators.");
+	super("ptype",
+	      "Display the type of a program variable or expression.",
+	      "ptype <expression>",
+	      ("The ptype command evaluates and displays the type of an"
+	       + " expression. The debugger interprets the expression"
+	       + " by looking up the value(s) associated with"
+	       + " each symbol and applying the operators."));
     }
     
-    public void interpret(CLI cli, Input cmd) {
+    public void interpret(CLI cli, Input cmd, Object options) {
         PTSet ptset = cli.getCommandPTSet(cmd);
-	if (cmd.size() == 1 && cmd.parameter(0).equals("-help")) {
-	    cli.printUsage(cmd);
-	    return;
-        }
-	if (cmd.size() == 0
-	    || ((cmd.parameter(0)).equals("-help"))) {
-	    cli.printUsage(cmd);
-	    return;
-        }
         // Skip set specification, if any
 	String sInput = cmd.stringValue();
 
-	if (sInput.length() == 0) {
-	    cli.printUsage(cmd);
-	    return;
-	}
-
-	if (cmd.getAction().compareTo("assign") == 0) {
-	    int i = sInput.indexOf(' ');
-	    if (i == -1) {
-		cli.printUsage(cmd);          
-		return;
-	    }
-	    sInput = sInput.substring(0, i) + "=" + sInput.substring(i);
-	}        
-
 	Value result = null;
         Iterator taskDataIter = ptset.getTaskData();
         boolean doWithoutTask = !taskDataIter.hasNext();
@@ -109,4 +87,10 @@ class PtypeCommand
                            Message.TYPE_ERROR);
         }
     }
+
+    int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		 List completions) {
+	return CompletionFactory.completeExpression(cli, ptset, incomplete,
+						    base, completions);
+    }
 }
diff --git a/frysk-core/frysk/hpd/SetCommand.java b/frysk-core/frysk/hpd/SetCommand.java
index f06cedf..47c53d3 100644
--- a/frysk-core/frysk/hpd/SetCommand.java
+++ b/frysk-core/frysk/hpd/SetCommand.java
@@ -42,54 +42,57 @@ package frysk.hpd;
 import java.util.List;
 
 class SetCommand extends ParameterizedCommand {
-    private static final String full = "The set command supports the viewing of "
-	    + "debugger state variables and the\n"
-	    + "assignment of new values to them.  When no arguments are "
-	    + "specified, the\n"
-	    + "names and current values for all debugger state variables are\n"
-	    + "displayed. When just a single argument is included, the "
-	    + "debugger echoes\n"
-	    + "the variable name and displays its current value.  The second "
-	    + "argument\n"
-	    + "defines the value that should replace any previous value for "
-	    + "that\n"
-	    + "variable.  It must be enclosed in quotes if it contains "
-	    + "multiple\n" + "words. ";
 
     private final DbgVariables dbgvars;
 
     SetCommand(DbgVariables dbgvars) {
 	super("set", "Change or view a debugger variable.",
-	      "set debugger-var = value\nset [debugger-var]", full);
+	      "set debugger-var = value\nset [debugger-var]",
+	      ("The set command supports the viewing of debugger state"
+	       + " variables and the assignment of new values to them.  When"
+	       + " no arguments are specified, the names and current values"
+	       + " for all debugger state variables are displayed.  When"
+	       + " just a single argument is included, the debugger echoes"
+	       + " the variable name and displays its current value.  The"
+	       + " second argument defines the value that should replace"
+	       + " any previous value for that variable.  It must be"
+	       + " enclosed in quotes if it contains multiple words."));
 	this.dbgvars = dbgvars;
     }
 
-    public void interpret(CLI cli, Input cmd, Object options) {
-	String temp;
-	if (cmd.size() == 3 && (cmd.parameter(1)).equals("=")) {
-	    temp = cmd.parameter(0);
-	    if (dbgvars.variableIsValid(temp)) {
-		if (dbgvars.valueIsValid(temp, cmd.parameter(2))) {
-		    dbgvars.setVariable(temp, cmd.parameter(2));
-		} else
-		    cli.addMessage("Illegal variable value.",
-			    Message.TYPE_ERROR);
-	    } else
-		cli.addMessage(new Message("Illegal debugger variable \""
-			+ cmd.parameter(0) + "\"", Message.TYPE_ERROR));
-	} else if (cmd.size() == 1) {
-	    temp = cmd.parameter(0);
-	    if (dbgvars.variableIsValid(temp)) {
-		cli.addMessage(
-			temp + " = " + dbgvars.getValue(temp).toString(),
-			Message.TYPE_NORMAL);
-	    } else
-		cli.addMessage(new Message("Illegal debugger variable \""
-			+ cmd.parameter(0) + "\"", Message.TYPE_ERROR));
-	} else if (cmd.size() == 0) {
-	    cli.addMessage(dbgvars.toString(), Message.TYPE_NORMAL);
-	} else {
-	    cli.printUsage(cmd);
+    public void interpret(CLI cli, Input input, Object options) {
+	switch (input.size()) {
+	default:
+	    throw new InvalidCommandException("wrong number of parameters");
+	case 3:
+	    if (!input.parameter(1).equals("="))
+		throw new InvalidCommandException("missing \"=\"");
+	    String variable = input.parameter(0);
+	    if (!dbgvars.variableIsValid(variable))
+		throw new InvalidCommandException("Debugger variable \""
+						  + variable
+						  + "\" is invalid");
+	    String value = input.parameter(2);
+	    if (!dbgvars.valueIsValid(variable, value))
+		throw new InvalidCommandException("Variable value \""
+						  + value
+						  + "\" is invalid");
+	    dbgvars.setVariable(variable, value);
+	    break;
+	case 1:
+	    String var = input.parameter(0);
+	    if (!dbgvars.variableIsValid(var))
+		throw new InvalidCommandException("Variable \""
+						  + var
+						  + "\" is invalid");
+	    cli.outWriter.print(var);
+	    cli.outWriter.print(" = ");
+	    cli.outWriter.print(dbgvars.getValue(var));
+	    cli.outWriter.println();
+	    break;
+	case 0:
+	    cli.outWriter.println(dbgvars.toString());
+	    break;
 	}
     }
 
diff --git a/frysk-core/frysk/hpd/ViewsetCommand.java b/frysk-core/frysk/hpd/ViewsetCommand.java
index 4d21d10..fc94e98 100644
--- a/frysk-core/frysk/hpd/ViewsetCommand.java
+++ b/frysk-core/frysk/hpd/ViewsetCommand.java
@@ -40,62 +40,62 @@
 package frysk.hpd;
 
 import java.util.Iterator;
-
+import java.util.List;
 import frysk.proc.Task;
 
-class ViewsetCommand extends Command {
-
-    private static final String full = "The viewset command displays the "
-	    + "members of debugger- or user-defined\n"
-	    + "sets. When no argument is used, the members of all currently "
-	    + "defined\n" + "sets are displayed. ";
+class ViewsetCommand extends ParameterizedCommand {
 
     ViewsetCommand() {
 	super("viewset", "List members of a proc/task set.",
-	      "viewset [set-name]", full);
+	      "viewset [set-name]",
+	      ("The viewset command displays the members of debugger-"
+	       + " or user-defined sets.  When no argument is used, the"
+	       + " members of all currently defined sets are displayed."));
     }
 
-    public void interpret(CLI cli, Input cmd) {
-	if (cmd.size() == 1 && cmd.parameter(0).equals("-help")) {
-	    cli.printUsage(cmd);
-	    return;
-	}
+    int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		 List candidates) {
+	return -1;
+    }


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



More information about the Frysk-cvs mailing list