home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 September / dppcpro0998.iso / Rwc / Sybase / Install.exe / java.z / Helper.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-23  |  9.5 KB  |  341 lines

  1. package powersoft.debugger;
  2.  
  3. import java.util.Vector;
  4. import sun.tools.debug.DebuggerCallback;
  5. import sun.tools.debug.RemoteClass;
  6. import sun.tools.debug.RemoteDebugger;
  7. import sun.tools.debug.RemoteDouble;
  8. import sun.tools.debug.RemoteField;
  9. import sun.tools.debug.RemoteFloat;
  10. import sun.tools.debug.RemoteThread;
  11. import sun.tools.debug.RemoteThreadGroup;
  12.  
  13. public class Helper implements DebuggerCallback {
  14.    private RemoteDebugger debugger;
  15.    private RemoteThread currentThread;
  16.    private Vector suspendedThreads = new Vector();
  17.    private RemoteThreadGroup currentThreadGroup;
  18.    private RemoteClass initialClass;
  19.    private volatile RemoteField initialBreakpoint;
  20.    private boolean taskCompleted = true;
  21.    private boolean hitBreakpoint = true;
  22.    private boolean hitTracepoint = true;
  23.    private String exceptionText;
  24.    private boolean inTrace = false;
  25.    private boolean doDebug = false;
  26.    private boolean doVerboseDebugger;
  27.    private String debugFileName;
  28.    private boolean firstPrint;
  29.    private boolean gotQuitEvent;
  30.  
  31.    public synchronized native void PrintCallBack(String var1);
  32.  
  33.    // $FF: renamed from: gc () void
  34.    void method_0() {
  35.       System.gc();
  36.    }
  37.  
  38.    RemoteDebugger StartDebugger(String host) {
  39.       try {
  40.          int dot = host.indexOf(58);
  41.          if (dot != -1) {
  42.             this.debugger = new RemoteDebugger(host.substring(0, dot), host.substring(dot + 1), this, this.doVerboseDebugger);
  43.          } else {
  44.             this.debugger = new RemoteDebugger("", this, this.doVerboseDebugger);
  45.          }
  46.  
  47.          this.gotQuitEvent = false;
  48.       } catch (Exception ex) {
  49.          this.exceptionText = ((Throwable)ex).toString();
  50.       }
  51.  
  52.       return this.debugger;
  53.    }
  54.  
  55.    static Helper Init() throws Exception {
  56.       return new Helper();
  57.    }
  58.  
  59.    void UnLoad() throws Exception {
  60.       if (this.currentThreadGroup != null) {
  61.          this.taskCompleted = true;
  62.          this.currentThread = null;
  63.          this.suspendedThreads.removeAllElements();
  64.          this.currentThreadGroup.stop();
  65.       }
  66.    }
  67.  
  68.    boolean Load(String[] argv) throws Exception {
  69.       this.initialClass = this.debugger.findClass(argv[0]);
  70.  
  71.       for(int i = 1; this.initialClass == null && i < 3; ++i) {
  72.          this.initialClass = this.debugger.findClass(argv[0]);
  73.       }
  74.  
  75.       if (this.initialClass == null) {
  76.          System.out.print(argv[0] + " not found");
  77.       } else {
  78.          RemoteField method = this.initialClass.getMethod("main");
  79.          this.initialBreakpoint = method;
  80.          this.initialClass.setBreakpointMethod(method);
  81.          this.taskCompleted = false;
  82.          this.currentThreadGroup = this.debugger.run(argv.length, argv);
  83.  
  84.          while(this.initialBreakpoint != null) {
  85.          }
  86.       }
  87.  
  88.       return this.currentThread != null && !this.taskCompleted;
  89.    }
  90.  
  91.    RemoteThread GetCurrentThread() throws Exception {
  92.       if (this.currentThread != null) {
  93.          this.printDebugMessage("GetCurrentThread() == " + this.currentThread.toString());
  94.       } else {
  95.          this.printDebugMessage("GetCurrentThread() == null");
  96.       }
  97.  
  98.       return this.currentThread;
  99.    }
  100.  
  101.    void ResumeSuspendedThreads() {
  102.       try {
  103.          for(int i = 0; i < this.suspendedThreads.size(); ++i) {
  104.             RemoteThread thread = (RemoteThread)this.suspendedThreads.elementAt(i);
  105.             thread.cont();
  106.          }
  107.  
  108.          this.suspendedThreads.removeAllElements();
  109.          this.debugger.cont();
  110.       } catch (Exception ex) {
  111.          this.exceptionText = ((Throwable)ex).toString();
  112.       }
  113.  
  114.    }
  115.  
  116.    void SetCurrentThread(RemoteThread t) {
  117.       this.currentThread = t;
  118.    }
  119.  
  120.    RemoteThreadGroup GetCurrentThreadGroup() {
  121.       return this.currentThreadGroup;
  122.    }
  123.  
  124.    void clearFlags(boolean tracing) throws Exception {
  125.       this.printDebugMessage("----- Clearning All Flags -----");
  126.       this.hitBreakpoint = false;
  127.       this.exceptionText = null;
  128.       this.hitTracepoint = false;
  129.       this.inTrace = tracing;
  130.       this.currentThread = null;
  131.    }
  132.  
  133.    public static void main(String[] argv) throws Exception {
  134.       try {
  135.          String arg = "";
  136.  
  137.          for(int i = 0; i < argv.length; ++i) {
  138.             arg = arg + argv[i];
  139.          }
  140.  
  141.          Helper debugger = Init();
  142.          debugger.StartDebugger("");
  143.          debugger.Load(argv);
  144.          debugger.currentThread.cont();
  145.       } catch (Exception ex) {
  146.          System.out.println(((Throwable)ex).toString());
  147.       }
  148.  
  149.    }
  150.  
  151.    public void threadDeathEvent(RemoteThread t) throws Exception {
  152.       if (t == this.currentThread) {
  153.          this.currentThread = null;
  154.       }
  155.  
  156.    }
  157.  
  158.    public void quitEvent() throws Exception {
  159.       this.printDebugMessage("\tquit event...");
  160.       this.currentThread = null;
  161.       this.taskCompleted = true;
  162.       this.gotQuitEvent = true;
  163.    }
  164.  
  165.    public boolean GetTaskCompleted() throws Exception {
  166.       this.printDebugMessage("GetTaskComplete() == " + this.taskCompleted);
  167.       if (this.gotQuitEvent) {
  168.          this.printDebugMessage("\t*** Saw a quit event ... taskCompleted == " + this.taskCompleted);
  169.       }
  170.  
  171.       return this.taskCompleted;
  172.    }
  173.  
  174.    public boolean GetHitBreakpoint() {
  175.       return this.hitBreakpoint;
  176.    }
  177.  
  178.    public boolean GetHitTracepoint() {
  179.       return this.hitTracepoint;
  180.    }
  181.  
  182.    public boolean GetHaveException() {
  183.       return this.exceptionText != null;
  184.    }
  185.  
  186.    public String GetExceptionText() {
  187.       return this.exceptionText;
  188.    }
  189.  
  190.    public int getTC_BOOLEAN() {
  191.       return 0;
  192.    }
  193.  
  194.    public int getTC_BYTE() {
  195.       return 1;
  196.    }
  197.  
  198.    public int getTC_CHAR() {
  199.       return 2;
  200.    }
  201.  
  202.    public int getTC_SHORT() {
  203.       return 3;
  204.    }
  205.  
  206.    public int getTC_INT() {
  207.       return 4;
  208.    }
  209.  
  210.    public int getTC_LONG() {
  211.       return 5;
  212.    }
  213.  
  214.    public int getTC_FLOAT() {
  215.       return 6;
  216.    }
  217.  
  218.    public int getTC_DOUBLE() {
  219.       return 7;
  220.    }
  221.  
  222.    public int getTC_NULL() {
  223.       return 8;
  224.    }
  225.  
  226.    public int getTC_ARRAY() {
  227.       return 9;
  228.    }
  229.  
  230.    public int getTC_CLASS() {
  231.       return 10;
  232.    }
  233.  
  234.    public int getTC_VOID() {
  235.       return 11;
  236.    }
  237.  
  238.    public int getTC_METHOD() {
  239.       return 12;
  240.    }
  241.  
  242.    public int getTC_ERROR() {
  243.       return 13;
  244.    }
  245.  
  246.    public String getJavaVersion() {
  247.       return System.getProperty("java.version");
  248.    }
  249.  
  250.    public void breakpointEvent(RemoteThread t) throws Exception {
  251.       this.printDebugMessage("----- BreakpointEvent() started -----");
  252.       this.displayThreadStatus();
  253.       if (this.initialBreakpoint != null) {
  254.          this.initialClass.clearBreakpointMethod(this.initialBreakpoint);
  255.          this.initialBreakpoint = null;
  256.       }
  257.  
  258.       this.displayThreadStatus();
  259.       this.suspendedThreads.addElement(t);
  260.       if (this.currentThread == null) {
  261.          this.currentThread = t;
  262.       }
  263.  
  264.       if (this.inTrace) {
  265.          this.printDebugMessage("----- BreakpointEvent(TRACE) -----");
  266.          this.hitTracepoint = true;
  267.       } else {
  268.          this.printDebugMessage("----- BreakpointEvent(BREAK) -----");
  269.          this.hitBreakpoint = true;
  270.       }
  271.  
  272.       this.printDebugMessage("----- BreakpointEvent() ended -----");
  273.    }
  274.  
  275.    public void exceptionEvent(RemoteThread t, String errorText) throws Exception {
  276.       t.setCurrentFrameIndex(0);
  277.       this.currentThread = t;
  278.       this.exceptionText = errorText;
  279.    }
  280.  
  281.    public synchronized void printToConsole(String text) throws Exception {
  282.       this.PrintCallBack(text);
  283.    }
  284.  
  285.    public synchronized void printDebugMessage(String text) throws Exception {
  286.       if (this.doDebug) {
  287.          this.printToConsole(text);
  288.       }
  289.  
  290.    }
  291.  
  292.    public synchronized void message(String text) throws Exception {
  293.       this.printToConsole(text);
  294.    }
  295.  
  296.    void SetDebugFlags(boolean debugOn, boolean verboseDebugger, boolean printToFile) {
  297.       this.doDebug = debugOn;
  298.       this.doVerboseDebugger = verboseDebugger;
  299.    }
  300.  
  301.    public synchronized void displayThreadStatus() throws Exception {
  302.       if (this.doDebug) {
  303.          int c = 0;
  304.          RemoteThreadGroup[] groups = this.debugger.listThreadGroups((RemoteThreadGroup)null);
  305.          this.printDebugMessage("===================================================");
  306.  
  307.          for(int i = 0; i < groups.length; ++i) {
  308.             this.printDebugMessage("Group \"" + groups[i].getName() + "\":");
  309.             RemoteThread[] threads = groups[i].listThreads(false);
  310.  
  311.             for(int j = 0; j < threads.length; ++j) {
  312.                if (i == 0 && j == 0) {
  313.                   this.printDebugMessage("{resuming " + threads[j].toString() + "}");
  314.                   threads[j].resume();
  315.                }
  316.  
  317.                ++c;
  318.                this.printDebugMessage(c + ". " + threads[j].toString() + threads[j].getStatus());
  319.             }
  320.          }
  321.  
  322.          this.printDebugMessage("===================================================");
  323.       }
  324.    }
  325.  
  326.    public String GetFloatViaString(RemoteFloat rf) {
  327.       return Float.toString(rf.get());
  328.    }
  329.  
  330.    public String GetDoubleViaString(RemoteDouble rd) {
  331.       return Double.toString(rd.get());
  332.    }
  333.  
  334.    public Helper() {
  335.       this.doVerboseDebugger = this.doDebug;
  336.       this.debugFileName = "d:\\debug.out";
  337.       this.firstPrint = true;
  338.       this.gotQuitEvent = false;
  339.    }
  340. }
  341.