public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Second half of refactor Set/Unset.
@ 2007-11-09 20:54 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2007-11-09 20:54 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  8b867fb62647409597fd921ec3e0888e53976190 (commit)
       via  6d8e45c3d597cb380215da40c2a6b02702ee4b9d (commit)
      from  fd94985768aaab064cb3fdae15087ace1fa7b188 (commit)

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

- Log -----------------------------------------------------------------
commit 8b867fb62647409597fd921ec3e0888e53976190
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Nov 9 15:50:11 2007 -0500

    Second half of refactor Set/Unset.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-09  Andrew Cagney  <cagney@redhat.com>
    
    	* DbgVariables.java (complete(String,int,List)): New.
    	* TestDbgVariables.java: New.
    	* DbgVariableCommands: New.
    	* SetCommand.java: Delete.
    	* UnsetCommand.java: Delete.
    	* TopLevelCommand.java: Update.
    	* CLI.java (dbgvars): Make final; update.

commit 6d8e45c3d597cb380215da40c2a6b02702ee4b9d
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Nov 9 15:48:59 2007 -0500

    Refactor unset and set; test.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-09  Andrew Cagney  <cagney@redhat.com>
    
    	* DbgVariables.java (complete(String,int,List)): New.
    	* TestDbgVariables.java: New.
    	* DbgVariableCommands: New.
    	* SetCommand.java: Delete.
    	* UnsetCommand.java: Delete.
    	* TopLevelCommand.java: Update.
    	* CLI.java (dbgvars): Make final; update.

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

