comparison agent/src/share/classes/sun/jvm/hotspot/HSDB.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 da91efe96a93
children de6a9e811145
comparison
equal deleted inserted replaced
11035:01e10b366055 11054:38ea2efa32a7
57 57
58 //-------------------------------------------------------------------------------- 58 //--------------------------------------------------------------------------------
59 // Internals only below this point 59 // Internals only below this point
60 // 60 //
61 private HotSpotAgent agent; 61 private HotSpotAgent agent;
62 private JVMDebugger jvmDebugger;
62 private JDesktopPane desktop; 63 private JDesktopPane desktop;
63 private boolean attached; 64 private boolean attached;
65 private boolean argError;
66 private JFrame frame;
64 /** List <JMenuItem> */ 67 /** List <JMenuItem> */
65 private java.util.List attachMenuItems; 68 private java.util.List attachMenuItems;
66 /** List <JMenuItem> */ 69 /** List <JMenuItem> */
67 private java.util.List detachMenuItems; 70 private java.util.List detachMenuItems;
68 private JMenu toolsMenu; 71 private JMenu toolsMenu;
83 System.out.println(" pid: attach to the process whose id is 'pid'"); 86 System.out.println(" pid: attach to the process whose id is 'pid'");
84 System.out.println(" path-to-java-executable: Debug a core file produced by this program"); 87 System.out.println(" path-to-java-executable: Debug a core file produced by this program");
85 System.out.println(" path-to-corefile: Debug this corefile. The default is 'core'"); 88 System.out.println(" path-to-corefile: Debug this corefile. The default is 'core'");
86 System.out.println(" If no arguments are specified, you can select what to do from the GUI.\n"); 89 System.out.println(" If no arguments are specified, you can select what to do from the GUI.\n");
87 HotSpotAgent.showUsage(); 90 HotSpotAgent.showUsage();
91 argError = true;
92 }
93
94 public HSDB(JVMDebugger d) {
95 jvmDebugger = d;
88 } 96 }
89 97
90 private HSDB(String[] args) { 98 private HSDB(String[] args) {
91 switch (args.length) { 99 switch (args.length) {
92 case (0): 100 case (0):
93 break; 101 break;
94 102
95 case (1): 103 case (1):
96 if (args[0].equals("help") || args[0].equals("-help")) { 104 if (args[0].equals("help") || args[0].equals("-help")) {
97 doUsage(); 105 doUsage();
98 System.exit(0);
99 } 106 }
100 // If all numbers, it is a PID to attach to 107 // If all numbers, it is a PID to attach to
101 // Else, it is a pathname to a .../bin/java for a core file. 108 // Else, it is a pathname to a .../bin/java for a core file.
102 try { 109 try {
103 int unused = Integer.parseInt(args[0]); 110 int unused = Integer.parseInt(args[0]);
115 break; 122 break;
116 123
117 default: 124 default:
118 System.out.println("HSDB Error: Too many options specified"); 125 System.out.println("HSDB Error: Too many options specified");
119 doUsage(); 126 doUsage();
120 System.exit(1); 127 }
121 } 128 }
122 } 129
123 130 // close this tool without calling System.exit
124 private void run() { 131 protected void closeUI() {
125 // At this point, if pidText != null we are supposed to attach to it. 132 workerThread.shutdown();
126 // Else, if execPath != null, it is the path of a jdk/bin/java 133 frame.dispose();
127 // and coreFilename is the pathname of a core file we are 134 }
128 // supposed to attach to. 135
136 public void run() {
137 // Don't start the UI if there were bad arguments.
138 if (argError) {
139 return;
140 }
129 141
130 agent = new HotSpotAgent(); 142 agent = new HotSpotAgent();
131 workerThread = new WorkerThread(); 143 workerThread = new WorkerThread();
132 attachMenuItems = new java.util.ArrayList(); 144 attachMenuItems = new java.util.ArrayList();
133 detachMenuItems = new java.util.ArrayList(); 145 detachMenuItems = new java.util.ArrayList();
134 146
135 JFrame frame = new JFrame("HSDB - HotSpot Debugger"); 147 frame = new JFrame("HSDB - HotSpot Debugger");
136 frame.setSize(800, 600); 148 frame.setSize(800, 600);
137 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 149 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
138 150
139 JMenuBar menuBar = new JMenuBar(); 151 JMenuBar menuBar = new JMenuBar();
140 152
141 // 153 //
142 // File menu 154 // File menu
195 menu.addSeparator(); 207 menu.addSeparator();
196 208
197 item = createMenuItem("Exit", 209 item = createMenuItem("Exit",
198 new ActionListener() { 210 new ActionListener() {
199 public void actionPerformed(ActionEvent e) { 211 public void actionPerformed(ActionEvent e) {
200 System.exit(0); 212 closeUI();
201 } 213 }
202 }); 214 });
203 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.ALT_MASK)); 215 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.ALT_MASK));
204 item.setMnemonic(KeyEvent.VK_X); 216 item.setMnemonic(KeyEvent.VK_X);
205 menu.add(item); 217 menu.add(item);
404 public void run() { 416 public void run() {
405 detachDebugger(); 417 detachDebugger();
406 } 418 }
407 }); 419 });
408 420
409 if (pidText != null) { 421 // If jvmDebugger is already set, we have been given a JVMDebugger.
422 // Otherwise, if pidText != null we are supposed to attach to it.
423 // Finally, if execPath != null, it is the path of a jdk/bin/java
424 // and coreFilename is the pathname of a core file we are
425 // supposed to attach to.
426
427 if (jvmDebugger != null) {
428 attach(jvmDebugger);
429 } else if (pidText != null) {
410 attach(pidText); 430 attach(pidText);
411 } else if (execPath != null) { 431 } else if (execPath != null) {
412 attach(execPath, coreFilename); 432 attach(execPath, coreFilename);
413 } 433 }
414 } 434 }
1111 annoPanel.repaint(); 1131 annoPanel.repaint();
1112 } 1132 }
1113 }); 1133 });
1114 } 1134 }
1115 1135
1136 // Attach to existing JVMDebugger, which should be already attached to a core/process.
1137 private void attach(JVMDebugger d) {
1138 attached = true;
1139 showThreadsDialog();
1140 }
1141
1116 /** NOTE we are in a different thread here than either the main 1142 /** NOTE we are in a different thread here than either the main
1117 thread or the Swing/AWT event handler thread, so we must be very 1143 thread or the Swing/AWT event handler thread, so we must be very
1118 careful when creating or removing widgets */ 1144 careful when creating or removing widgets */
1119 private void attach(String pidText) { 1145 private void attach(String pidText) {
1120 try { 1146 try {