incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccris...@apache.org
Subject svn commit: r754949 [1/5] - in /incubator/kato/trunk/import/org.apache.kato.tools.katoview: ./ .settings/ src/ src/com/ src/com/ibm/ src/com/ibm/dtfj/ src/com/ibm/dtfj/dtfjview/ src/com/ibm/dtfj/dtfjview/commands/ src/com/ibm/dtfj/dtfjview/commands/hel...
Date Mon, 16 Mar 2009 16:43:31 GMT
Author: ccristal
Date: Mon Mar 16 16:43:29 2009
New Revision: 754949

URL: http://svn.apache.org/viewvc?rev=754949&view=rev
Log:
Initial code contribution from IBM.

Added:
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/.classpath
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/.cvsignore
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/.project
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/.settings/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/.settings/org.eclipse.jdt.core.prefs
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/ConsoleOutputChannel.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/DTFJView.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/FileOutputChannel.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Output.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/OutputChannel.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Session.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Version.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/CdCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/Command.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/DeadlockCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/ExitCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindNextCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindPtrCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/HeapdumpCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/HelpCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/HexdumpCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/InfoCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/MinusCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/PlusCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/PwdCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/QuitCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/RootCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/SetCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/ShowCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/WhatisCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/XCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/ClassOutput.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Exceptions.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorNode.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/MonitorState.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/NodeList.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/StateToString.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/ThreadData.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/helpers/Utils.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoClassCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoHeapCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoJitmCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoLockCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoMmapCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoProcCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoSymCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoSystemCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/infocommands/InfoThreadCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/setcommands/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/setcommands/SetHeapdumpCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/setcommands/SetLoggingCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/showcommands/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/showcommands/ShowHeapdumpCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/showcommands/ShowLoggingCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/xcommands/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/xcommands/XDCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/xcommands/XJCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/xcommands/XKCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/xcommands/XXCommand.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/heapdump/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/heapdump/HeapDumpFormatter.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/heapdump/HeapDumpSettings.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/heapdump/LongArrayReferenceIterator.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/heapdump/LongListReferenceIterator.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/heapdump/ReferenceIterator.java
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/heapdump/classic/
    incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/heapdump/classic/ClassicHeapDumpFormatter.java

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/.classpath
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/.classpath?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/.classpath (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/.classpath Mon Mar 16 16:43:29 2009
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry combineaccessrules="false" kind="src" path="/org.apache.kato.api"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/.cvsignore
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/.cvsignore?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/.cvsignore (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/.cvsignore Mon Mar 16 16:43:29 2009
@@ -0,0 +1 @@
+bin

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/.project
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/.project?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/.project (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/.project Mon Mar 16 16:43:29 2009
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.kato.tools.katoview</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/.settings/org.eclipse.jdt.core.prefs?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/.settings/org.eclipse.jdt.core.prefs Mon Mar 16 16:43:29 2009
@@ -0,0 +1,12 @@
+#Sat Jul 05 12:52:01 BST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/ConsoleOutputChannel.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/ConsoleOutputChannel.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/ConsoleOutputChannel.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/ConsoleOutputChannel.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview;
+
+public class ConsoleOutputChannel implements OutputChannel {
+	
+	private boolean noPrint = false;
+
+	public void print(String outputString) {
+		if (!noPrint)
+			System.out.print(outputString);
+	}
+
+	public void printPrompt(String prompt) {
+		System.out.print(prompt);
+	}
+
+	public void println(String outputString) {
+		if (!noPrint)
+			System.out.println(outputString);
+	}
+
+	public void error(String outputString) {
+		System.err.print("\n");
+		System.err.print("\tERROR: " + outputString + "\n");
+	}
+
+	public void printInput(long timestamp, String prompt, String outputString) {
+		// we don't need to output anything, but we could output the time the command was started
+		//System.out.println("<started at: " + (new Date(timestamp)).toString() + ">");
+	}
+	
+	public void close() {
+		// do nothing, because we don't need to close System.out or System.err
+	}
+	
+	public void setNoPrint(boolean b) {
+		noPrint = b;
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/DTFJView.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/DTFJView.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/DTFJView.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/DTFJView.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview;
+
+
+public class DTFJView {
+
+	private Session session;
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		DTFJView dtfjView = new DTFJView();
+		dtfjView.session = new Session(args);
+		
+		dtfjView.session.run();
+		
+		
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/FileOutputChannel.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/FileOutputChannel.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/FileOutputChannel.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/FileOutputChannel.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Date;
+
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+
+public class FileOutputChannel implements OutputChannel {
+	
+	private FileWriter fw;
+
+	// f must not be null
+	public FileOutputChannel(FileWriter f)
+	{
+		fw = f;
+	}
+
+	public void print(String outputString) {
+		try {
+			fw.write(Utils.toString(outputString));
+		} catch (IOException e) {
+			
+		}
+	}
+
+	public void printPrompt(String prompt) {
+		// do nothing; we'll output the prompt when we get a printInput() call
+	}
+
+	public void println(String outputString) {
+		try {
+			fw.write(Utils.toString(outputString) + "\n");
+		} catch (IOException e) {
+			
+		}
+	}
+
+	public void error(String outputString) {
+		try {
+			fw.write("\n");
+			fw.write("\tERROR: " + Utils.toString(outputString) + "\n");
+			fw.write("\n");
+		} catch (IOException e) {
+			
+		}
+	}
+
+	public void printInput(long timestamp, String prompt, String outputString) {
+		try {
+			fw.write((new Date(timestamp)).toString() + " " +
+					prompt + Utils.toString(outputString) + "\n");
+		} catch (IOException e) {
+			
+		}
+	}
+	
+	public void close() {
+		try {
+			fw.close();
+		} catch (IOException e) {
+			
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Output.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Output.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Output.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Output.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview;
+
+import java.util.Vector;
+
+public class Output {
+	
+	Vector outputChannels;
+	long lastTimestamp = 0;
+	String lastPrompt = "";
+	String lastInput = "";
+
+	public Output(){
+		outputChannels = new Vector();
+	}
+	
+	public void print(String outputString){
+		for (int i = 0; i < outputChannels.size(); i++){
+			((OutputChannel)outputChannels.elementAt(i)).print(outputString);
+		}
+	}
+	
+	public void printPrompt(String prompt){
+		for (int i = 0; i < outputChannels.size(); i++){
+			((OutputChannel)outputChannels.elementAt(i)).printPrompt(prompt);
+		}
+	}
+	
+	public void println(String outputString){
+		for (int i = 0; i < outputChannels.size(); i++){
+			((OutputChannel)outputChannels.elementAt(i)).println(outputString);
+		}
+	}
+	
+	public void error(String outputString){
+		for (int i = 0; i < outputChannels.size(); i++){
+			((OutputChannel)outputChannels.elementAt(i)).error(outputString);
+		}
+	}
+	
+	public void printInput(long timestamp, String prompt, String outputString){
+		for (int i = 0; i < outputChannels.size(); i++){
+			((OutputChannel)outputChannels.elementAt(i)).
+				printInput(timestamp, prompt, outputString);
+		}
+		lastTimestamp = timestamp;
+		lastPrompt = prompt;
+		lastInput = outputString;
+	}
+	
+	public void addChannel(OutputChannel channel){
+		addChannel(channel, false);
+	}
+	
+	public void addChannel(OutputChannel channel, boolean printLastInput){
+		outputChannels.add(channel);
+		if (printLastInput)
+			channel.printInput(lastTimestamp, lastPrompt, lastInput);
+	}
+	
+	public void removeFileChannel(){
+		for (int i = 0; i < outputChannels.size(); i++){
+			if ((OutputChannel)outputChannels.elementAt(i) instanceof FileOutputChannel)
+			{
+				((OutputChannel)outputChannels.elementAt(i)).close();
+				outputChannels.removeElementAt(i);
+			}
+		}
+	}
+	
+	public void setConsoleNoPrint(boolean noPrint){
+		for (int i = 0; i < outputChannels.size(); i++){
+			if ((OutputChannel)outputChannels.elementAt(i) instanceof ConsoleOutputChannel)
+			{
+				((ConsoleOutputChannel)outputChannels.elementAt(i)).setNoPrint(noPrint);
+			}
+		}
+	}
+	
+	public void close() {
+		for (int i = 0; i < outputChannels.size(); i++){
+			((OutputChannel)outputChannels.elementAt(i)).close();
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/OutputChannel.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/OutputChannel.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/OutputChannel.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/OutputChannel.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview;
+
+public interface OutputChannel {
+
+	public void print(String outputString);
+	public void printPrompt(String prompt);
+	public void println(String outputString);
+	public void error(String outputString);
+	public void printInput(long timestamp, String prompt, String outputString);
+	public void close();
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Session.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Session.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Session.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Session.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Stack;
+import java.util.HashMap;
+
+import com.ibm.dtfj.dtfjview.commands.RootCommand;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.image.ImageAddressSpace;
+import com.ibm.dtfj.image.ImageFactory;
+
+public class Session {
+
+	public static final String CORE_FILE_PATH_PROPERTY = "core_file_path";
+	private String factoryName;
+	private Image loadedImage;
+	private RootCommand rootCommand;
+	private HashMap variables;
+	private Output out;
+	
+	private static final String defaultFactoryName = ""; //TODO: assign proper factory class name 
+	private static final String factoryProperty = "com.ibm.dtfj.image.factoryclass";
+	private static final String launcherProperty = "com.ibm.jvm.dtfjview.launcher";
+	
+	public Session(String[] args) {
+		factoryName = System.getProperty(factoryProperty, defaultFactoryName);
+		sessionInit(args);
+	}
+
+	private void sessionInit(String[] args){
+		variables = new HashMap();
+		out = new Output();
+
+		out.addChannel(new ConsoleOutputChannel());
+		
+		rootCommand = new RootCommand(out);
+		/*add the root_command object to HashMap so that 
+		commands such as + and - can access it to invoke hexdump command*/
+		variables.put(Utils.RootCommand_OBJECT, rootCommand);
+		variables.put("pwd", new File(System.getProperty("user.dir")));
+		
+		loadedImage = imageFromCommandLine(args);
+	}
+	
+	private ImageFactory getFactory() {
+		try {
+			Class factoryClass = Class.forName(factoryName);
+			return (ImageFactory)factoryClass.newInstance();
+		} catch (ClassNotFoundException e) {
+			out.error("ClassNotFoundException while getting ImageFactory: " + e.getMessage());
+			out.error("Use -D" + factoryProperty + "=<classname> to change the ImageFactory");
+			return null;
+		} catch (InstantiationException e) {
+			out.error("InstantiationException while getting ImageFactory: " + e.getMessage());
+			return null;
+		} catch (IllegalAccessException e) {
+			out.error("IllegalAccessException while getting ImageFactory: " + e.getMessage());
+			return null;
+		}
+	}
+	
+	/**
+	 * @param args
+	 */
+	private Image imageFromCommandLine(String args[]) {
+		Image loadedImage = null;
+		int coreFilePathIndex = indexOf("-core", args)+1;
+		int xmlFilePathIndex = indexOf("-xml", args)+1;
+		int zipFilePathIndex = indexOf("-zip", args)+1;
+		int terseVersionIndex = indexOf("-v", args)+1;
+		int verboseVersionIndex = indexOf("--version", args)+1;
+		int verboseIndex = indexOf("-verbose", args)+1;
+
+		ImageFactory factory = getFactory();
+		if (factory == null) {
+			return null;
+		}
+		
+		if (0 != verboseIndex) {
+			variables.put("verbose.mode", "on");
+		}
+						
+		if ((0 != terseVersionIndex) || (0 != verboseVersionIndex)) {
+			out.println(Version.getAllVersionInfo(factory));
+			return null;
+		}
+		
+		String launcher = System.getProperty(launcherProperty, "dtfjview");
+		
+		// User must specify -zip or -core as parameter, and a dump filename following
+		if (((zipFilePathIndex == 0) && (coreFilePathIndex == 0)) ||
+			((0 != zipFilePathIndex) && (args.length <= zipFilePathIndex)) ||
+			((0 != coreFilePathIndex) && (args.length <= coreFilePathIndex))) {
+			out.print(
+				"\n\tUsage: \"" + launcher + " -core <core_file> [-xml <xml_file>]\" or \n" +
+				"\t \"" + launcher + " -zip <zip_file>\" or \n" +
+				"\t \"" + launcher + " --version\" or \"" + launcher + " -v\"\n\n");
+			return null;
+		}
+
+		out.println(Version.getAllVersionInfo(factory));
+		out.println("Loading image from DTFJ...\n");
+		
+		try {
+		    String coreFilePath = null;
+			if (0 != zipFilePathIndex) {
+			    coreFilePath = args[zipFilePathIndex];
+				loadedImage = factory.getImage(new File(coreFilePath));
+			} else if ((0 != coreFilePathIndex) && (0 == xmlFilePathIndex)) {
+			    coreFilePath = args[coreFilePathIndex];
+				loadedImage = factory.getImage(new File(coreFilePath));
+			} else if ((0 != coreFilePathIndex) && (0 != xmlFilePathIndex)) {
+			    coreFilePath = args[coreFilePathIndex];
+				loadedImage = factory.getImage(new File(coreFilePath), new File(args[xmlFilePathIndex]));
+			} 
+			//Store the core file/zip file path in the variables. We need it for creating default filenames for heapdumps
+			variables.put(CORE_FILE_PATH_PROPERTY, coreFilePath);
+		} catch (IOException e) {
+			out.error("Could not load dump file and/or could not load XML file: " + e.getMessage());
+			out.print(
+				"\tNote: " + launcher + " requires both core and XML files. If the -xml option\n" +
+				"\t is omitted the tool will search for the XML file based on the\n" +
+				"\t core filename.\n\n");
+			if (null != variables.get("verbose.mode")) {
+				e.printStackTrace();
+			}
+		}
+		
+		return loadedImage;
+	}
+
+	/**
+	 * @param string, args
+	 */
+	private int indexOf(String string, String[] args) {
+		int index = -1;
+		
+		for (int x = 0; x < args.length; x++) {
+			if (string.equals(args[x])) {
+				index = x;
+				break;
+			}
+		}
+		return index;
+	}
+	
+	public void run(){
+		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+		String input = "";
+		String quit = "";
+		String prompt = "> ";
+		Stack inputWordsStack = new Stack();
+		
+		if (null == loadedImage)
+			return;
+		
+		// FIXME: In the current code, this is the _only_ place where the current
+		//  address space is set.  Also, the only commands that use this value (at the
+		//  time of this writing, anyway) are the "x/k" command (XKCommand class) and
+		//  the "info thread" command.  What we would ideally like is some
+		//  sort of command that sets the current address space based on some sort of
+		//  identifier (there is currently no identifier; that would have to be built
+		//  into the DTFJ API).  Also, we would need all commands (at least those that
+		//  are dependent on accessing memory in an address space) to use this value;
+		//  currently only "x/k" and "info thread" use this, as stated above.  We don't
+		//  really know if multiple address spaces can actually exist in a given core
+		//  file, but this capability is put in here just in case they can.
+		
+		variables.put(
+				"current_address_space",
+				(ImageAddressSpace)loadedImage.getAddressSpaces().next()
+		);
+		
+		out.println("For a list of commands, type \"help\"; " +
+				"for how to use \"help\", type \"help help\"");
+
+		while (quit == null || !quit.equals("on"))
+		{
+			out.printPrompt(prompt);
+			
+			try {
+				input = stdin.readLine();
+			} catch (IOException e) {
+				out.error("IOException encountered while reading input; exiting program...");
+				break;
+			}
+			
+			if (null == input)
+			{
+				out.error("End of input stream has been reached; exiting program...");
+				break;
+			}
+			
+			String trimmedInput = input.trim();
+			out.printInput(System.currentTimeMillis(), prompt, input);
+			
+			if (!trimmedInput.equals(""))
+			{
+				inputWordsStack = Utils.constructStackFromString(trimmedInput);
+				try {
+					rootCommand.doCommand(inputWordsStack, loadedImage, variables);
+				} catch (RuntimeException e) {
+					out.error("An error occurred while processing the command: " + e);
+					e.printStackTrace();
+				}
+				quit = (String)variables.get("quit");
+			}
+		}
+		
+		// "out" MUST be closed here, otherwise the file deletions in the below
+		//  code block will not work
+		out.close();
+		
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Version.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Version.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Version.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/Version.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview;
+
+import com.ibm.dtfj.image.ImageFactory;
+
+public class Version {
+
+	private static int majorVersion = 1;
+	private static int minorVersion = 0;
+	private static int buildVersion = 24;
+	
+	private static String name = "DTFJView";
+	
+	public static String getVersion()
+	{
+		return Integer.toString(majorVersion) + "." +
+			Integer.toString(minorVersion) + "." +
+			Integer.toString(buildVersion);
+	}
+	
+	public static String getName()
+	{
+		return name;
+	}
+	
+	public static String getAllVersionInfo(ImageFactory factory)
+	{
+		String DTFJViewVersion = getName() + " version " + getVersion();
+		String DTFJAPIVersion = factory.getDTFJMajorVersion() + "." + factory.getDTFJMinorVersion();
+
+		return DTFJViewVersion + ", using DTFJ API version " + DTFJAPIVersion;
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/CdCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/CdCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/CdCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/CdCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+import java.io.File;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.Image;
+
+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);
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/Command.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/Command.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/Command.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/Command.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,304 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands;
+
+import java.util.HashMap;
+import java.util.Vector;
+import java.util.Stack;
+import java.util.Iterator;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.Image;
+
+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));
+	}
+}
+

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/DeadlockCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/DeadlockCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/DeadlockCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/DeadlockCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,322 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.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 com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.helpers.Exceptions;
+import com.ibm.dtfj.dtfjview.commands.helpers.MonitorNode;
+import com.ibm.dtfj.dtfjview.commands.helpers.NodeList;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.*;
+import com.ibm.dtfj.java.*;
+
+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();
+			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();
+				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;
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/ExitCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/ExitCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/ExitCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/ExitCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.image.Image;
+
+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");
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,294 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Stack;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.image.ImagePointer;
+import com.ibm.dtfj.image.ImageSection;
+import com.ibm.dtfj.image.MemoryAccessException;
+
+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;
+			}
+		}
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindNextCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindNextCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindNextCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindNextCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.Image;
+
+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);
+	}
+}

Added: incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindPtrCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindPtrCommand.java?rev=754949&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindPtrCommand.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tools.katoview/src/com/ibm/dtfj/dtfjview/commands/FindPtrCommand.java Mon Mar 16 16:43:29 2009
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.dtfjview.commands;
+
+import java.util.HashMap;
+import java.util.Stack;
+
+import com.ibm.dtfj.dtfjview.Output;
+import com.ibm.dtfj.dtfjview.commands.helpers.Utils;
+import com.ibm.dtfj.image.Image;
+
+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;
+	}
+}



Mime
View raw message