home *** CD-ROM | disk | FTP | other *** search
- package powersoft.debugger;
-
- import java.util.Vector;
- import sun.tools.debug.DebuggerCallback;
- import sun.tools.debug.RemoteClass;
- import sun.tools.debug.RemoteDebugger;
- import sun.tools.debug.RemoteDouble;
- import sun.tools.debug.RemoteField;
- import sun.tools.debug.RemoteFloat;
- import sun.tools.debug.RemoteThread;
- import sun.tools.debug.RemoteThreadGroup;
-
- public class Helper implements DebuggerCallback {
- private RemoteDebugger debugger;
- private RemoteThread currentThread;
- private Vector suspendedThreads = new Vector();
- private RemoteThreadGroup currentThreadGroup;
- private RemoteClass initialClass;
- private volatile RemoteField initialBreakpoint;
- private boolean taskCompleted = true;
- private boolean hitBreakpoint = true;
- private boolean hitTracepoint = true;
- private String exceptionText;
- private boolean inTrace = false;
- private boolean doDebug = false;
- private boolean doVerboseDebugger;
- private String debugFileName;
- private boolean firstPrint;
- private boolean gotQuitEvent;
-
- public synchronized native void PrintCallBack(String var1);
-
- // $FF: renamed from: gc () void
- void method_0() {
- System.gc();
- }
-
- RemoteDebugger StartDebugger(String host) {
- try {
- int dot = host.indexOf(58);
- if (dot != -1) {
- this.debugger = new RemoteDebugger(host.substring(0, dot), host.substring(dot + 1), this, this.doVerboseDebugger);
- } else {
- this.debugger = new RemoteDebugger("", this, this.doVerboseDebugger);
- }
-
- this.gotQuitEvent = false;
- } catch (Exception ex) {
- this.exceptionText = ((Throwable)ex).toString();
- }
-
- return this.debugger;
- }
-
- static Helper Init() throws Exception {
- return new Helper();
- }
-
- void UnLoad() throws Exception {
- if (this.currentThreadGroup != null) {
- this.taskCompleted = true;
- this.currentThread = null;
- this.suspendedThreads.removeAllElements();
- this.currentThreadGroup.stop();
- }
- }
-
- boolean Load(String[] argv) throws Exception {
- this.initialClass = this.debugger.findClass(argv[0]);
-
- for(int i = 1; this.initialClass == null && i < 3; ++i) {
- this.initialClass = this.debugger.findClass(argv[0]);
- }
-
- if (this.initialClass == null) {
- System.out.print(argv[0] + " not found");
- } else {
- RemoteField method = this.initialClass.getMethod("main");
- this.initialBreakpoint = method;
- this.initialClass.setBreakpointMethod(method);
- this.taskCompleted = false;
- this.currentThreadGroup = this.debugger.run(argv.length, argv);
-
- while(this.initialBreakpoint != null) {
- }
- }
-
- return this.currentThread != null && !this.taskCompleted;
- }
-
- RemoteThread GetCurrentThread() throws Exception {
- if (this.currentThread != null) {
- this.printDebugMessage("GetCurrentThread() == " + this.currentThread.toString());
- } else {
- this.printDebugMessage("GetCurrentThread() == null");
- }
-
- return this.currentThread;
- }
-
- void ResumeSuspendedThreads() {
- try {
- for(int i = 0; i < this.suspendedThreads.size(); ++i) {
- RemoteThread thread = (RemoteThread)this.suspendedThreads.elementAt(i);
- thread.cont();
- }
-
- this.suspendedThreads.removeAllElements();
- this.debugger.cont();
- } catch (Exception ex) {
- this.exceptionText = ((Throwable)ex).toString();
- }
-
- }
-
- void SetCurrentThread(RemoteThread t) {
- this.currentThread = t;
- }
-
- RemoteThreadGroup GetCurrentThreadGroup() {
- return this.currentThreadGroup;
- }
-
- void clearFlags(boolean tracing) throws Exception {
- this.printDebugMessage("----- Clearning All Flags -----");
- this.hitBreakpoint = false;
- this.exceptionText = null;
- this.hitTracepoint = false;
- this.inTrace = tracing;
- this.currentThread = null;
- }
-
- public static void main(String[] argv) throws Exception {
- try {
- String arg = "";
-
- for(int i = 0; i < argv.length; ++i) {
- arg = arg + argv[i];
- }
-
- Helper debugger = Init();
- debugger.StartDebugger("");
- debugger.Load(argv);
- debugger.currentThread.cont();
- } catch (Exception ex) {
- System.out.println(((Throwable)ex).toString());
- }
-
- }
-
- public void threadDeathEvent(RemoteThread t) throws Exception {
- if (t == this.currentThread) {
- this.currentThread = null;
- }
-
- }
-
- public void quitEvent() throws Exception {
- this.printDebugMessage("\tquit event...");
- this.currentThread = null;
- this.taskCompleted = true;
- this.gotQuitEvent = true;
- }
-
- public boolean GetTaskCompleted() throws Exception {
- this.printDebugMessage("GetTaskComplete() == " + this.taskCompleted);
- if (this.gotQuitEvent) {
- this.printDebugMessage("\t*** Saw a quit event ... taskCompleted == " + this.taskCompleted);
- }
-
- return this.taskCompleted;
- }
-
- public boolean GetHitBreakpoint() {
- return this.hitBreakpoint;
- }
-
- public boolean GetHitTracepoint() {
- return this.hitTracepoint;
- }
-
- public boolean GetHaveException() {
- return this.exceptionText != null;
- }
-
- public String GetExceptionText() {
- return this.exceptionText;
- }
-
- public int getTC_BOOLEAN() {
- return 0;
- }
-
- public int getTC_BYTE() {
- return 1;
- }
-
- public int getTC_CHAR() {
- return 2;
- }
-
- public int getTC_SHORT() {
- return 3;
- }
-
- public int getTC_INT() {
- return 4;
- }
-
- public int getTC_LONG() {
- return 5;
- }
-
- public int getTC_FLOAT() {
- return 6;
- }
-
- public int getTC_DOUBLE() {
- return 7;
- }
-
- public int getTC_NULL() {
- return 8;
- }
-
- public int getTC_ARRAY() {
- return 9;
- }
-
- public int getTC_CLASS() {
- return 10;
- }
-
- public int getTC_VOID() {
- return 11;
- }
-
- public int getTC_METHOD() {
- return 12;
- }
-
- public int getTC_ERROR() {
- return 13;
- }
-
- public String getJavaVersion() {
- return System.getProperty("java.version");
- }
-
- public void breakpointEvent(RemoteThread t) throws Exception {
- this.printDebugMessage("----- BreakpointEvent() started -----");
- this.displayThreadStatus();
- if (this.initialBreakpoint != null) {
- this.initialClass.clearBreakpointMethod(this.initialBreakpoint);
- this.initialBreakpoint = null;
- }
-
- this.displayThreadStatus();
- this.suspendedThreads.addElement(t);
- if (this.currentThread == null) {
- this.currentThread = t;
- }
-
- if (this.inTrace) {
- this.printDebugMessage("----- BreakpointEvent(TRACE) -----");
- this.hitTracepoint = true;
- } else {
- this.printDebugMessage("----- BreakpointEvent(BREAK) -----");
- this.hitBreakpoint = true;
- }
-
- this.printDebugMessage("----- BreakpointEvent() ended -----");
- }
-
- public void exceptionEvent(RemoteThread t, String errorText) throws Exception {
- t.setCurrentFrameIndex(0);
- this.currentThread = t;
- this.exceptionText = errorText;
- }
-
- public synchronized void printToConsole(String text) throws Exception {
- this.PrintCallBack(text);
- }
-
- public synchronized void printDebugMessage(String text) throws Exception {
- if (this.doDebug) {
- this.printToConsole(text);
- }
-
- }
-
- public synchronized void message(String text) throws Exception {
- this.printToConsole(text);
- }
-
- void SetDebugFlags(boolean debugOn, boolean verboseDebugger, boolean printToFile) {
- this.doDebug = debugOn;
- this.doVerboseDebugger = verboseDebugger;
- }
-
- public synchronized void displayThreadStatus() throws Exception {
- if (this.doDebug) {
- int c = 0;
- RemoteThreadGroup[] groups = this.debugger.listThreadGroups((RemoteThreadGroup)null);
- this.printDebugMessage("===================================================");
-
- for(int i = 0; i < groups.length; ++i) {
- this.printDebugMessage("Group \"" + groups[i].getName() + "\":");
- RemoteThread[] threads = groups[i].listThreads(false);
-
- for(int j = 0; j < threads.length; ++j) {
- if (i == 0 && j == 0) {
- this.printDebugMessage("{resuming " + threads[j].toString() + "}");
- threads[j].resume();
- }
-
- ++c;
- this.printDebugMessage(c + ". " + threads[j].toString() + threads[j].getStatus());
- }
- }
-
- this.printDebugMessage("===================================================");
- }
- }
-
- public String GetFloatViaString(RemoteFloat rf) {
- return Float.toString(rf.get());
- }
-
- public String GetDoubleViaString(RemoteDouble rd) {
- return Double.toString(rd.get());
- }
-
- public Helper() {
- this.doVerboseDebugger = this.doDebug;
- this.debugFileName = "d:\\debug.out";
- this.firstPrint = true;
- this.gotQuitEvent = false;
- }
- }
-