agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java

Print this page

        

@@ -33,17 +33,25 @@
 // generic command line or GUI tool.
 // override run & code main as shown below.
 
 public abstract class Tool implements Runnable {
    private HotSpotAgent agent;
+   private JVMDebugger jvmDebugger;
    private int debugeeType;
 
    // debugeeType is one of constants below
    protected static final int DEBUGEE_PID    = 0;
    protected static final int DEBUGEE_CORE   = 1;
    protected static final int DEBUGEE_REMOTE = 2;
 
+   public Tool() {
+   }
+
+   public Tool(JVMDebugger d) {
+      jvmDebugger = d;
+   }
+
    public String getName() {
       return getClass().getName();
    }
 
    protected boolean needsJavaPrefix() {

@@ -88,11 +96,10 @@
        System.out.println("    -h | -help\tto print this help message");
    }
 
    protected void usage() {
       printUsage();
-      System.exit(1);
    }
 
    /*
       Derived class main should be of the following form:
 

@@ -104,17 +111,17 @@
    */
 
    protected void stop() {
       if (agent != null) {
          agent.detach();
-         System.exit(0);
       }
    }
 
    protected void start(String[] args) {
       if ((args.length < 1) || (args.length > 2)) {
          usage();
+         return;
       }
 
       // Attempt to handle -h or -help or some invalid flag
       if (args[0].startsWith("-")) {
           usage();

@@ -183,17 +190,35 @@
              err.print("Error attaching to remote server: ");
              break;
         }
         if (e.getMessage() != null) {
           err.print(e.getMessage());
+          e.printStackTrace();
         }
         err.println();
-        System.exit(1);
+        return;
       }
 
       err.println("Debugger attached successfully.");
+      startInternal();
+   }
+
+   // When using an existing JVMDebugger.
+   public void start() {
 
+      if (jvmDebugger == null) {
+         throw new RuntimeException("Tool.start() called with no JVMDebugger set.");
+      }
+      agent = new HotSpotAgent();
+      agent.attach(jvmDebugger);
+      startInternal();
+   }
+
+   // Remains of the start mechanism, common to both start methods.
+   private void startInternal() {
+
+      PrintStream err = System.err;
       VM vm = VM.getVM();
       if (vm.isCore()) {
         err.println("Core build detected.");
       } else if (vm.isClientCompiler()) {
         err.println("Client compiler detected.");