84 import sun.jvm.hotspot.ui.tree.CTypeTreeNodeAdapter;
85 import sun.jvm.hotspot.ui.tree.OopTreeNodeAdapter;
86 import sun.jvm.hotspot.ui.tree.SimpleTreeNode;
87 import sun.jvm.hotspot.utilities.AddressOps;
88 import sun.jvm.hotspot.utilities.Assert;
89 import sun.jvm.hotspot.utilities.HeapProgressThunk;
90 import sun.jvm.hotspot.utilities.LivenessPathElement;
91 import sun.jvm.hotspot.utilities.MethodArray;
92 import sun.jvm.hotspot.utilities.ObjectReader;
93 import sun.jvm.hotspot.utilities.PointerFinder;
94 import sun.jvm.hotspot.utilities.PointerLocation;
95 import sun.jvm.hotspot.utilities.ReversePtrs;
96 import sun.jvm.hotspot.utilities.ReversePtrsAnalysis;
97 import sun.jvm.hotspot.utilities.RobustOopDeterminator;
98 import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
99 import sun.jvm.hotspot.utilities.soql.JSJavaFactory;
100 import sun.jvm.hotspot.utilities.soql.JSJavaFactoryImpl;
101 import sun.jvm.hotspot.utilities.soql.JSJavaScriptEngine;
102
103 public class CommandProcessor {
104 public abstract static class DebuggerInterface {
105 public abstract HotSpotAgent getAgent();
106 public abstract boolean isAttached();
107 public abstract void attach(String pid);
108 public abstract void attach(String java, String core);
109 public abstract void detach();
110 public abstract void reattach();
111 }
112
113 public static class BootFilter implements ClassFilter {
114 public boolean canInclude(InstanceKlass kls) {
115 return kls.getClassLoader() == null;
116 }
117 }
118
119 public static class NonBootFilter implements ClassFilter {
120 private HashMap emitted = new HashMap();
121 public boolean canInclude(InstanceKlass kls) {
122 if (kls.getClassLoader() == null) return false;
123 if (emitted.get(kls.getName()) != null) {
1118 PMap pmap = new PMap();
1119 pmap.run(out, debugger.getAgent().getDebugger());
1120 }
1121 },
1122 new Command("pstack", "pstack [-v]", false) {
1123 public void doit(Tokens t) {
1124 boolean verbose = false;
1125 if (t.countTokens() > 0 && t.nextToken().equals("-v")) {
1126 verbose = true;
1127 }
1128 PStack pstack = new PStack(verbose, true);
1129 pstack.run(out, debugger.getAgent().getDebugger());
1130 }
1131 },
1132 new Command("quit", true) {
1133 public void doit(Tokens t) {
1134 if (t.countTokens() != 0) {
1135 usage();
1136 } else {
1137 debugger.detach();
1138 System.exit(0);
1139 }
1140 }
1141 },
1142 new Command("echo", "echo [ true | false ]", true) {
1143 public void doit(Tokens t) {
1144 if (t.countTokens() == 0) {
1145 out.println("echo is " + doEcho);
1146 } else if (t.countTokens() == 1) {
1147 doEcho = Boolean.valueOf(t.nextToken()).booleanValue();
1148 } else {
1149 usage();
1150 }
1151 }
1152 },
1153 new Command("versioncheck", "versioncheck [ true | false ]", true) {
1154 public void doit(Tokens t) {
1155 if (t.countTokens() == 0) {
1156 out.println("versioncheck is " +
1157 (System.getProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck") == null));
1158 } else if (t.countTokens() == 1) {
1697
1698 // called before debuggee attach
1699 private void preAttach() {
1700 // nothing for now..
1701 }
1702
1703 // called after debuggee attach
1704 private void postAttach() {
1705 // create JavaScript engine and start it
1706 jsengine = new JSJavaScriptEngine() {
1707 private ObjectReader reader = new ObjectReader();
1708 private JSJavaFactory factory = new JSJavaFactoryImpl();
1709 public ObjectReader getObjectReader() {
1710 return reader;
1711 }
1712 public JSJavaFactory getJSJavaFactory() {
1713 return factory;
1714 }
1715 protected void quit() {
1716 debugger.detach();
1717 System.exit(0);
1718 }
1719 protected BufferedReader getInputReader() {
1720 return in;
1721 }
1722 protected PrintStream getOutputStream() {
1723 return out;
1724 }
1725 protected PrintStream getErrorStream() {
1726 return err;
1727 }
1728 };
1729 try {
1730 jsengine.defineFunction(this,
1731 this.getClass().getMethod("registerCommand",
1732 new Class[] {
1733 String.class, String.class, String.class
1734 }));
1735 } catch (NoSuchMethodException exp) {
1736 // should not happen, see below...!!
1737 exp.printStackTrace();
1764 this.debugger = debugger;
1765 this.agent = debugger.getAgent();
1766 this.in = in;
1767 this.out = out;
1768 this.err = err;
1769 for (int i = 0; i < commandList.length; i++) {
1770 Command c = commandList[i];
1771 if (commands.get(c.name) != null) {
1772 throw new InternalError(c.name + " has multiple definitions");
1773 }
1774 commands.put(c.name, c);
1775 }
1776 if (debugger.isAttached()) {
1777 postAttach();
1778 }
1779 }
1780
1781
1782 public void run(boolean prompt) {
1783 // Process interactive commands.
1784 while (true) {
1785 if (prompt) printPrompt();
1786 String ln = null;
1787 try {
1788 ln = in.readLine();
1789 } catch (IOException e) {
1790 }
1791 if (ln == null) {
1792 if (prompt) err.println("Input stream closed.");
1793 return;
1794 }
1795
1796 executeCommand(ln, prompt);
1797 }
1798 }
1799
1800 static Pattern historyPattern = Pattern.compile("((!\\*)|(!\\$)|(!!-?)|(!-?[0-9][0-9]*)|(![a-zA-Z][^ ]*))");
1801
1802 public void executeCommand(String ln, boolean putInHistory) {
1803 if (ln.indexOf('!') != -1) {
1804 int size = history.size();
|
84 import sun.jvm.hotspot.ui.tree.CTypeTreeNodeAdapter;
85 import sun.jvm.hotspot.ui.tree.OopTreeNodeAdapter;
86 import sun.jvm.hotspot.ui.tree.SimpleTreeNode;
87 import sun.jvm.hotspot.utilities.AddressOps;
88 import sun.jvm.hotspot.utilities.Assert;
89 import sun.jvm.hotspot.utilities.HeapProgressThunk;
90 import sun.jvm.hotspot.utilities.LivenessPathElement;
91 import sun.jvm.hotspot.utilities.MethodArray;
92 import sun.jvm.hotspot.utilities.ObjectReader;
93 import sun.jvm.hotspot.utilities.PointerFinder;
94 import sun.jvm.hotspot.utilities.PointerLocation;
95 import sun.jvm.hotspot.utilities.ReversePtrs;
96 import sun.jvm.hotspot.utilities.ReversePtrsAnalysis;
97 import sun.jvm.hotspot.utilities.RobustOopDeterminator;
98 import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
99 import sun.jvm.hotspot.utilities.soql.JSJavaFactory;
100 import sun.jvm.hotspot.utilities.soql.JSJavaFactoryImpl;
101 import sun.jvm.hotspot.utilities.soql.JSJavaScriptEngine;
102
103 public class CommandProcessor {
104
105 volatile boolean quit;
106
107 public abstract static class DebuggerInterface {
108 public abstract HotSpotAgent getAgent();
109 public abstract boolean isAttached();
110 public abstract void attach(String pid);
111 public abstract void attach(String java, String core);
112 public abstract void detach();
113 public abstract void reattach();
114 }
115
116 public static class BootFilter implements ClassFilter {
117 public boolean canInclude(InstanceKlass kls) {
118 return kls.getClassLoader() == null;
119 }
120 }
121
122 public static class NonBootFilter implements ClassFilter {
123 private HashMap emitted = new HashMap();
124 public boolean canInclude(InstanceKlass kls) {
125 if (kls.getClassLoader() == null) return false;
126 if (emitted.get(kls.getName()) != null) {
1121 PMap pmap = new PMap();
1122 pmap.run(out, debugger.getAgent().getDebugger());
1123 }
1124 },
1125 new Command("pstack", "pstack [-v]", false) {
1126 public void doit(Tokens t) {
1127 boolean verbose = false;
1128 if (t.countTokens() > 0 && t.nextToken().equals("-v")) {
1129 verbose = true;
1130 }
1131 PStack pstack = new PStack(verbose, true);
1132 pstack.run(out, debugger.getAgent().getDebugger());
1133 }
1134 },
1135 new Command("quit", true) {
1136 public void doit(Tokens t) {
1137 if (t.countTokens() != 0) {
1138 usage();
1139 } else {
1140 debugger.detach();
1141 quit = true;
1142 }
1143 }
1144 },
1145 new Command("echo", "echo [ true | false ]", true) {
1146 public void doit(Tokens t) {
1147 if (t.countTokens() == 0) {
1148 out.println("echo is " + doEcho);
1149 } else if (t.countTokens() == 1) {
1150 doEcho = Boolean.valueOf(t.nextToken()).booleanValue();
1151 } else {
1152 usage();
1153 }
1154 }
1155 },
1156 new Command("versioncheck", "versioncheck [ true | false ]", true) {
1157 public void doit(Tokens t) {
1158 if (t.countTokens() == 0) {
1159 out.println("versioncheck is " +
1160 (System.getProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck") == null));
1161 } else if (t.countTokens() == 1) {
1700
1701 // called before debuggee attach
1702 private void preAttach() {
1703 // nothing for now..
1704 }
1705
1706 // called after debuggee attach
1707 private void postAttach() {
1708 // create JavaScript engine and start it
1709 jsengine = new JSJavaScriptEngine() {
1710 private ObjectReader reader = new ObjectReader();
1711 private JSJavaFactory factory = new JSJavaFactoryImpl();
1712 public ObjectReader getObjectReader() {
1713 return reader;
1714 }
1715 public JSJavaFactory getJSJavaFactory() {
1716 return factory;
1717 }
1718 protected void quit() {
1719 debugger.detach();
1720 quit = true;
1721 }
1722 protected BufferedReader getInputReader() {
1723 return in;
1724 }
1725 protected PrintStream getOutputStream() {
1726 return out;
1727 }
1728 protected PrintStream getErrorStream() {
1729 return err;
1730 }
1731 };
1732 try {
1733 jsengine.defineFunction(this,
1734 this.getClass().getMethod("registerCommand",
1735 new Class[] {
1736 String.class, String.class, String.class
1737 }));
1738 } catch (NoSuchMethodException exp) {
1739 // should not happen, see below...!!
1740 exp.printStackTrace();
1767 this.debugger = debugger;
1768 this.agent = debugger.getAgent();
1769 this.in = in;
1770 this.out = out;
1771 this.err = err;
1772 for (int i = 0; i < commandList.length; i++) {
1773 Command c = commandList[i];
1774 if (commands.get(c.name) != null) {
1775 throw new InternalError(c.name + " has multiple definitions");
1776 }
1777 commands.put(c.name, c);
1778 }
1779 if (debugger.isAttached()) {
1780 postAttach();
1781 }
1782 }
1783
1784
1785 public void run(boolean prompt) {
1786 // Process interactive commands.
1787 while (!quit) {
1788 if (prompt) printPrompt();
1789 String ln = null;
1790 try {
1791 ln = in.readLine();
1792 } catch (IOException e) {
1793 }
1794 if (ln == null) {
1795 if (prompt) err.println("Input stream closed.");
1796 return;
1797 }
1798
1799 executeCommand(ln, prompt);
1800 }
1801 }
1802
1803 static Pattern historyPattern = Pattern.compile("((!\\*)|(!\\$)|(!!-?)|(!-?[0-9][0-9]*)|(![a-zA-Z][^ ]*))");
1804
1805 public void executeCommand(String ln, boolean putInHistory) {
1806 if (ln.indexOf('!') != -1) {
1807 int size = history.size();
|