Summary of changes:
 frysk-core/frysk/hpd/CLI.java                 |    9 +-
 frysk-core/frysk/hpd/ChangeLog                |    8 +
 frysk-core/frysk/hpd/DbgVariableCommands.java |  162 ++++++++++++++++
 frysk-core/frysk/hpd/DbgVariables.java        |  245 ++++++++++++-------------
 frysk-core/frysk/hpd/SetCommand.java          |  103 -----------
 frysk-core/frysk/hpd/TopLevelCommand.java     |    6 +-
 frysk-core/frysk/hpd/UnsetCommand.java        |   84 ---------
 7 files changed, 294 insertions(+), 323 deletions(-)
 create mode 100644 frysk-core/frysk/hpd/DbgVariableCommands.java
 delete mode 100644 frysk-core/frysk/hpd/SetCommand.java
 delete mode 100644 frysk-core/frysk/hpd/UnsetCommand.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index e077073..04a10a5 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -163,7 +163,7 @@ public class CLI {
     private final SortedMap handlers = new TreeMap();
     private final Command topLevelCommand;
     final UserHelp userhelp;
-    private DbgVariables dbgvars;
+    final DbgVariables dbgvars = new DbgVariables();
 
     // PT set related stuff
     private SetNotationParser setparser;
@@ -220,7 +220,6 @@ public class CLI {
 
         prepro = new Preprocessor();
         userhelp = new UserHelp();
-        dbgvars = new DbgVariables();
    
         //XXX: Must make a reference to every command that is used
         //otherwise build system will discard those classes. Therefore
@@ -250,11 +249,11 @@ public class CLI {
         addHandler(new PtypeCommand());
         addHandler(new QuitCommand("quit"));
         addHandler(new QuitCommand("exit"));
-        addHandler(new SetCommand(dbgvars));
+        addHandler(new DbgVariableCommands.Set());
         addHandler(new StepCommand());
         addHandler(new StepInstructionCommand());
         addHandler(new UndefsetCommand());
-        addHandler(new UnsetCommand(dbgvars));
+        addHandler(new DbgVariableCommands.Unset());
         addHandler(new FrameCommands("up"));
         addHandler(new ViewsetCommand());
         addHandler(new WhatCommand());
@@ -268,7 +267,7 @@ public class CLI {
         addHandler(new ExamineCommand());
         addHandler(new LoadCommand());
         addHandler(new PeekCommand());
-	topLevelCommand = new TopLevelCommand(dbgvars);
+	topLevelCommand = new TopLevelCommand();
 
         // initialize PT set stuff
         setparser = new SetNotationParser();
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index f46f0fa..093da8c 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,5 +1,13 @@
 2007-11-09  Andrew Cagney  <cagney@redhat.com>
 
+	* DbgVariables.java (complete(String,int,List)): New.
+	* TestDbgVariables.java: New.
+	* DbgVariableCommands: New.
+	* SetCommand.java: Delete.
+	* UnsetCommand.java: Delete.
+	* TopLevelCommand.java: Update.
+	* CLI.java (dbgvars): Make final; update.
+
 	* TestParameterizedCommand.java (check(...)): Add check for
 	input.stringValue().
 	* PrintCommand.java: Extend ParameterizedCommand.
diff --git a/frysk-core/frysk/hpd/DbgVariableCommands.java b/frysk-core/frysk/hpd/DbgVariableCommands.java
new file mode 100644
index 0000000..e8c90d2
--- /dev/null
+++ b/frysk-core/frysk/hpd/DbgVariableCommands.java
@@ -0,0 +1,162 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2005, 2006, 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;
+
+abstract class DbgVariableCommands extends ParameterizedCommand {
+
+    DbgVariableCommands(String name, String description,
+			String syntax, String full) {
+	super(name, description, syntax, full);
+    }
+
+    int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		 List completions) {
+	return cli.dbgvars.complete(incomplete, base, completions);
+    }
+
+    static class Set extends DbgVariableCommands {
+	Set() {
+	    super("set", "Change or view a debugger variable.",
+		  "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."));
+	}
+	public void interpret(CLI cli, Input input, Object options) {
+	    switch (input.size()) {
+	    default:
+		throw new InvalidCommandException
+		    ("wrong number of parameters");
+	    case 0:
+		cli.outWriter.println(cli.dbgvars.toString());
+		break;
+	    case 1:
+		String var = input.parameter(0);
+		if (!cli.dbgvars.variableIsValid(var))
+		    throw new InvalidCommandException("Debug variable \""
+						      + var
+						      + "\" is invalid");
+		cli.outWriter.print(var);
+		cli.outWriter.print(" = ");
+		cli.outWriter.print(cli.dbgvars.getValue(var));
+		cli.outWriter.println();
+		break;
+	    case 2:
+	    case 3:
+		if (input.size() == 3 && !input.parameter(1).equals("="))
+		    throw new InvalidCommandException("missing \"=\"");
+		String variable = input.parameter(0);
+		if (!cli.dbgvars.variableIsValid(variable))
+		    throw new InvalidCommandException("Debugger variable \""
+						      + variable
+						      + "\" is invalid");
+		String value = input.parameter(input.size() - 1);
+		if (!cli.dbgvars.valueIsValid(variable, value))
+		    throw new InvalidCommandException("Debug variable value \""
+						      + value
+						      + "\" is invalid");
+		cli.dbgvars.setVariable(variable, value);
+		break;
+	    }
+	}
+    }
+
+    static class Unset extends DbgVariableCommands {
+	Unset() {
+	    super("unset", "Revert variable value to default.",
+		  "unset [ <debugger-var> | -all ]",
+		  ("The unset command reverses the effects of any previous"
+		   + " set operations, restoring the debugger state"
+		   + " variable(s) to their default settings.  When the"
+		   + " argument -all is specified, the command affects all"
+		   + " debugger state variables, restoring them to the"
+		   + " original settings that were in effect when the"
+		   + " debugging session began.  When just a single"
+		   + " argument is included, only that variable is"
+		   + " affected."));
+	    add(new CommandOption("all", "Revert all variables") {
+		    void parse(String arg, Object option) {
+			((Options)option).all = true;
+		    }
+		});
+	}
+
+	private class Options {
+	    boolean all = false;
+	}
+	Object options() {
+	    return new Options();
+	}
+
+	public void interpret(CLI cli, Input input, Object o) {
+	    Options options = (Options)o;
+	    if (options.all) {
+		if (input.size() != 0)
+		    throw new InvalidCommandException
+			("Too many arguments for -all");
+		cli.dbgvars.unsetAll();
+		cli.outWriter.println("All debug variables reset");
+		return;
+	    }
+
+	    switch (input.size()) {
+	    case 0:
+		throw new InvalidCommandException("Missing argument");
+	    case 1:
+		String temp = input.parameter(0);
+		if (!cli.dbgvars.variableIsValid(temp))
+		    throw new InvalidCommandException
+			("\"" + temp + "\" is not a valid debugger variable");
+		cli.dbgvars.unsetVariable(temp);
+		break;
+	    default:
+		throw new InvalidCommandException("Too many arguments");
+	    }
+	}
+    }
+}
diff --git a/frysk-core/frysk/hpd/DbgVariables.java b/frysk-core/frysk/hpd/DbgVariables.java
index c38083a..c115224 100644
--- a/frysk-core/frysk/hpd/DbgVariables.java
+++ b/frysk-core/frysk/hpd/DbgVariables.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2006, Red Hat Inc.
+// Copyright 2006, 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
@@ -36,160 +36,149 @@
 // 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.Hashtable;
+import java.util.SortedMap;
+import java.util.TreeMap;
 import java.util.LinkedList;
 import java.util.Arrays;
 import java.lang.Integer;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * Debugger variable accessible through the "set" command.
  */
-class DbgVariables
-{
-	public static int VARTYPE_INT = 0;
-	public static int VARTYPE_STRING = 1;
-	public static int VARTYPE_CUSTOM = 2;
-
-	Hashtable vars;
-
-	class Value
-	{
-		private int type;
-		private Object value;
-		private Object deflt;
-		private LinkedList validVals;
-
-		public Value(int type, Object deflt)
-		{
-			this.type = type;
-			this.value = deflt;
-			this.deflt = deflt;
-		}
-
-		public Value(int type, Object deflt, String[] validVals)
-		{
-			this.type = type;
-			this.value = deflt;
-			this.deflt = deflt;
-			this.validVals = new LinkedList(Arrays.asList(validVals));
-		}
-
-		public int getType()
-		{
-			return type;
-		}
-
-		public Object getValue()
-		{
-			return value;
-		}
-
-		public Object getDefault()
-		{
-			return deflt;
-		}
-
-		public void setValue(Object val)
-		{
-			value = val;
-		}
-
-		public boolean valueValid(String val)
-		{
-			return validVals.contains(val);
-		}
-
-		public String toString()
-		{
-			return value.toString();
-		}
+class DbgVariables {
+    public static int VARTYPE_INT = 0;
+    public static int VARTYPE_STRING = 1;
+    public static int VARTYPE_CUSTOM = 2;
+
+    static private class Value {
+	private int type;
+	private Object value;
+	private Object deflt;
+	private LinkedList validVals;
+
+	public Value(int type, Object deflt) {
+	    this.type = type;
+	    this.value = deflt;
+	    this.deflt = deflt;
 	}
 
-	public DbgVariables()
-	{
-		vars = new Hashtable();
-
-		vars.put("MODE", new Value(VARTYPE_CUSTOM, "MULTILEVEL", new String[] {"THREADS", "PROCESSES", "MULTILEVEL"}));
-		vars.put("START_MODEL", new Value(VARTYPE_CUSTOM, "ANY", new String[] {"ANY", "ALL"}));
-		vars.put("STOP_MODEL", new Value(VARTYPE_CUSTOM, "ANY", new String[] {"ANY", "ALL"}));
-		vars.put("EVENT_INTERRUPT", new Value(VARTYPE_CUSTOM, "ON", new String[] {"ON", "OFF"}));
-		vars.put("VERBOSE", new Value(VARTYPE_CUSTOM, "WARN", new String[] {"WARN", "ERR", "ALL"}));
-		vars.put("ERROR_CHECKS", new Value(VARTYPE_CUSTOM, "NORMAL", new String[] {"NORMAL", "MIN", "MAX"}));
-		vars.put("MAX_PROMPT", new Value(VARTYPE_INT, new Integer(40)));
-		vars.put("MAX_HISTORY", new Value(VARTYPE_INT, new Integer(20)));
-		vars.put("MAX_LEVELS", new Value(VARTYPE_INT, new Integer(20)));
-		vars.put("MAX_LIST", new Value(VARTYPE_INT, new Integer(20)));
-		vars.put("PROMPT", new Value(VARTYPE_STRING, "(frysk) "));
-		vars.put("SOURCE_PATH", new Value(VARTYPE_STRING, ""));
-		vars.put("EXECUTABLE_PATH", new Value(VARTYPE_STRING, "./:" + System.getenv("PATH")));
+	public Value(int type, Object deflt, String[] validVals) {
+	    this.type = type;
+	    this.value = deflt;
+	    this.deflt = deflt;
+	    this.validVals = new LinkedList(Arrays.asList(validVals));
 	}
 
-	public void setVariable(String var, String value)
-	{
-		Value tempval = (Value)vars.get(var);
-
-		if (var.equals("MAX_PROMPT") || var.equals("MAX_HISTORY") ||
-				var.equals("MAX_LEVELS") || var.equals("MAX_LIST"))
-			tempval.setValue(Integer.getInteger(value));
-		else 
-			tempval.setValue(value);
+	public int getType() {
+	    return type;
 	}
 
-	public void unsetVariable(String var)
-	{
-		Value tempval = (Value)vars.get(var);
-		tempval.setValue(tempval.getDefault());
+	public Object getValue() {
+	    return value;
 	}
 
-	public void unsetAll()
-	{
-		Value tempval;
-
-		for (Iterator iter = vars.values().iterator(); iter.hasNext();)
-		{
-			tempval = (Value)iter.next();
-			tempval.setValue(tempval.getDefault());
-		}
+	public Object getDefault() {
+	    return deflt;
 	}
 
-	public boolean variableIsValid(String var)
-	{
-		return vars.containsKey(var);
+	public void setValue(Object val) {
+	    value = val;
 	}
 
-	public boolean valueIsValid(String var, String value)
-	{
-		boolean result = true;
-		Value tempval = (Value) vars.get(var);
-		
-		if (tempval.getType() == VARTYPE_INT && Integer.getInteger(value) == null)
-			result = false;
-		else if (tempval.getType() == VARTYPE_CUSTOM && !tempval.valueValid(value))
-			result = false;
-
-		return result;
+	public boolean valueValid(String val) {
+	    return validVals.contains(val);
 	}
 
-	public int getIntValue(String var)
-	{
-		return ((Integer)vars.get(var)).intValue();
+	public String toString() {
+	    return value.toString();
 	}
-
-	public String getStringValue(String var)
-	{
-		return (String)vars.get(var);
+    }
+
+    private final SortedMap vars = new TreeMap();
+
+    public DbgVariables() {
+	vars.put("MODE", new Value(VARTYPE_CUSTOM, "MULTILEVEL", new String[] {"THREADS", "PROCESSES", "MULTILEVEL"}));
+	vars.put("START_MODEL", new Value(VARTYPE_CUSTOM, "ANY", new String[] {"ANY", "ALL"}));
+	vars.put("STOP_MODEL", new Value(VARTYPE_CUSTOM, "ANY", new String[] {"ANY", "ALL"}));
+	vars.put("EVENT_INTERRUPT", new Value(VARTYPE_CUSTOM, "ON", new String[] {"ON", "OFF"}));
+	vars.put("VERBOSE", new Value(VARTYPE_CUSTOM, "WARN", new String[] {"WARN", "ERR", "ALL"}));
+	vars.put("ERROR_CHECKS", new Value(VARTYPE_CUSTOM, "NORMAL", new String[] {"NORMAL", "MIN", "MAX"}));
+	vars.put("MAX_PROMPT", new Value(VARTYPE_INT, new Integer(40)));
+	vars.put("MAX_HISTORY", new Value(VARTYPE_INT, new Integer(20)));
+	vars.put("MAX_LEVELS", new Value(VARTYPE_INT, new Integer(20)));
+	vars.put("MAX_LIST", new Value(VARTYPE_INT, new Integer(20)));
+	vars.put("PROMPT", new Value(VARTYPE_STRING, "(frysk) "));
+	vars.put("SOURCE_PATH", new Value(VARTYPE_STRING, ""));
+	vars.put("EXECUTABLE_PATH", new Value(VARTYPE_STRING, "./:" + System.getenv("PATH")));
+    }
+
+    public void setVariable(String var, String value) {
+	Value tempval = (Value)vars.get(var);
+	if (var.equals("MAX_PROMPT") || var.equals("MAX_HISTORY") ||
+	    var.equals("MAX_LEVELS") || var.equals("MAX_LIST"))
+	    tempval.setValue(Integer.getInteger(value));
+	else 
+	    tempval.setValue(value);
+    }
+
+    public void unsetVariable(String var) {
+	Value tempval = (Value)vars.get(var);
+	tempval.setValue(tempval.getDefault());
+    }
+
+    public void unsetAll() {
+	Value tempval;
+	for (Iterator iter = vars.values().iterator(); iter.hasNext();) {
+	    tempval = (Value)iter.next();
+	    tempval.setValue(tempval.getDefault());
 	}
+    }
 
-	public Object getValue(String var)
-	{
-		return ((Value)vars.get(var)).getValue();
-	}
+    public boolean variableIsValid(String var) {
+	return vars.containsKey(var);
+    }
 
-	public String toString()
-	{
-		return vars.toString();
+    public boolean valueIsValid(String var, String value) {
+	boolean result = true;
+	Value tempval = (Value) vars.get(var);
+		
+	if (tempval.getType() == VARTYPE_INT
+	    && Integer.getInteger(value) == null)
+	    result = false;
+	else if (tempval.getType() == VARTYPE_CUSTOM
+		 && !tempval.valueValid(value))
+	    result = false;
+	return result;
+    }
+
+    public int getIntValue(String var) {
+	return ((Integer)vars.get(var)).intValue();
+    }
+
+    public String getStringValue(String var) {
+	return (String)vars.get(var);
+    }


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


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

only message in thread, other threads:[~2007-11-09 20:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-09 20:54 [SCM] master: Second half of refactor Set/Unset cagney

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