You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by mo...@apache.org on 2009/11/23 15:54:15 UTC
svn commit: r883384 [39/47] - in /incubator/kato/trunk/org.apache.kato: ./
kato.anttasks/src/main/java/org/apache/kato/anttasks/
kato.anttasks/src/main/java/org/apache/kato/anttasks/sitebuilder/
kato.anttasks/src/main/java/org/apache/kato/anttasks/tck/...
Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/CdCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/CdCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/CdCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/CdCommand.java Mon Nov 23 15:53:48 2009
@@ -1,75 +1,75 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.katoview.commands;
-
-import java.util.HashMap;
-import java.util.Stack;
-import java.io.File;
-
-import javax.tools.diagnostics.image.Image;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class CdCommand extends Command {
-
- public CdCommand(Output o){
- super(o, "cd", "changes the current working directory, used for log files",
- "parameters: <directory_name>\n\n" +
- "Changes the current working directory to <directory_name>, checking " +
- "to see if it exists and is a directory before making the change. " +
- "The current working directory is where log files are outputted to; " +
- "a change to the current working directory has no effect on the current " +
- "log file setting because the logging filename is converted to an " +
- "absolute path when set. Note: to see what the current working " +
- "directory is set to, use the \"pwd\" command.\n"
- );
- child_commands = null;
- }
-
- public void doCommand(Stack args, Image loadedImage, HashMap properties){
- if (args.isEmpty())
- {
- out.error("\"cd\" requires exactly one parameter");
- return;
- }
-
- String path = "";
-
- while (!args.isEmpty())
- {
- path += (String)args.pop() + " ";
- }
- path = path.substring(0, path.length() - 1);
-
- File newPwd = Utils.absPath(properties, path);
-
- if (!newPwd.isDirectory())
- {
- if (newPwd.isFile())
- {
- out.error("cannot change to specified path because it specifies a file, not a directory");
- }
- else
- {
- out.error("specified path is not a directory or a file; it probably doesn't exist");
- }
- }
- else
- {
- properties.put("pwd", newPwd);
- }
- }
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.katoview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+import java.io.File;
+
+import javax.tools.diagnostics.image.Image;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class CdCommand extends Command {
+
+ public CdCommand(Output o){
+ super(o, "cd", "changes the current working directory, used for log files",
+ "parameters: <directory_name>\n\n" +
+ "Changes the current working directory to <directory_name>, checking " +
+ "to see if it exists and is a directory before making the change. " +
+ "The current working directory is where log files are outputted to; " +
+ "a change to the current working directory has no effect on the current " +
+ "log file setting because the logging filename is converted to an " +
+ "absolute path when set. Note: to see what the current working " +
+ "directory is set to, use the \"pwd\" command.\n"
+ );
+ child_commands = null;
+ }
+
+ public void doCommand(Stack args, Image loadedImage, HashMap properties){
+ if (args.isEmpty())
+ {
+ out.error("\"cd\" requires exactly one parameter");
+ return;
+ }
+
+ String path = "";
+
+ while (!args.isEmpty())
+ {
+ path += (String)args.pop() + " ";
+ }
+ path = path.substring(0, path.length() - 1);
+
+ File newPwd = Utils.absPath(properties, path);
+
+ if (!newPwd.isDirectory())
+ {
+ if (newPwd.isFile())
+ {
+ out.error("cannot change to specified path because it specifies a file, not a directory");
+ }
+ else
+ {
+ out.error("specified path is not a directory or a file; it probably doesn't exist");
+ }
+ }
+ else
+ {
+ properties.put("pwd", newPwd);
+ }
+ }
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/CdCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/Command.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/Command.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/Command.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/Command.java Mon Nov 23 15:53:48 2009
@@ -1,306 +1,306 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.katoview.commands;
-
-import java.util.HashMap;
-import java.util.Vector;
-import java.util.Stack;
-import java.util.Iterator;
-
-import javax.tools.diagnostics.image.Image;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public abstract class Command {
-
- private String name;
- private String desc;
- private String longDesc;
- protected Vector child_commands;
- protected Output out;
-
- protected Command(Output o, String aName, String aDesc, String aLongDesc){
- out = o;
- name = aName;
- desc = aDesc;
-
- // WARNING: assumptions on aLongDesc:
- // - the only whitespace is ' ' and '\n'; no tabs
- // - there are no single words longer than 80 - 12 = 68 characters
- // - 12 is from nIndent + nWrapIndent + 1
- longDesc = aLongDesc;
- }
-
- public String getName(){
- return name;
- }
-
- public String getDesc(){
- return desc;
- }
-
- public Vector getChildCommands(){
- return child_commands;
- }
-
- public void printHelp(String indent, int descOffset, Stack currArgs, Stack prevArgs)
- {
- if (null == currArgs)
- {
- // the calling function just wants us to print our short name
-
- String spaces = "";
-
- int numSpaces = descOffset;
- numSpaces -= indent.length();
- numSpaces -= name.length();
- for (int i = 0; i < numSpaces; i++)
- spaces += " ";
-
- out.print(indent + name + spaces + desc + "\n");
-
- if (null != child_commands)
- {
- Iterator itCommand = child_commands.iterator();
- while (itCommand.hasNext())
- {
- Command command = (Command)itCommand.next();
- command.printHelp(indent + " ", descOffset, currArgs, prevArgs);
- }
- }
- return;
- }
- if (currArgs.isEmpty())
- {
- // out of arguments; we should either print our long description (if we're
- // a leaf node in the command tree) or get our children to print their
- // short descriptions
-
- String cmdName = getNameFromStack(prevArgs);
-
- if (null == child_commands) { // we're a leaf node in the command tree
- if (null == longDesc) {
- out.error("<long descriptions not implemented for \"" +
- cmdName + "\" command>");
- } else {
- if (cmdName != null && cmdName != "") {
- out.print("\n");
- out.print("\t");
- out.print("\"" + cmdName + "\" command");
- }
- out.print("\n");
- out.print(formatDesc(longDesc));
- out.print("\n");
- }
- } else { // we're an internal node in the command tree
- indent = "\t";
- out.print("\n");
- out.print(indent + cmdName);
- out.print("\n");
- Iterator itCommand = child_commands.iterator();
- while (itCommand.hasNext())
- {
- Command command = (Command)itCommand.next();
- command.printHelp(indent + " ", descOffset, null, prevArgs);
- }
- out.print("\n");
- }
-
- return;
- }
-
- // ASSERT: !currArgs.isEmpty()
- // we've still got arguments left so we should print an error if we're a leaf
- // node in the command tree or keep on processing if we're an internal node
- String arg = (String)currArgs.pop();
-
- if (null == child_commands) // we're a leaf node; output an error
- {
- String cmdName = getNameFromStack(prevArgs);
- out.error("\"" + cmdName + "\" does not have any sub-commands");
- return;
- }
-
- // ASSERT: !currArgs.isEmpty() && null != child_commands
- // we've still got arguments left and we're an internal node in the command tree;
- // thus, we'll pass on the job to the next command down
- Iterator itCommand = child_commands.iterator();
- boolean found = false;
- Command currCommand = null;
- while (itCommand.hasNext() && !found)
- {
- currCommand = (Command)itCommand.next();
- if (currCommand.getName().equals(arg))
- found = true;
- }
-
- if (found)
- {
- prevArgs.push(arg);
- currCommand.printHelp(indent, descOffset, currArgs, prevArgs);
- }
- else
- {
- String cmdName = getNameFromStack(prevArgs);
- out.error("\"" + arg + "\" is not a sub-command of \"" + cmdName + "\"");
- return;
- }
- }
-
- private String getNameFromStack(Stack args)
- {
- String cmdName = "";
- while (!args.isEmpty())
- {
- String currArg = (String)args.pop();
- if (currArg.endsWith("/")) {
- cmdName = currArg + cmdName;
- } else {
- cmdName = currArg + " " + cmdName;
- }
- }
- if (cmdName.length() > 0 && cmdName.endsWith(" "))
- {
- cmdName = cmdName.substring(0, cmdName.length() - 1);
- }
- return cmdName;
- }
-
- private String formatDesc(String sDesc)
- {
- int nIndent = 8;
-
- // note: lines _always_ start with "\t " (the space is intentional) since
- // every word is prefixed by a space
- String sIndent = "\t";
-
- int nWrapIndent = 3;
- String sWrapIndent = " ";
-
- int nWidth = 80;
- char[] aDesc = sDesc.toCharArray();
- String formatted = "";
-
- formatted += sIndent;
- int charsInLine = nIndent;
- String currWord;
- int i = 0;
-
- while (i < aDesc.length)
- {
- currWord = "";
- for (;i < aDesc.length && '\n' != aDesc[i] && ' ' != aDesc[i]; i++)
- {
- currWord += aDesc[i];
- }
- // advance another character, past the '\n' or ' '; otherwise we get stuck
- // in an infinite loop
- i++;
-
- int currWordLength = currWord.length() + 1; // the 1 is for the added space
- if (currWordLength + charsInLine > nWidth)
- {
- // start a new line
- formatted += "\n";
- formatted += sIndent;
- formatted += sWrapIndent;
- charsInLine = nIndent + nWrapIndent;
- }
-
- // add the word to the current line
- formatted += " " + currWord;
- charsInLine += currWordLength;
-
- // if the character directly following the last word read is a new-line
- // character, start a new line
- if (i <= aDesc.length && '\n' == aDesc[i-1])
- {
- // start a new line
- formatted += "\n";
- formatted += sIndent;
- charsInLine = nIndent;
- }
- }
-
- return formatted;
- }
-
- public void doCommand(Stack args, Image loadedImage, HashMap properties){
- boolean found = false;
- String nextCommand = null;
-
- if (!args.isEmpty())
- {
- nextCommand = (String)args.pop();
- }
- else
- {
- out.error("specified command requires additional subcommand");
- return;
- }
- nextCommand = nextCommand.toLowerCase();
-
- Command currCommand = null;
- Iterator itCommand = child_commands.iterator();
- while (itCommand.hasNext() && !found)
- {
- currCommand = (Command)itCommand.next();
- if (nextCommand.equals(currCommand.getName()))
- found = true;
- }
-
- if (found){
- currCommand.doCommand(args, loadedImage, properties);
- }
- else{
- out.error("command \"" + nextCommand + "\" does not exist; type \"help\" " +
- "for a list of available commands");
- return;
- }
- }
-
- protected void doScrollCommand(Image loadedImage, HashMap properties, boolean direction){
- RootCommand rootCommand = (RootCommand)properties.get(Utils.RootCommand_OBJECT);
- if (null == rootCommand){
- out.error("ERROR - No mapping found for RootCommand object");
- return;
- }
-
- Long currentMemAddress = (Long)properties.get(Utils.CURRENT_MEM_ADDRESS);
- Integer currentNumBytesToPrint = (Integer)properties.get(Utils.CURRENT_NUM_BYTES_TO_PRINT);
- if (null == currentMemAddress || null == currentNumBytesToPrint){
- out.error("ERROR - starting mem address or the number of bytes to print needs to be set " +
- "by running hexdump command");
- return;
- }
-
- //out.println("*******" + Long.toHexString( ((Long)properties.get(Utils.CURRENT_MEM_ADDRESS)).longValue() ));
-
- long newMemAddrss;
- if (direction)
- newMemAddrss = currentMemAddress.longValue() + currentNumBytesToPrint.intValue();
- else
- newMemAddrss = currentMemAddress.longValue() - currentNumBytesToPrint.intValue();
-
- Stack plusCommandStack = Utils.constructStackFromString("hexdump" + " "
- + Long.toHexString(newMemAddrss) + " " + currentNumBytesToPrint.toString());
-
- rootCommand.doCommand(plusCommandStack, loadedImage, properties);
-
- properties.put(Utils.CURRENT_MEM_ADDRESS, new Long(newMemAddrss));
- }
-}
-
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.katoview.commands;
+
+import java.util.HashMap;
+import java.util.Vector;
+import java.util.Stack;
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.Image;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public abstract class Command {
+
+ private String name;
+ private String desc;
+ private String longDesc;
+ protected Vector child_commands;
+ protected Output out;
+
+ protected Command(Output o, String aName, String aDesc, String aLongDesc){
+ out = o;
+ name = aName;
+ desc = aDesc;
+
+ // WARNING: assumptions on aLongDesc:
+ // - the only whitespace is ' ' and '\n'; no tabs
+ // - there are no single words longer than 80 - 12 = 68 characters
+ // - 12 is from nIndent + nWrapIndent + 1
+ longDesc = aLongDesc;
+ }
+
+ public String getName(){
+ return name;
+ }
+
+ public String getDesc(){
+ return desc;
+ }
+
+ public Vector getChildCommands(){
+ return child_commands;
+ }
+
+ public void printHelp(String indent, int descOffset, Stack currArgs, Stack prevArgs)
+ {
+ if (null == currArgs)
+ {
+ // the calling function just wants us to print our short name
+
+ String spaces = "";
+
+ int numSpaces = descOffset;
+ numSpaces -= indent.length();
+ numSpaces -= name.length();
+ for (int i = 0; i < numSpaces; i++)
+ spaces += " ";
+
+ out.print(indent + name + spaces + desc + "\n");
+
+ if (null != child_commands)
+ {
+ Iterator itCommand = child_commands.iterator();
+ while (itCommand.hasNext())
+ {
+ Command command = (Command)itCommand.next();
+ command.printHelp(indent + " ", descOffset, currArgs, prevArgs);
+ }
+ }
+ return;
+ }
+ if (currArgs.isEmpty())
+ {
+ // out of arguments; we should either print our long description (if we're
+ // a leaf node in the command tree) or get our children to print their
+ // short descriptions
+
+ String cmdName = getNameFromStack(prevArgs);
+
+ if (null == child_commands) { // we're a leaf node in the command tree
+ if (null == longDesc) {
+ out.error("<long descriptions not implemented for \"" +
+ cmdName + "\" command>");
+ } else {
+ if (cmdName != null && cmdName != "") {
+ out.print("\n");
+ out.print("\t");
+ out.print("\"" + cmdName + "\" command");
+ }
+ out.print("\n");
+ out.print(formatDesc(longDesc));
+ out.print("\n");
+ }
+ } else { // we're an internal node in the command tree
+ indent = "\t";
+ out.print("\n");
+ out.print(indent + cmdName);
+ out.print("\n");
+ Iterator itCommand = child_commands.iterator();
+ while (itCommand.hasNext())
+ {
+ Command command = (Command)itCommand.next();
+ command.printHelp(indent + " ", descOffset, null, prevArgs);
+ }
+ out.print("\n");
+ }
+
+ return;
+ }
+
+ // ASSERT: !currArgs.isEmpty()
+ // we've still got arguments left so we should print an error if we're a leaf
+ // node in the command tree or keep on processing if we're an internal node
+ String arg = (String)currArgs.pop();
+
+ if (null == child_commands) // we're a leaf node; output an error
+ {
+ String cmdName = getNameFromStack(prevArgs);
+ out.error("\"" + cmdName + "\" does not have any sub-commands");
+ return;
+ }
+
+ // ASSERT: !currArgs.isEmpty() && null != child_commands
+ // we've still got arguments left and we're an internal node in the command tree;
+ // thus, we'll pass on the job to the next command down
+ Iterator itCommand = child_commands.iterator();
+ boolean found = false;
+ Command currCommand = null;
+ while (itCommand.hasNext() && !found)
+ {
+ currCommand = (Command)itCommand.next();
+ if (currCommand.getName().equals(arg))
+ found = true;
+ }
+
+ if (found)
+ {
+ prevArgs.push(arg);
+ currCommand.printHelp(indent, descOffset, currArgs, prevArgs);
+ }
+ else
+ {
+ String cmdName = getNameFromStack(prevArgs);
+ out.error("\"" + arg + "\" is not a sub-command of \"" + cmdName + "\"");
+ return;
+ }
+ }
+
+ private String getNameFromStack(Stack args)
+ {
+ String cmdName = "";
+ while (!args.isEmpty())
+ {
+ String currArg = (String)args.pop();
+ if (currArg.endsWith("/")) {
+ cmdName = currArg + cmdName;
+ } else {
+ cmdName = currArg + " " + cmdName;
+ }
+ }
+ if (cmdName.length() > 0 && cmdName.endsWith(" "))
+ {
+ cmdName = cmdName.substring(0, cmdName.length() - 1);
+ }
+ return cmdName;
+ }
+
+ private String formatDesc(String sDesc)
+ {
+ int nIndent = 8;
+
+ // note: lines _always_ start with "\t " (the space is intentional) since
+ // every word is prefixed by a space
+ String sIndent = "\t";
+
+ int nWrapIndent = 3;
+ String sWrapIndent = " ";
+
+ int nWidth = 80;
+ char[] aDesc = sDesc.toCharArray();
+ String formatted = "";
+
+ formatted += sIndent;
+ int charsInLine = nIndent;
+ String currWord;
+ int i = 0;
+
+ while (i < aDesc.length)
+ {
+ currWord = "";
+ for (;i < aDesc.length && '\n' != aDesc[i] && ' ' != aDesc[i]; i++)
+ {
+ currWord += aDesc[i];
+ }
+ // advance another character, past the '\n' or ' '; otherwise we get stuck
+ // in an infinite loop
+ i++;
+
+ int currWordLength = currWord.length() + 1; // the 1 is for the added space
+ if (currWordLength + charsInLine > nWidth)
+ {
+ // start a new line
+ formatted += "\n";
+ formatted += sIndent;
+ formatted += sWrapIndent;
+ charsInLine = nIndent + nWrapIndent;
+ }
+
+ // add the word to the current line
+ formatted += " " + currWord;
+ charsInLine += currWordLength;
+
+ // if the character directly following the last word read is a new-line
+ // character, start a new line
+ if (i <= aDesc.length && '\n' == aDesc[i-1])
+ {
+ // start a new line
+ formatted += "\n";
+ formatted += sIndent;
+ charsInLine = nIndent;
+ }
+ }
+
+ return formatted;
+ }
+
+ public void doCommand(Stack args, Image loadedImage, HashMap properties){
+ boolean found = false;
+ String nextCommand = null;
+
+ if (!args.isEmpty())
+ {
+ nextCommand = (String)args.pop();
+ }
+ else
+ {
+ out.error("specified command requires additional subcommand");
+ return;
+ }
+ nextCommand = nextCommand.toLowerCase();
+
+ Command currCommand = null;
+ Iterator itCommand = child_commands.iterator();
+ while (itCommand.hasNext() && !found)
+ {
+ currCommand = (Command)itCommand.next();
+ if (nextCommand.equals(currCommand.getName()))
+ found = true;
+ }
+
+ if (found){
+ currCommand.doCommand(args, loadedImage, properties);
+ }
+ else{
+ out.error("command \"" + nextCommand + "\" does not exist; type \"help\" " +
+ "for a list of available commands");
+ return;
+ }
+ }
+
+ protected void doScrollCommand(Image loadedImage, HashMap properties, boolean direction){
+ RootCommand rootCommand = (RootCommand)properties.get(Utils.RootCommand_OBJECT);
+ if (null == rootCommand){
+ out.error("ERROR - No mapping found for RootCommand object");
+ return;
+ }
+
+ Long currentMemAddress = (Long)properties.get(Utils.CURRENT_MEM_ADDRESS);
+ Integer currentNumBytesToPrint = (Integer)properties.get(Utils.CURRENT_NUM_BYTES_TO_PRINT);
+ if (null == currentMemAddress || null == currentNumBytesToPrint){
+ out.error("ERROR - starting mem address or the number of bytes to print needs to be set " +
+ "by running hexdump command");
+ return;
+ }
+
+ //out.println("*******" + Long.toHexString( ((Long)properties.get(Utils.CURRENT_MEM_ADDRESS)).longValue() ));
+
+ long newMemAddrss;
+ if (direction)
+ newMemAddrss = currentMemAddress.longValue() + currentNumBytesToPrint.intValue();
+ else
+ newMemAddrss = currentMemAddress.longValue() - currentNumBytesToPrint.intValue();
+
+ Stack plusCommandStack = Utils.constructStackFromString("hexdump" + " "
+ + Long.toHexString(newMemAddrss) + " " + currentNumBytesToPrint.toString());
+
+ rootCommand.doCommand(plusCommandStack, loadedImage, properties);
+
+ properties.put(Utils.CURRENT_MEM_ADDRESS, new Long(newMemAddrss));
+ }
+}
+
Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/Command.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/DeadlockCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/DeadlockCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/DeadlockCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/DeadlockCommand.java Mon Nov 23 15:53:48 2009
@@ -1,324 +1,324 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.katoview.commands;
-
-import java.util.HashMap;
-import java.util.Stack;
-import java.util.Iterator;
-import java.util.TreeMap;
-import java.util.SortedMap;
-import java.util.Vector;
-
-import javax.tools.diagnostics.image.*;
-import javax.tools.diagnostics.runtime.java.*;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.helpers.Exceptions;
-import org.apache.kato.katoview.commands.helpers.MonitorNode;
-import org.apache.kato.katoview.commands.helpers.NodeList;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class DeadlockCommand extends Command {
-
- public DeadlockCommand(Output o){
- super(o, "deadlock", "displays information about deadlocks if there are any",
- "parameters: none\n\n" +
- "The \"deadlock\" command shows detailed information about deadlocks " +
- "or \"no deadlocks detected\" if there are no deadlocks. A deadlock " +
- "situation consists of one or more deadlock loops and zero or more " +
- "branches attached to those loops. This command prints out each " +
- "branch attached to a loop and then the loop itself. If there is a " +
- "split in a deadlock branch, separate branches will be created for " +
- "each side of the split in the branch. Deadlock branches start with " +
- "a monitor that has no threads waiting on it and the continues until " +
- "it reaches a monitor that exists in another deadlock branch or loop. " +
- "Deadlock loops start and end with the same monitor.\n\n" +
- "Monitors are represented by their owner and the object associated with " +
- "the given monitor. For example, \"3435 (0x45ae67)\" represents the " +
- "monitor that is owned by the thread with id 3435 and is associated " +
- "the object at address 0x45ae67. Objects can be viewed by using a " +
- "command like \"x/j 0x45ae67\" and threads can be viewed using a " +
- "command like \"info thread 3435\".\n"
- );
- child_commands = null;
- }
-
- public void doCommand(Stack args, Image loadedImage, HashMap properties)
- {
- Iterator itRuntime = Utils.getRuntimes(loadedImage);
-
- int jrnum = 1;
- while (itRuntime.hasNext())
- {
- SortedMap monitorNodes = new TreeMap();
- JavaRuntime jr = (JavaRuntime)itRuntime.next();
- Iterator itMonitor = jr.getMonitors().iterator();
- int nodeListNum = 0;
-
- out.print("\n deadlocks for runtime #" + jrnum + "\n");
-
- // Step 1. iterate over all monitors, creating a MonitorNode for each monitor that
- // contains the monitor (JavaMonitor) and some parameters and adding that MonitorNode
- // to a Hashtable, indexed by owner (JavaThread object address)
- while (itMonitor.hasNext()) {
- JavaMonitor monitor = (JavaMonitor)itMonitor.next();
- MonitorNode node = new MonitorNode(monitor);
- JavaThread owner = null;
- Long id = null;
-
- try {
- owner = monitor.getOwner();
- } catch (CorruptDataException e) {
- out.error("exception encountered while getting monitor owner: " +
- Exceptions.getCorruptDataExceptionString());
- return;
- }
-
- if (null == owner) {
- // A monitor with no owner cannot be involved in a deadlock, according to the
- // algorithm used here anyway, because in order for a monitor to be in a deadlock,
- // its owner must be in a deadlock or an owner somewhere down the chain of
- // ownership must own the given monitor. Since there is no owner, we can't get
- // the monitor's owner or the next monitor in a potential deadlock chain.
- continue;
- } else {
- JavaObject threadObject;
- try {
- threadObject = owner.getObject();
- } catch (CorruptDataException e) {
- out.error("exception encountered while getting owner's JavaObject: " +
- Exceptions.getCorruptDataExceptionString());
- return;
- }
- id = new Long(threadObject.getID().getAddress());
- }
-
- // Note: we used to give up here with an error if there was already
- // a monitor node in the table with the same key (thread). This is very common (a
- // thread owning multiple monitors).
- monitorNodes.put(id, node);
- }
-
- Iterator values = monitorNodes.values().iterator();
-
- // Step 2. iterate over Hashtable and for every MonitorNode, iterate over monitor m1's
- // enter waiters (JavaMonitor.getEnterWaiters()), which are JavaThreads, and for each
- // enter waiter, set that waiter's MonitorNode's waitingOn to m1.
- while (values.hasNext()) {
- MonitorNode currNode = (MonitorNode)values.next();
- JavaMonitor currMonitor = currNode.getMonitor();
-
- Iterator itWaiters = currMonitor.getEnterWaiters().iterator();
- while (itWaiters.hasNext()) {
- JavaThread waiter = (JavaThread)itWaiters.next();
- JavaObject threadObject;
- Long id = null;
-
- try {
- threadObject = waiter.getObject();
- } catch (CorruptDataException e) {
- out.error("exception encountered while getting waiter's ImageThread: " +
- Exceptions.getCorruptDataExceptionString());
- return;
- }
-
- id = new Long(threadObject.getID().getAddress());
-
- MonitorNode waiterNode = (MonitorNode)monitorNodes.get(id);
- if (null != waiterNode) {
- waiterNode.waitingOn = currNode;
- }
- }
- }
-
- values = monitorNodes.values().iterator();
- int visit = 1;
- Vector lists = new Vector();
-
- // Step 3. iterate over Hashtable and for every MonitorNode m1:
- // Step 3a. set a unique visit number, visit > 0 (visit++ would work)
- // Step 3b. iterate over waitingOns, setting visit number, until a null
- // waitingOn is reached (no deadlock), a deadlocked node is reached
- // (m1 is part of a branch that joins a deadlock loop), or a node with
- // the same visit is reached (m1 is part of a deadlock loop)
- // Step 3c. if deadlock found, start at m1 and iterate over all
- // waitingOns until a deadlocked node is found, setting deadlock
- // (branch or loop, depending on result in 3b) along the way
-
- // note: Step 4* are not laid out precisely as specified; the instructions
- // listed for Step 4* are integrated into Step 3
-
- // Step 4. for each MonitorNode m1 where inList == false and m1 is part
- // of a deadlock loop *, create a new list and push it on the list
- // stack right away:
- // Step 4a. iterate over all enter waiters, setting inList to true at
- // every MonitorNode
- // Step 4b. if there are no enter waiters, terminate the current list
- // Step 4c. if there is one enter waiter: if the enter waiter is the
- // current list, stop; else continue creating the current list,
- // iterating to that thread's MonitorNode
- // Step 4d. if there is more than one enter waiter, continue creating
- // current list and start a new list, pushing it on the list stack
- // right away
-
- while (values.hasNext())
- {
- MonitorNode startNode = (MonitorNode)values.next();
- MonitorNode currNode = startNode;
- MonitorNode endNode;
-
- if (0 != startNode.visit)
- {
- continue;
- }
-
- while (true)
- {
- currNode.visit = visit;
-
- if (null == currNode.waitingOn)
- {
- currNode.deadlock = MonitorNode.NO_DEADLOCK;
- break;
- }
-
- if (isDeadlocked(currNode.waitingOn))
- {
- // we've encountered a deadlocked node in the chain;
- // set branch deadlock for all nodes between startNode
- // and currNode
-
- endNode = currNode.waitingOn;
- currNode = startNode;
- NodeList branchList = null;
- while (currNode != endNode)
- {
- if (null == branchList)
- {
- branchList = new NodeList(currNode, nodeListNum++);
- }
- currNode.deadlock = MonitorNode.BRANCH_DEADLOCK;
- currNode = currNode.waitingOn;
- branchList.add(currNode);
- if (currNode != endNode)
- currNode.inList = branchList;
- }
-
- if (endNode.inList.isLoop())
- {
- lists.insertElementAt(branchList, lists.indexOf(endNode.inList));
- }
- else
- {
- NodeList oldList = endNode.inList;
-
- // FIXME: the below line will cause problems with at least
- // one case that was not considered when attachOrSplit was
- // coded: if a NodeList n1 has already been split and another
- // NodeList n2 tries to attach to the end of n1, then n1 will
- // allow n2 to attach to n1, while what n1 should really do is
- // just return n2 and not allow n2 to attach to itself
- NodeList split = endNode.inList.attachOrSplit(branchList, nodeListNum++);
- if (null != split)
- {
- lists.insertElementAt(split, lists.indexOf(oldList));
- lists.insertElementAt(branchList, lists.indexOf(oldList));
- }
- }
- break;
- }
-
- if (currNode.waitingOn.visit == visit)
- {
- // we've encountered a node in the same visit as the current
- // visit, ie. we've found a loop; first flag the whole loop
- // with a loop deadlock flag, then flag the rest of the nodes
- // in the chain with a branch deadlock
-
- endNode = currNode.waitingOn;
- currNode = endNode;
- NodeList loopList = new NodeList(currNode, nodeListNum++);
- lists.insertElementAt(loopList, 0);
-
- do
- {
- currNode.deadlock = MonitorNode.LOOP_DEADLOCK;
- currNode = currNode.waitingOn;
- loopList.add(currNode);
- currNode.inList = loopList;
- } while (currNode != endNode);
-
- currNode = startNode;
- NodeList branchList = null;
- while (currNode != endNode)
- {
- if (null == branchList)
- {
- branchList = new NodeList(currNode, nodeListNum++);
- lists.insertElementAt(branchList, 0);
- }
- currNode.deadlock = MonitorNode.BRANCH_DEADLOCK;
- currNode = currNode.waitingOn;
- branchList.add(currNode);
- if (currNode != endNode)
- currNode.inList = branchList;
- }
- break;
- }
-
- currNode = currNode.waitingOn;
- }
-
- visit++;
- }
-
- if (lists.isEmpty())
- {
- out.print("\n");
- out.print("\t no deadlocks detected");
- out.print("\n");
- return;
- }
-
- boolean lastListWasLoop = true;
- Iterator itList = lists.iterator();
-
- // Step 5. print the lists
- while (itList.hasNext())
- {
- NodeList list = (NodeList)itList.next();
-
- if (list.isLoop()) {
- out.print("\n deadlock loop:\n");
- lastListWasLoop = true;
- } else if (lastListWasLoop) { // && !list.isLoop()
- out.print("\n\n deadlock branch(es):\n");
- lastListWasLoop = false;
- }
-
- out.print("\t " + list.toString());
- out.print("\n");
- }
- out.print("\n");
- jrnum++;
- }
- }
-
- private boolean isDeadlocked(MonitorNode node)
- {
- return MonitorNode.LOOP_DEADLOCK == node.deadlock ||
- MonitorNode.BRANCH_DEADLOCK == node.deadlock;
- }
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.katoview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+import java.util.Iterator;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.Vector;
+
+import javax.tools.diagnostics.image.*;
+import javax.tools.diagnostics.runtime.java.*;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.helpers.Exceptions;
+import org.apache.kato.katoview.commands.helpers.MonitorNode;
+import org.apache.kato.katoview.commands.helpers.NodeList;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class DeadlockCommand extends Command {
+
+ public DeadlockCommand(Output o){
+ super(o, "deadlock", "displays information about deadlocks if there are any",
+ "parameters: none\n\n" +
+ "The \"deadlock\" command shows detailed information about deadlocks " +
+ "or \"no deadlocks detected\" if there are no deadlocks. A deadlock " +
+ "situation consists of one or more deadlock loops and zero or more " +
+ "branches attached to those loops. This command prints out each " +
+ "branch attached to a loop and then the loop itself. If there is a " +
+ "split in a deadlock branch, separate branches will be created for " +
+ "each side of the split in the branch. Deadlock branches start with " +
+ "a monitor that has no threads waiting on it and the continues until " +
+ "it reaches a monitor that exists in another deadlock branch or loop. " +
+ "Deadlock loops start and end with the same monitor.\n\n" +
+ "Monitors are represented by their owner and the object associated with " +
+ "the given monitor. For example, \"3435 (0x45ae67)\" represents the " +
+ "monitor that is owned by the thread with id 3435 and is associated " +
+ "the object at address 0x45ae67. Objects can be viewed by using a " +
+ "command like \"x/j 0x45ae67\" and threads can be viewed using a " +
+ "command like \"info thread 3435\".\n"
+ );
+ child_commands = null;
+ }
+
+ public void doCommand(Stack args, Image loadedImage, HashMap properties)
+ {
+ Iterator itRuntime = Utils.getRuntimes(loadedImage);
+
+ int jrnum = 1;
+ while (itRuntime.hasNext())
+ {
+ SortedMap monitorNodes = new TreeMap();
+ JavaRuntime jr = (JavaRuntime)itRuntime.next();
+ Iterator itMonitor = jr.getMonitors().iterator();
+ int nodeListNum = 0;
+
+ out.print("\n deadlocks for runtime #" + jrnum + "\n");
+
+ // Step 1. iterate over all monitors, creating a MonitorNode for each monitor that
+ // contains the monitor (JavaMonitor) and some parameters and adding that MonitorNode
+ // to a Hashtable, indexed by owner (JavaThread object address)
+ while (itMonitor.hasNext()) {
+ JavaMonitor monitor = (JavaMonitor)itMonitor.next();
+ MonitorNode node = new MonitorNode(monitor);
+ JavaThread owner = null;
+ Long id = null;
+
+ try {
+ owner = monitor.getOwner();
+ } catch (CorruptDataException e) {
+ out.error("exception encountered while getting monitor owner: " +
+ Exceptions.getCorruptDataExceptionString());
+ return;
+ }
+
+ if (null == owner) {
+ // A monitor with no owner cannot be involved in a deadlock, according to the
+ // algorithm used here anyway, because in order for a monitor to be in a deadlock,
+ // its owner must be in a deadlock or an owner somewhere down the chain of
+ // ownership must own the given monitor. Since there is no owner, we can't get
+ // the monitor's owner or the next monitor in a potential deadlock chain.
+ continue;
+ } else {
+ JavaObject threadObject;
+ try {
+ threadObject = owner.getObject();
+ } catch (CorruptDataException e) {
+ out.error("exception encountered while getting owner's JavaObject: " +
+ Exceptions.getCorruptDataExceptionString());
+ return;
+ }
+ id = new Long(threadObject.getID().getAddress());
+ }
+
+ // Note: we used to give up here with an error if there was already
+ // a monitor node in the table with the same key (thread). This is very common (a
+ // thread owning multiple monitors).
+ monitorNodes.put(id, node);
+ }
+
+ Iterator values = monitorNodes.values().iterator();
+
+ // Step 2. iterate over Hashtable and for every MonitorNode, iterate over monitor m1's
+ // enter waiters (JavaMonitor.getEnterWaiters()), which are JavaThreads, and for each
+ // enter waiter, set that waiter's MonitorNode's waitingOn to m1.
+ while (values.hasNext()) {
+ MonitorNode currNode = (MonitorNode)values.next();
+ JavaMonitor currMonitor = currNode.getMonitor();
+
+ Iterator itWaiters = currMonitor.getEnterWaiters().iterator();
+ while (itWaiters.hasNext()) {
+ JavaThread waiter = (JavaThread)itWaiters.next();
+ JavaObject threadObject;
+ Long id = null;
+
+ try {
+ threadObject = waiter.getObject();
+ } catch (CorruptDataException e) {
+ out.error("exception encountered while getting waiter's ImageThread: " +
+ Exceptions.getCorruptDataExceptionString());
+ return;
+ }
+
+ id = new Long(threadObject.getID().getAddress());
+
+ MonitorNode waiterNode = (MonitorNode)monitorNodes.get(id);
+ if (null != waiterNode) {
+ waiterNode.waitingOn = currNode;
+ }
+ }
+ }
+
+ values = monitorNodes.values().iterator();
+ int visit = 1;
+ Vector lists = new Vector();
+
+ // Step 3. iterate over Hashtable and for every MonitorNode m1:
+ // Step 3a. set a unique visit number, visit > 0 (visit++ would work)
+ // Step 3b. iterate over waitingOns, setting visit number, until a null
+ // waitingOn is reached (no deadlock), a deadlocked node is reached
+ // (m1 is part of a branch that joins a deadlock loop), or a node with
+ // the same visit is reached (m1 is part of a deadlock loop)
+ // Step 3c. if deadlock found, start at m1 and iterate over all
+ // waitingOns until a deadlocked node is found, setting deadlock
+ // (branch or loop, depending on result in 3b) along the way
+
+ // note: Step 4* are not laid out precisely as specified; the instructions
+ // listed for Step 4* are integrated into Step 3
+
+ // Step 4. for each MonitorNode m1 where inList == false and m1 is part
+ // of a deadlock loop *, create a new list and push it on the list
+ // stack right away:
+ // Step 4a. iterate over all enter waiters, setting inList to true at
+ // every MonitorNode
+ // Step 4b. if there are no enter waiters, terminate the current list
+ // Step 4c. if there is one enter waiter: if the enter waiter is the
+ // current list, stop; else continue creating the current list,
+ // iterating to that thread's MonitorNode
+ // Step 4d. if there is more than one enter waiter, continue creating
+ // current list and start a new list, pushing it on the list stack
+ // right away
+
+ while (values.hasNext())
+ {
+ MonitorNode startNode = (MonitorNode)values.next();
+ MonitorNode currNode = startNode;
+ MonitorNode endNode;
+
+ if (0 != startNode.visit)
+ {
+ continue;
+ }
+
+ while (true)
+ {
+ currNode.visit = visit;
+
+ if (null == currNode.waitingOn)
+ {
+ currNode.deadlock = MonitorNode.NO_DEADLOCK;
+ break;
+ }
+
+ if (isDeadlocked(currNode.waitingOn))
+ {
+ // we've encountered a deadlocked node in the chain;
+ // set branch deadlock for all nodes between startNode
+ // and currNode
+
+ endNode = currNode.waitingOn;
+ currNode = startNode;
+ NodeList branchList = null;
+ while (currNode != endNode)
+ {
+ if (null == branchList)
+ {
+ branchList = new NodeList(currNode, nodeListNum++);
+ }
+ currNode.deadlock = MonitorNode.BRANCH_DEADLOCK;
+ currNode = currNode.waitingOn;
+ branchList.add(currNode);
+ if (currNode != endNode)
+ currNode.inList = branchList;
+ }
+
+ if (endNode.inList.isLoop())
+ {
+ lists.insertElementAt(branchList, lists.indexOf(endNode.inList));
+ }
+ else
+ {
+ NodeList oldList = endNode.inList;
+
+ // FIXME: the below line will cause problems with at least
+ // one case that was not considered when attachOrSplit was
+ // coded: if a NodeList n1 has already been split and another
+ // NodeList n2 tries to attach to the end of n1, then n1 will
+ // allow n2 to attach to n1, while what n1 should really do is
+ // just return n2 and not allow n2 to attach to itself
+ NodeList split = endNode.inList.attachOrSplit(branchList, nodeListNum++);
+ if (null != split)
+ {
+ lists.insertElementAt(split, lists.indexOf(oldList));
+ lists.insertElementAt(branchList, lists.indexOf(oldList));
+ }
+ }
+ break;
+ }
+
+ if (currNode.waitingOn.visit == visit)
+ {
+ // we've encountered a node in the same visit as the current
+ // visit, ie. we've found a loop; first flag the whole loop
+ // with a loop deadlock flag, then flag the rest of the nodes
+ // in the chain with a branch deadlock
+
+ endNode = currNode.waitingOn;
+ currNode = endNode;
+ NodeList loopList = new NodeList(currNode, nodeListNum++);
+ lists.insertElementAt(loopList, 0);
+
+ do
+ {
+ currNode.deadlock = MonitorNode.LOOP_DEADLOCK;
+ currNode = currNode.waitingOn;
+ loopList.add(currNode);
+ currNode.inList = loopList;
+ } while (currNode != endNode);
+
+ currNode = startNode;
+ NodeList branchList = null;
+ while (currNode != endNode)
+ {
+ if (null == branchList)
+ {
+ branchList = new NodeList(currNode, nodeListNum++);
+ lists.insertElementAt(branchList, 0);
+ }
+ currNode.deadlock = MonitorNode.BRANCH_DEADLOCK;
+ currNode = currNode.waitingOn;
+ branchList.add(currNode);
+ if (currNode != endNode)
+ currNode.inList = branchList;
+ }
+ break;
+ }
+
+ currNode = currNode.waitingOn;
+ }
+
+ visit++;
+ }
+
+ if (lists.isEmpty())
+ {
+ out.print("\n");
+ out.print("\t no deadlocks detected");
+ out.print("\n");
+ return;
+ }
+
+ boolean lastListWasLoop = true;
+ Iterator itList = lists.iterator();
+
+ // Step 5. print the lists
+ while (itList.hasNext())
+ {
+ NodeList list = (NodeList)itList.next();
+
+ if (list.isLoop()) {
+ out.print("\n deadlock loop:\n");
+ lastListWasLoop = true;
+ } else if (lastListWasLoop) { // && !list.isLoop()
+ out.print("\n\n deadlock branch(es):\n");
+ lastListWasLoop = false;
+ }
+
+ out.print("\t " + list.toString());
+ out.print("\n");
+ }
+ out.print("\n");
+ jrnum++;
+ }
+ }
+
+ private boolean isDeadlocked(MonitorNode node)
+ {
+ return MonitorNode.LOOP_DEADLOCK == node.deadlock ||
+ MonitorNode.BRANCH_DEADLOCK == node.deadlock;
+ }
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/DeadlockCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/ExitCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/ExitCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/ExitCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/ExitCommand.java Mon Nov 23 15:53:48 2009
@@ -1,44 +1,44 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.katoview.commands;
-
-import java.util.HashMap;
-import java.util.Stack;
-
-import javax.tools.diagnostics.image.Image;
-
-import org.apache.kato.katoview.Output;
-
-
-public class ExitCommand extends Command {
-
- public ExitCommand(Output o){
- super(o, "exit", "exits the core file viewing tool",
- "parameters: none\n\n" +
- "exits the core file viewing tool; any log files that are " +
- "currently open will be closed prior to exit\n"
- );
- child_commands = null;
- }
-
- public void doCommand(Stack args, Image loadedImage, HashMap properties){
- if (!args.isEmpty())
- {
- out.error("\"exit\" does not take any parameters");
- return;
- }
- // pass 'quit' back up to Session.run()
- properties.put("quit", "on");
- }
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.katoview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+
+import javax.tools.diagnostics.image.Image;
+
+import org.apache.kato.katoview.Output;
+
+
+public class ExitCommand extends Command {
+
+ public ExitCommand(Output o){
+ super(o, "exit", "exits the core file viewing tool",
+ "parameters: none\n\n" +
+ "exits the core file viewing tool; any log files that are " +
+ "currently open will be closed prior to exit\n"
+ );
+ child_commands = null;
+ }
+
+ public void doCommand(Stack args, Image loadedImage, HashMap properties){
+ if (!args.isEmpty())
+ {
+ out.error("\"exit\" does not take any parameters");
+ return;
+ }
+ // pass 'quit' back up to Session.run()
+ properties.put("quit", "on");
+ }
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/ExitCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindCommand.java Mon Nov 23 15:53:48 2009
@@ -1,296 +1,296 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.katoview.commands;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Stack;
-
-import javax.tools.diagnostics.image.CorruptDataException;
-import javax.tools.diagnostics.image.Image;
-import javax.tools.diagnostics.image.ImagePointer;
-import javax.tools.diagnostics.image.ImageSection;
-import javax.tools.diagnostics.image.MemoryAccessException;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class FindCommand extends Command{
-
- static final int text = 1;
- static final int binary = 2;
-
- /*args for the find command must be comma separated
- * e.g. find cpu,0,21665f64,64,16,30
- */
- FindAttribute findAtt = new FindAttribute();
- StringBuffer sb = new StringBuffer();
- ArrayList matches = new ArrayList();
-
- public FindCommand(Output o){
- super(o, "find", "searches memory for a given string",
- "parameters, comma separated: " +
- "<pattern>,<start_address>,<end_address>,<memory_boundary>,<bytes_to_print>,<matches_to_display>\n\n" +
- "the find command searches for <pattern> in the memory segment from <start_address> to <end_address> inclusive, " +
- "matching only addresses that start at the specified <memory_boundary>, for example 1,2,4 or 8 bytes. It " +
- "displays <bytes_to_print> bytes from the final match, and lists the first <matches_to_display> matches found." +
- "\n example: find pattern,,,,64,3"
- );
- child_commands = null;
- }
-
- public void doCommand(Stack args, Image loadedImage, HashMap properties){
- String argsConcact = Utils.concatArgsFromStack(args);
- String[] params = argsConcact.split(",", -1);
- sb = new StringBuffer();
- matches.clear();
- if (!isParametersValid(args, params)) return;
- determineModeFromPattern();
- if (!parseParams(args, params)) return;
- Iterator imageSections = Utils.getAddressSapceSectionInfo(loadedImage);
-
- while(imageSections.hasNext()){
- if (matches.size() > findAtt.numMatchesToDisplay) break;
- ImageSection imageSection = (ImageSection)imageSections.next();
- if (scanImageSection(imageSection)) break;
- }
- if (matches.size() > 0)
- findAtt.lastMatch = ((Long)matches.get(matches.size()-1)).longValue();
- properties.put(Utils.FIND_ATTRIBUTES, findAtt);
- doPrint();
- if (matches.size() > 0)
- printLastMatchContent(loadedImage, properties);
-
- //preppend "0x" back to pattern for findnext command
- restoreHexPrefix();
- }
-
- private void restoreHexPrefix(){
- if (findAtt.mode == binary)
- findAtt.pattern = "0x" + findAtt.pattern;
- }
-
- private void printLastMatchContent(Image loadedImage, HashMap properties){
- RootCommand rootCommand = (RootCommand)properties.get(Utils.RootCommand_OBJECT);
- if (null == rootCommand){
- out.error("ERROR - No mapping found for RootCommand object");
- return;
- }
- Stack hexdumpCommandStack = Utils.constructStackFromString("hexdump" + " "
- + Long.toHexString(findAtt.lastMatch) + " "
- + findAtt.numBytesToPrint);
- rootCommand.doCommand(hexdumpCommandStack, loadedImage, properties);
- }
-
- private void doPrint(){
- int size = matches.size();
- if(0 == size){
- sb.append("No matches found.\n");
- }
- else{
- int limit = Math.min(findAtt.numMatchesToDisplay, size);
- for(int i = 0; i < limit; i++){
- long match = ((Long)matches.get(i)).longValue();
- sb.append("#" + i + ": " + "0x" + Long.toHexString(match) + "\n");
- }
- }
- out.print(new String(sb));
- }
-
- private boolean scanImageSection(ImageSection imageSection){
- long imageStartAddress = imageSection.getBaseAddress().getAddress();
- long imageEndAddress = imageStartAddress + imageSection.getSize() - 1;
- if (findAtt.startAddress < imageStartAddress && findAtt.endAddress < imageStartAddress){
- return false;
- }
- else if(findAtt.startAddress > imageEndAddress && findAtt.endAddress > imageEndAddress){
- return false;
- }
- else if(findAtt.startAddress >= imageStartAddress && findAtt.endAddress <= imageEndAddress){
- return scanRegion(findAtt.startAddress, findAtt.endAddress, imageSection);
- }
- else if(findAtt.startAddress <= imageStartAddress && findAtt.endAddress <= imageEndAddress
- && findAtt.endAddress >= imageStartAddress){
- return scanRegion(imageStartAddress, findAtt.endAddress, imageSection);
- }
- else if(findAtt.startAddress <= imageEndAddress && findAtt.startAddress >= imageStartAddress
- && findAtt.endAddress >= imageEndAddress){
- return scanRegion(findAtt.startAddress, imageEndAddress, imageSection);
- }
- else{
- return scanRegion(imageStartAddress, imageEndAddress, imageSection);
- }
- }
-
- private boolean scanRegion(long start, long end, ImageSection imageSection){
- ImagePointer imagePointer = imageSection.getBaseAddress();
- long i;
- if (0 != start%findAtt.boundary) {
- i = start - start%findAtt.boundary + findAtt.boundary;
- } else {
- i = start;
- }
- int patternLength = findAtt.length();
- byte[] bytes = findAtt.getBytes();
-
- for(; i <= end; i+=findAtt.boundary){
- int j;
- for(j = 0; j < patternLength; j++){
- byte oneByte = bytes[j];
- if (getByteFromImage(imagePointer, i+j) == oneByte){
- continue;
- }
- else {
- break;
- }
- }
- if (j >= patternLength){
- matches.add(new Long(i));
- if (matches.size() == findAtt.numMatchesToDisplay)
- return true;
- }
- }
- return false;
- }
-
- private byte getByteFromImage(ImagePointer imagePointer, long address){
- long imagePointerBaseAddress = imagePointer.getAddress();
- try{
- return imagePointer.getByteAt(address-imagePointerBaseAddress);
- }catch(CorruptDataException cde){
- return 0;
- }catch(MemoryAccessException mae){
- out.error("MemoryAccessException occurred at 0x" + Long.toHexString(address));
- return 0;
- }
- }
-
- private boolean parseParams(Stack args, String[] params) {
- if (params[1].equals("")) {
- findAtt.startAddress = 0;
- } else {
- findAtt.startAddress = Utils.longFromString(params[1]).longValue();
- }
-
- if (params[2].equals("")) {
- //TODO how to convert to "unsigned" long
- findAtt.endAddress = Long.MAX_VALUE;
- } else {
- findAtt.endAddress = Utils.longFromString(params[2]).longValue();
- }
-
- if (findAtt.startAddress > findAtt.endAddress) {
- out.error("start address must not be greater than end address");
- printHelp("\t",10,new Stack(),args);
- return false;
- }
-
- if (params[3].equals("")) {
- findAtt.boundary = 1;
- } else {
- findAtt.boundary = Integer.parseInt(params[3]);
- if (findAtt.boundary <= 0) {
- out.error("memory boundary must be a positive non-zero value");
- printHelp("\t",10,new Stack(),args);
- return false;
- }
- }
-
- if (params[4].equals("")) {
- findAtt.numBytesToPrint = 256;
- } else {
- findAtt.numBytesToPrint = Integer.parseInt(params[4]);
- if (findAtt.numBytesToPrint < 0) {
- out.error("bytes to print must be a non-negative value");
- printHelp("\t",10,new Stack(),args);
- return false;
- }
- }
-
- if (params[5].equals("")) {
- findAtt.numMatchesToDisplay = 1;
- } else {
- findAtt.numMatchesToDisplay = Integer.parseInt(params[5]);
- if (findAtt.numMatchesToDisplay < 0) {
- out.error("matches to display must be a non-negative value");
- printHelp("\t",10,new Stack(),args);
- return false;
- }
- }
- return true;
- }
-
- private void determineModeFromPattern(){
- if (findAtt.pattern.startsWith("0x")) {
- findAtt.pattern = findAtt.pattern.substring(2);
- findAtt.mode = binary;
- allignBits();
- }
- else{
- findAtt.mode = text;
- }
- }
-
- private void allignBits(){
- int patternLength = findAtt.pattern.length();
- if (0 != patternLength%2){
- findAtt.pattern = "0" + findAtt.pattern;
- }
- }
-
- private boolean isParametersValid(Stack args, String[] params){
- if (6 != params.length){
- out.error("incorrect number of parameters");
- printHelp("\t",10,new Stack(),args);
- return false;
- }
- findAtt.pattern = params[0];
- if (findAtt.pattern.equals("")) {
- out.error("missing search pattern string");
- printHelp("\t",10,new Stack(),args);
- return false;
- }
- return true;
- }
-
- class FindAttribute{
- String pattern;
- long startAddress, endAddress;
- int boundary, numBytesToPrint, numMatchesToDisplay;
- long lastMatch;
- int mode;
-
- public int length() {
- if (mode == binary) {
- return pattern.length() / 2;
- } else {
- return pattern.length();
- }
- }
-
- public byte[] getBytes() {
- if (mode == text) {
- return pattern.getBytes();
- } else {
- byte[] result = new byte[length()];
- for (int i = 0; i < length(); i++) {
- result[i] = (byte)Integer.parseInt(pattern.substring(i*2, i*2+2), 16);
- }
- return result;
- }
- }
- }
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.katoview.commands;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Stack;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.ImageSection;
+import javax.tools.diagnostics.image.MemoryAccessException;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class FindCommand extends Command{
+
+ static final int text = 1;
+ static final int binary = 2;
+
+ /*args for the find command must be comma separated
+ * e.g. find cpu,0,21665f64,64,16,30
+ */
+ FindAttribute findAtt = new FindAttribute();
+ StringBuffer sb = new StringBuffer();
+ ArrayList matches = new ArrayList();
+
+ public FindCommand(Output o){
+ super(o, "find", "searches memory for a given string",
+ "parameters, comma separated: " +
+ "<pattern>,<start_address>,<end_address>,<memory_boundary>,<bytes_to_print>,<matches_to_display>\n\n" +
+ "the find command searches for <pattern> in the memory segment from <start_address> to <end_address> inclusive, " +
+ "matching only addresses that start at the specified <memory_boundary>, for example 1,2,4 or 8 bytes. It " +
+ "displays <bytes_to_print> bytes from the final match, and lists the first <matches_to_display> matches found." +
+ "\n example: find pattern,,,,64,3"
+ );
+ child_commands = null;
+ }
+
+ public void doCommand(Stack args, Image loadedImage, HashMap properties){
+ String argsConcact = Utils.concatArgsFromStack(args);
+ String[] params = argsConcact.split(",", -1);
+ sb = new StringBuffer();
+ matches.clear();
+ if (!isParametersValid(args, params)) return;
+ determineModeFromPattern();
+ if (!parseParams(args, params)) return;
+ Iterator imageSections = Utils.getAddressSapceSectionInfo(loadedImage);
+
+ while(imageSections.hasNext()){
+ if (matches.size() > findAtt.numMatchesToDisplay) break;
+ ImageSection imageSection = (ImageSection)imageSections.next();
+ if (scanImageSection(imageSection)) break;
+ }
+ if (matches.size() > 0)
+ findAtt.lastMatch = ((Long)matches.get(matches.size()-1)).longValue();
+ properties.put(Utils.FIND_ATTRIBUTES, findAtt);
+ doPrint();
+ if (matches.size() > 0)
+ printLastMatchContent(loadedImage, properties);
+
+ //preppend "0x" back to pattern for findnext command
+ restoreHexPrefix();
+ }
+
+ private void restoreHexPrefix(){
+ if (findAtt.mode == binary)
+ findAtt.pattern = "0x" + findAtt.pattern;
+ }
+
+ private void printLastMatchContent(Image loadedImage, HashMap properties){
+ RootCommand rootCommand = (RootCommand)properties.get(Utils.RootCommand_OBJECT);
+ if (null == rootCommand){
+ out.error("ERROR - No mapping found for RootCommand object");
+ return;
+ }
+ Stack hexdumpCommandStack = Utils.constructStackFromString("hexdump" + " "
+ + Long.toHexString(findAtt.lastMatch) + " "
+ + findAtt.numBytesToPrint);
+ rootCommand.doCommand(hexdumpCommandStack, loadedImage, properties);
+ }
+
+ private void doPrint(){
+ int size = matches.size();
+ if(0 == size){
+ sb.append("No matches found.\n");
+ }
+ else{
+ int limit = Math.min(findAtt.numMatchesToDisplay, size);
+ for(int i = 0; i < limit; i++){
+ long match = ((Long)matches.get(i)).longValue();
+ sb.append("#" + i + ": " + "0x" + Long.toHexString(match) + "\n");
+ }
+ }
+ out.print(new String(sb));
+ }
+
+ private boolean scanImageSection(ImageSection imageSection){
+ long imageStartAddress = imageSection.getBaseAddress().getAddress();
+ long imageEndAddress = imageStartAddress + imageSection.getSize() - 1;
+ if (findAtt.startAddress < imageStartAddress && findAtt.endAddress < imageStartAddress){
+ return false;
+ }
+ else if(findAtt.startAddress > imageEndAddress && findAtt.endAddress > imageEndAddress){
+ return false;
+ }
+ else if(findAtt.startAddress >= imageStartAddress && findAtt.endAddress <= imageEndAddress){
+ return scanRegion(findAtt.startAddress, findAtt.endAddress, imageSection);
+ }
+ else if(findAtt.startAddress <= imageStartAddress && findAtt.endAddress <= imageEndAddress
+ && findAtt.endAddress >= imageStartAddress){
+ return scanRegion(imageStartAddress, findAtt.endAddress, imageSection);
+ }
+ else if(findAtt.startAddress <= imageEndAddress && findAtt.startAddress >= imageStartAddress
+ && findAtt.endAddress >= imageEndAddress){
+ return scanRegion(findAtt.startAddress, imageEndAddress, imageSection);
+ }
+ else{
+ return scanRegion(imageStartAddress, imageEndAddress, imageSection);
+ }
+ }
+
+ private boolean scanRegion(long start, long end, ImageSection imageSection){
+ ImagePointer imagePointer = imageSection.getBaseAddress();
+ long i;
+ if (0 != start%findAtt.boundary) {
+ i = start - start%findAtt.boundary + findAtt.boundary;
+ } else {
+ i = start;
+ }
+ int patternLength = findAtt.length();
+ byte[] bytes = findAtt.getBytes();
+
+ for(; i <= end; i+=findAtt.boundary){
+ int j;
+ for(j = 0; j < patternLength; j++){
+ byte oneByte = bytes[j];
+ if (getByteFromImage(imagePointer, i+j) == oneByte){
+ continue;
+ }
+ else {
+ break;
+ }
+ }
+ if (j >= patternLength){
+ matches.add(new Long(i));
+ if (matches.size() == findAtt.numMatchesToDisplay)
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private byte getByteFromImage(ImagePointer imagePointer, long address){
+ long imagePointerBaseAddress = imagePointer.getAddress();
+ try{
+ return imagePointer.getByteAt(address-imagePointerBaseAddress);
+ }catch(CorruptDataException cde){
+ return 0;
+ }catch(MemoryAccessException mae){
+ out.error("MemoryAccessException occurred at 0x" + Long.toHexString(address));
+ return 0;
+ }
+ }
+
+ private boolean parseParams(Stack args, String[] params) {
+ if (params[1].equals("")) {
+ findAtt.startAddress = 0;
+ } else {
+ findAtt.startAddress = Utils.longFromString(params[1]).longValue();
+ }
+
+ if (params[2].equals("")) {
+ //TODO how to convert to "unsigned" long
+ findAtt.endAddress = Long.MAX_VALUE;
+ } else {
+ findAtt.endAddress = Utils.longFromString(params[2]).longValue();
+ }
+
+ if (findAtt.startAddress > findAtt.endAddress) {
+ out.error("start address must not be greater than end address");
+ printHelp("\t",10,new Stack(),args);
+ return false;
+ }
+
+ if (params[3].equals("")) {
+ findAtt.boundary = 1;
+ } else {
+ findAtt.boundary = Integer.parseInt(params[3]);
+ if (findAtt.boundary <= 0) {
+ out.error("memory boundary must be a positive non-zero value");
+ printHelp("\t",10,new Stack(),args);
+ return false;
+ }
+ }
+
+ if (params[4].equals("")) {
+ findAtt.numBytesToPrint = 256;
+ } else {
+ findAtt.numBytesToPrint = Integer.parseInt(params[4]);
+ if (findAtt.numBytesToPrint < 0) {
+ out.error("bytes to print must be a non-negative value");
+ printHelp("\t",10,new Stack(),args);
+ return false;
+ }
+ }
+
+ if (params[5].equals("")) {
+ findAtt.numMatchesToDisplay = 1;
+ } else {
+ findAtt.numMatchesToDisplay = Integer.parseInt(params[5]);
+ if (findAtt.numMatchesToDisplay < 0) {
+ out.error("matches to display must be a non-negative value");
+ printHelp("\t",10,new Stack(),args);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void determineModeFromPattern(){
+ if (findAtt.pattern.startsWith("0x")) {
+ findAtt.pattern = findAtt.pattern.substring(2);
+ findAtt.mode = binary;
+ allignBits();
+ }
+ else{
+ findAtt.mode = text;
+ }
+ }
+
+ private void allignBits(){
+ int patternLength = findAtt.pattern.length();
+ if (0 != patternLength%2){
+ findAtt.pattern = "0" + findAtt.pattern;
+ }
+ }
+
+ private boolean isParametersValid(Stack args, String[] params){
+ if (6 != params.length){
+ out.error("incorrect number of parameters");
+ printHelp("\t",10,new Stack(),args);
+ return false;
+ }
+ findAtt.pattern = params[0];
+ if (findAtt.pattern.equals("")) {
+ out.error("missing search pattern string");
+ printHelp("\t",10,new Stack(),args);
+ return false;
+ }
+ return true;
+ }
+
+ class FindAttribute{
+ String pattern;
+ long startAddress, endAddress;
+ int boundary, numBytesToPrint, numMatchesToDisplay;
+ long lastMatch;
+ int mode;
+
+ public int length() {
+ if (mode == binary) {
+ return pattern.length() / 2;
+ } else {
+ return pattern.length();
+ }
+ }
+
+ public byte[] getBytes() {
+ if (mode == text) {
+ return pattern.getBytes();
+ } else {
+ byte[] result = new byte[length()];
+ for (int i = 0; i < length(); i++) {
+ result[i] = (byte)Integer.parseInt(pattern.substring(i*2, i*2+2), 16);
+ }
+ return result;
+ }
+ }
+ }
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindNextCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindNextCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindNextCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindNextCommand.java Mon Nov 23 15:53:48 2009
@@ -1,60 +1,60 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.katoview.commands;
-
-import java.util.HashMap;
-import java.util.Stack;
-
-import javax.tools.diagnostics.image.Image;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class FindNextCommand extends Command{
- public FindNextCommand(Output o){
- super(o, "findnext", "finds the next instance of the last string passed to \"find\"",
- "parameters: none\n\n" +
- "The findnext command is used in conjunction with find or findptr command " +
- "to continue searching for upcoming matches. It repeats " +
- "the previous find or findptr command (depending on which command is " +
- "most recently issued) starting from the last match."
- );
- child_commands = null;
- }
-
- public void doCommand(Stack args, Image loadedImage, HashMap properties){
- RootCommand rootCommand = (RootCommand)properties.get(Utils.RootCommand_OBJECT);
- if (null == rootCommand){
- out.error("ERROR - No mapping found for RootCommand object");
- return;
- }
-
- FindCommand.FindAttribute findAtt = (FindCommand.FindAttribute)properties.get(Utils.FIND_ATTRIBUTES);
- if (null == findAtt){
- out.println("No find command has been executed.");
- return;
- }
-
- String startAddress = Long.toHexString((findAtt.lastMatch + 1));
- String endAddress = Long.toHexString(findAtt.endAddress);
-
- Stack findCommandStack = Utils.constructStackFromString("find" + " "
- + findAtt.pattern + "," + startAddress + ","
- + endAddress + "," + findAtt.boundary + ","
- + findAtt.numBytesToPrint + "," + findAtt.numMatchesToDisplay);
-
- rootCommand.doCommand(findCommandStack, loadedImage, properties);
- }
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.katoview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+
+import javax.tools.diagnostics.image.Image;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class FindNextCommand extends Command{
+ public FindNextCommand(Output o){
+ super(o, "findnext", "finds the next instance of the last string passed to \"find\"",
+ "parameters: none\n\n" +
+ "The findnext command is used in conjunction with find or findptr command " +
+ "to continue searching for upcoming matches. It repeats " +
+ "the previous find or findptr command (depending on which command is " +
+ "most recently issued) starting from the last match."
+ );
+ child_commands = null;
+ }
+
+ public void doCommand(Stack args, Image loadedImage, HashMap properties){
+ RootCommand rootCommand = (RootCommand)properties.get(Utils.RootCommand_OBJECT);
+ if (null == rootCommand){
+ out.error("ERROR - No mapping found for RootCommand object");
+ return;
+ }
+
+ FindCommand.FindAttribute findAtt = (FindCommand.FindAttribute)properties.get(Utils.FIND_ATTRIBUTES);
+ if (null == findAtt){
+ out.println("No find command has been executed.");
+ return;
+ }
+
+ String startAddress = Long.toHexString((findAtt.lastMatch + 1));
+ String endAddress = Long.toHexString(findAtt.endAddress);
+
+ Stack findCommandStack = Utils.constructStackFromString("find" + " "
+ + findAtt.pattern + "," + startAddress + ","
+ + endAddress + "," + findAtt.boundary + ","
+ + findAtt.numBytesToPrint + "," + findAtt.numMatchesToDisplay);
+
+ rootCommand.doCommand(findCommandStack, loadedImage, properties);
+ }
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindNextCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindPtrCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindPtrCommand.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindPtrCommand.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindPtrCommand.java Mon Nov 23 15:53:48 2009
@@ -1,98 +1,98 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.katoview.commands;
-
-import java.util.HashMap;
-import java.util.Stack;
-
-import javax.tools.diagnostics.image.Image;
-
-import org.apache.kato.katoview.Output;
-import org.apache.kato.katoview.commands.helpers.Utils;
-
-
-public class FindPtrCommand extends Command{
-
- String pattern;
-
- public FindPtrCommand(Output out){
- super(out, "findptr", "searches memory for the given pointer",
- "parameters: see parameters for \"find\" command\n\n" +
- "the findptr command searches for <pattern> as a pointer in the memory segment from <start_address> to <end_address> (both inclusive), " +
- "and outputs the first <matches_to_display> matching addresses that start at the corresponding <memory_boundary>. " +
- "It also display the next <bytes_to_print> bytes for the last match.");
- child_commands = null;
- }
-
- public void doCommand(Stack args, Image loadedImage, HashMap properties){
- RootCommand rootCommand = (RootCommand)properties.get(Utils.RootCommand_OBJECT);
- if (null == rootCommand){
- out.error("ERROR - No mapping found for RootCommand object");
- return;
- }
- String argsConcact = Utils.concatArgsFromStack(args);
- //TODO split consecutive <,>
- String[] params = argsConcact.split(",");
- if (!isParametersValid(params)) return;
- if(isLittleEndian())
- pattern = reorderBytes();
- String parameters = getparameters(params);
-
- out.println("issuing: find" + " " + parameters);
-
- Stack findCommandStack = Utils.constructStackFromString("find" + " " + parameters);
- rootCommand.doCommand(findCommandStack, loadedImage, properties);
- //out.println(pattern);
- }
-
- private String getparameters(String[] params){
- String temp = "0x" + pattern;
- for(int i = 1; i < params.length; i++){
- temp+=(","+params[i]);
- }
- return temp;
- }
-
- private String reorderBytes(){
- if (0 != pattern.length()%2)
- pattern = "0" + pattern;
- String temp = "";
- for (int i = pattern.length()/2 - 1; i >= 0; i--){
- temp+=pattern.substring(i*2,i*2+2);
- }
- return temp;
- }
-
- private boolean isLittleEndian(){
- //TODO implement this method once the API is available
- return true;
- }
-
- private boolean isParametersValid(String[] params){
- if (6 != params.length){
- out.error("insufficient number of parameters");
- return false;
- }
- pattern = params[0];
- if (pattern.equals("")) {
- out.error("missing pattern string");
- return false;
- }
-
- if (pattern.startsWith("0x")) {
- pattern = pattern.substring(2);
- }
- return true;
- }
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.katoview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+
+import javax.tools.diagnostics.image.Image;
+
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.helpers.Utils;
+
+
+public class FindPtrCommand extends Command{
+
+ String pattern;
+
+ public FindPtrCommand(Output out){
+ super(out, "findptr", "searches memory for the given pointer",
+ "parameters: see parameters for \"find\" command\n\n" +
+ "the findptr command searches for <pattern> as a pointer in the memory segment from <start_address> to <end_address> (both inclusive), " +
+ "and outputs the first <matches_to_display> matching addresses that start at the corresponding <memory_boundary>. " +
+ "It also display the next <bytes_to_print> bytes for the last match.");
+ child_commands = null;
+ }
+
+ public void doCommand(Stack args, Image loadedImage, HashMap properties){
+ RootCommand rootCommand = (RootCommand)properties.get(Utils.RootCommand_OBJECT);
+ if (null == rootCommand){
+ out.error("ERROR - No mapping found for RootCommand object");
+ return;
+ }
+ String argsConcact = Utils.concatArgsFromStack(args);
+ //TODO split consecutive <,>
+ String[] params = argsConcact.split(",");
+ if (!isParametersValid(params)) return;
+ if(isLittleEndian())
+ pattern = reorderBytes();
+ String parameters = getparameters(params);
+
+ out.println("issuing: find" + " " + parameters);
+
+ Stack findCommandStack = Utils.constructStackFromString("find" + " " + parameters);
+ rootCommand.doCommand(findCommandStack, loadedImage, properties);
+ //out.println(pattern);
+ }
+
+ private String getparameters(String[] params){
+ String temp = "0x" + pattern;
+ for(int i = 1; i < params.length; i++){
+ temp+=(","+params[i]);
+ }
+ return temp;
+ }
+
+ private String reorderBytes(){
+ if (0 != pattern.length()%2)
+ pattern = "0" + pattern;
+ String temp = "";
+ for (int i = pattern.length()/2 - 1; i >= 0; i--){
+ temp+=pattern.substring(i*2,i*2+2);
+ }
+ return temp;
+ }
+
+ private boolean isLittleEndian(){
+ //TODO implement this method once the API is available
+ return true;
+ }
+
+ private boolean isParametersValid(String[] params){
+ if (6 != params.length){
+ out.error("insufficient number of parameters");
+ return false;
+ }
+ pattern = params[0];
+ if (pattern.equals("")) {
+ out.error("missing pattern string");
+ return false;
+ }
+
+ if (pattern.startsWith("0x")) {
+ pattern = pattern.substring(2);
+ }
+ return true;
+ }
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tools.katoview/src/main/java/org/apache/kato/katoview/commands/FindPtrCommand.java
------------------------------------------------------------------------------
svn:eol-style = native