comparison agent/src/share/classes/sun/jvm/hotspot/CLHSDB.java @ 11054:38ea2efa32a7

8010278: SA: provide mechanism for using an alternative SA debugger back-end. Reviewed-by: sla, dsamersoff
author kevinw
date Wed, 26 Jun 2013 00:01:20 +0100
parents f6f3bb0ee072
children de6a9e811145
comparison
equal deleted inserted replaced
11035:01e10b366055 11054:38ea2efa32a7
29 29
30 import java.io.*; 30 import java.io.*;
31 import java.util.*; 31 import java.util.*;
32 32
33 public class CLHSDB { 33 public class CLHSDB {
34
35 public CLHSDB(JVMDebugger d) {
36 jvmDebugger = d;
37 }
38
34 public static void main(String[] args) { 39 public static void main(String[] args) {
35 new CLHSDB(args).run(); 40 new CLHSDB(args).run();
36 } 41 }
37 42
38 private void run() { 43 public void run() {
39 // At this point, if pidText != null we are supposed to attach to it. 44 // If jvmDebugger is already set, we have been given a JVMDebugger.
40 // Else, if execPath != null, it is the path of a jdk/bin/java 45 // Otherwise, if pidText != null we are supposed to attach to it.
46 // Finally, if execPath != null, it is the path of a jdk/bin/java
41 // and coreFilename is the pathname of a core file we are 47 // and coreFilename is the pathname of a core file we are
42 // supposed to attach to. 48 // supposed to attach to.
43 49
44 agent = new HotSpotAgent(); 50 agent = new HotSpotAgent();
45 51
47 public void run() { 53 public void run() {
48 detachDebugger(); 54 detachDebugger();
49 } 55 }
50 }); 56 });
51 57
52 if (pidText != null) { 58 if (jvmDebugger != null) {
59 attachDebugger(jvmDebugger);
60 } else if (pidText != null) {
53 attachDebugger(pidText); 61 attachDebugger(pidText);
54 } else if (execPath != null) { 62 } else if (execPath != null) {
55 attachDebugger(execPath, coreFilename); 63 attachDebugger(execPath, coreFilename);
56 } 64 }
57 65
94 102
95 //-------------------------------------------------------------------------------- 103 //--------------------------------------------------------------------------------
96 // Internals only below this point 104 // Internals only below this point
97 // 105 //
98 private HotSpotAgent agent; 106 private HotSpotAgent agent;
107 private JVMDebugger jvmDebugger;
99 private boolean attached; 108 private boolean attached;
100 // These had to be made data members because they are referenced in inner classes. 109 // These had to be made data members because they are referenced in inner classes.
101 private String pidText; 110 private String pidText;
102 private int pid; 111 private int pid;
103 private String execPath; 112 private String execPath;
118 break; 127 break;
119 128
120 case (1): 129 case (1):
121 if (args[0].equals("help") || args[0].equals("-help")) { 130 if (args[0].equals("help") || args[0].equals("-help")) {
122 doUsage(); 131 doUsage();
123 System.exit(0); 132 return;
124 } 133 }
125 // If all numbers, it is a PID to attach to 134 // If all numbers, it is a PID to attach to
126 // Else, it is a pathname to a .../bin/java for a core file. 135 // Else, it is a pathname to a .../bin/java for a core file.
127 try { 136 try {
128 int unused = Integer.parseInt(args[0]); 137 int unused = Integer.parseInt(args[0]);
140 break; 149 break;
141 150
142 default: 151 default:
143 System.out.println("HSDB Error: Too many options specified"); 152 System.out.println("HSDB Error: Too many options specified");
144 doUsage(); 153 doUsage();
145 System.exit(1); 154 return;
146 } 155 }
147 } 156 }
157
158 private void attachDebugger(JVMDebugger d) {
159 agent.attach(d);
160 attached = true;
161 }
148 162
149 /** NOTE we are in a different thread here than either the main 163 /** NOTE we are in a different thread here than either the main
150 thread or the Swing/AWT event handler thread, so we must be very 164 thread or the Swing/AWT event handler thread, so we must be very
151 careful when creating or removing widgets */ 165 careful when creating or removing widgets */
152 private void attachDebugger(String pidText) { 166 private void attachDebugger(String pidText) {