author | ysuenaga |
Tue, 09 Aug 2016 21:57:29 +0900 | |
changeset 40380 | 5e5a194ad1b4 |
parent 40101 | 3b8101f0fd65 |
permissions | -rw-r--r-- |
31978 | 1 |
/* |
40101 | 2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
31978 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot; |
|
26 |
||
27 |
import java.util.ArrayList; |
|
28 |
import java.util.Arrays; |
|
29 |
||
30 |
import sun.jvm.hotspot.tools.JStack; |
|
31 |
import sun.jvm.hotspot.tools.JMap; |
|
32 |
import sun.jvm.hotspot.tools.JInfo; |
|
37090 | 33 |
import sun.jvm.hotspot.tools.JSnap; |
31978 | 34 |
|
35 |
public class SALauncher { |
|
36 |
||
37 |
private static boolean launcherHelp() { |
|
38 |
System.out.println(" clhsdb \tcommand line debugger"); |
|
40101 | 39 |
System.out.println(" debugd \tdebug server"); |
31978 | 40 |
System.out.println(" hsdb \tui debugger"); |
41 |
System.out.println(" jstack --help\tto get more information"); |
|
42 |
System.out.println(" jmap --help\tto get more information"); |
|
43 |
System.out.println(" jinfo --help\tto get more information"); |
|
37090 | 44 |
System.out.println(" jsnap --help\tto get more information"); |
31978 | 45 |
return false; |
46 |
} |
|
47 |
||
48 |
private static boolean commonHelp() { |
|
49 |
// --pid <pid> |
|
50 |
// --exe <exe> |
|
51 |
// --core <core> |
|
52 |
System.out.println(" --exe\texecutable image name"); |
|
53 |
System.out.println(" --core\tpath to coredump"); |
|
54 |
System.out.println(" --pid\tpid of process to attach"); |
|
55 |
return false; |
|
56 |
} |
|
57 |
||
40101 | 58 |
private static boolean debugdHelp() { |
59 |
// [options] <pid> [server-id] |
|
60 |
// [options] <executable> <core> [server-id] |
|
61 |
java.io.PrintStream out = System.out; |
|
62 |
out.print(" [option] <pid> [server-id]"); |
|
63 |
out.println("\t\t(to connect to a live java process)"); |
|
64 |
out.print(" or [option] <executable> <core> [server-id]"); |
|
65 |
out.println("\t\t(to connect to a core file produced by <executable>)"); |
|
66 |
out.print("\t\tserver-id is an optional unique id for this debug server, needed "); |
|
67 |
out.println("\t\tif multiple debug servers are run on the same machine"); |
|
68 |
out.println("where option includes:"); |
|
69 |
out.println(" -h | -help\tto print this help message"); |
|
70 |
return false; |
|
71 |
} |
|
72 |
||
31978 | 73 |
private static boolean jinfoHelp() { |
74 |
// --flags -> -flags |
|
75 |
// --sysprops -> -sysprops |
|
76 |
System.out.println(" --flags\tto print VM flags"); |
|
77 |
System.out.println(" --sysprops\tto print Java System properties"); |
|
78 |
System.out.println(" <no option>\tto print both of the above"); |
|
79 |
return commonHelp(); |
|
80 |
} |
|
81 |
||
82 |
private static boolean jmapHelp() { |
|
83 |
// --heap -> -heap |
|
84 |
// --binaryheap -> -heap:format=b |
|
85 |
// --histo -> -histo |
|
86 |
// --clstats -> -clstats |
|
87 |
// --finalizerinfo -> -finalizerinfo |
|
88 |
||
89 |
System.out.println(" <no option>\tto print same info as Solaris pmap"); |
|
90 |
System.out.println(" --heap\tto print java heap summary"); |
|
91 |
System.out.println(" --binaryheap\tto dump java heap in hprof binary format"); |
|
38264 | 92 |
System.out.println(" --dumpfile\tname of the dump file"); |
31978 | 93 |
System.out.println(" --histo\tto print histogram of java object heap"); |
94 |
System.out.println(" --clstats\tto print class loader statistics"); |
|
95 |
System.out.println(" --finalizerinfo\tto print information on objects awaiting finalization"); |
|
96 |
return commonHelp(); |
|
97 |
} |
|
98 |
||
99 |
private static boolean jstackHelp() { |
|
100 |
// --locks -> -l |
|
101 |
// --mixed -> -m |
|
102 |
System.out.println(" --locks\tto print java.util.concurrent locks"); |
|
103 |
System.out.println(" --mixed\tto print both java and native frames (mixed mode)"); |
|
104 |
return commonHelp(); |
|
105 |
} |
|
106 |
||
37090 | 107 |
private static boolean jsnapHelp() { |
37177 | 108 |
System.out.println(" --all\tto print all performance counters"); |
37090 | 109 |
return commonHelp(); |
110 |
} |
|
111 |
||
31978 | 112 |
private static boolean toolHelp(String toolName) { |
113 |
if (toolName.equals("jstack")) { |
|
114 |
return jstackHelp(); |
|
115 |
} |
|
116 |
if (toolName.equals("jinfo")) { |
|
117 |
return jinfoHelp(); |
|
118 |
} |
|
119 |
if (toolName.equals("jmap")) { |
|
120 |
return jmapHelp(); |
|
121 |
} |
|
37090 | 122 |
if (toolName.equals("jsnap")) { |
123 |
return jsnapHelp(); |
|
124 |
} |
|
40101 | 125 |
if (toolName.equals("debugd")) { |
126 |
return debugdHelp(); |
|
127 |
} |
|
31978 | 128 |
if (toolName.equals("hsdb") || toolName.equals("clhsdb")) { |
129 |
return commonHelp(); |
|
130 |
} |
|
131 |
return launcherHelp(); |
|
132 |
} |
|
133 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
134 |
private static void buildAttachArgs(ArrayList<String> newArgs, String pid, |
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
135 |
String exe, String core, boolean allowEmpty) { |
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
136 |
if (!allowEmpty && (pid == null) && (exe == null)) { |
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
137 |
throw new SAGetoptException("You have to set --pid or --exe."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
138 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
139 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
140 |
if (pid != null) { // Attach to live process |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
141 |
if (exe != null) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
142 |
throw new SAGetoptException("Unnecessary argument: --exe"); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
143 |
} else if (core != null) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
144 |
throw new SAGetoptException("Unnecessary argument: --core"); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
145 |
} else if (!pid.matches("^\\d+$")) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
146 |
throw new SAGetoptException("Invalid pid: " + pid); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
147 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
148 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
149 |
newArgs.add(pid); |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
150 |
} else if (exe != null) { |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
151 |
if (exe.length() == 0) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
152 |
throw new SAGetoptException("You have to set --exe."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
153 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
154 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
155 |
newArgs.add(exe); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
156 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
157 |
if ((core == null) || (core.length() == 0)) { |
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
158 |
throw new SAGetoptException("You have to set --core."); |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
159 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
160 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
161 |
newArgs.add(core); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
162 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
163 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
164 |
|
31978 | 165 |
private static void runCLHSDB(String[] oldArgs) { |
166 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
167 |
String[] longOpts = {"exe=", "core=", "pid="}; |
|
168 |
||
169 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
170 |
String pid = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
171 |
String exe = null; |
31978 | 172 |
String core = null; |
173 |
String s = null; |
|
174 |
||
175 |
while((s = sg.next(null, longOpts)) != null) { |
|
176 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
177 |
exe = sg.getOptarg(); |
31978 | 178 |
continue; |
179 |
} |
|
180 |
if (s.equals("core")) { |
|
181 |
core = sg.getOptarg(); |
|
182 |
continue; |
|
183 |
} |
|
184 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
185 |
pid = sg.getOptarg(); |
31978 | 186 |
continue; |
187 |
} |
|
188 |
} |
|
189 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
190 |
buildAttachArgs(newArgs, pid, exe, core, true); |
31978 | 191 |
CLHSDB.main(newArgs.toArray(new String[newArgs.size()])); |
192 |
} |
|
193 |
||
194 |
private static void runHSDB(String[] oldArgs) { |
|
195 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
196 |
String[] longOpts = {"exe=", "core=", "pid="}; |
|
197 |
||
198 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
199 |
String pid = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
200 |
String exe = null; |
31978 | 201 |
String core = null; |
202 |
String s = null; |
|
203 |
||
204 |
while((s = sg.next(null, longOpts)) != null) { |
|
205 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
206 |
exe = sg.getOptarg(); |
31978 | 207 |
continue; |
208 |
} |
|
209 |
if (s.equals("core")) { |
|
210 |
core = sg.getOptarg(); |
|
211 |
continue; |
|
212 |
} |
|
213 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
214 |
pid = sg.getOptarg(); |
31978 | 215 |
continue; |
216 |
} |
|
217 |
} |
|
218 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
219 |
buildAttachArgs(newArgs, pid, exe, core, true); |
31978 | 220 |
HSDB.main(newArgs.toArray(new String[newArgs.size()])); |
221 |
} |
|
222 |
||
223 |
private static void runJSTACK(String[] oldArgs) { |
|
224 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
225 |
String[] longOpts = {"exe=", "core=", "pid=", |
|
226 |
"mixed", "locks"}; |
|
227 |
||
228 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
229 |
String pid = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
230 |
String exe = null; |
31978 | 231 |
String core = null; |
232 |
String s = null; |
|
233 |
||
234 |
while((s = sg.next(null, longOpts)) != null) { |
|
235 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
236 |
exe = sg.getOptarg(); |
31978 | 237 |
continue; |
238 |
} |
|
239 |
if (s.equals("core")) { |
|
240 |
core = sg.getOptarg(); |
|
241 |
continue; |
|
242 |
} |
|
243 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
244 |
pid = sg.getOptarg(); |
31978 | 245 |
continue; |
246 |
} |
|
247 |
if (s.equals("mixed")) { |
|
248 |
newArgs.add("-m"); |
|
249 |
continue; |
|
250 |
} |
|
251 |
if (s.equals("locks")) { |
|
252 |
newArgs.add("-l"); |
|
253 |
continue; |
|
254 |
} |
|
255 |
} |
|
256 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
257 |
buildAttachArgs(newArgs, pid, exe, core, false); |
40380
5e5a194ad1b4
8163185: jhsdb jstack cannot work with normal mode
ysuenaga
parents:
40101
diff
changeset
|
258 |
JStack jstack = new JStack(false, false); |
5e5a194ad1b4
8163185: jhsdb jstack cannot work with normal mode
ysuenaga
parents:
40101
diff
changeset
|
259 |
jstack.runWithArgs(newArgs.toArray(new String[newArgs.size()])); |
31978 | 260 |
} |
261 |
||
262 |
private static void runJMAP(String[] oldArgs) { |
|
263 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
264 |
String[] longOpts = {"exe=", "core=", "pid=", |
|
38264 | 265 |
"heap", "binaryheap", "dumpfile=", "histo", "clstats", "finalizerinfo"}; |
31978 | 266 |
|
267 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
268 |
String pid = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
269 |
String exe = null; |
31978 | 270 |
String core = null; |
271 |
String s = null; |
|
38264 | 272 |
String dumpfile = null; |
273 |
boolean requestHeapdump = false; |
|
31978 | 274 |
|
275 |
while((s = sg.next(null, longOpts)) != null) { |
|
276 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
277 |
exe = sg.getOptarg(); |
31978 | 278 |
continue; |
279 |
} |
|
280 |
if (s.equals("core")) { |
|
281 |
core = sg.getOptarg(); |
|
282 |
continue; |
|
283 |
} |
|
284 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
285 |
pid = sg.getOptarg(); |
31978 | 286 |
continue; |
287 |
} |
|
288 |
if (s.equals("heap")) { |
|
289 |
newArgs.add("-heap"); |
|
290 |
continue; |
|
291 |
} |
|
292 |
if (s.equals("binaryheap")) { |
|
38264 | 293 |
requestHeapdump = true; |
294 |
continue; |
|
295 |
} |
|
296 |
if (s.equals("dumpfile")) { |
|
297 |
dumpfile = sg.getOptarg(); |
|
31978 | 298 |
continue; |
299 |
} |
|
300 |
if (s.equals("histo")) { |
|
301 |
newArgs.add("-histo"); |
|
302 |
continue; |
|
303 |
} |
|
304 |
if (s.equals("clstats")) { |
|
305 |
newArgs.add("-clstats"); |
|
306 |
continue; |
|
307 |
} |
|
308 |
if (s.equals("finalizerinfo")) { |
|
309 |
newArgs.add("-finalizerinfo"); |
|
310 |
continue; |
|
311 |
} |
|
312 |
} |
|
313 |
||
38264 | 314 |
if (!requestHeapdump && (dumpfile != null)) { |
315 |
throw new IllegalArgumentException("Unexpected argument dumpfile"); |
|
316 |
} |
|
317 |
if (requestHeapdump) { |
|
318 |
if (dumpfile == null) { |
|
319 |
newArgs.add("-heap:format=b"); |
|
320 |
} else { |
|
321 |
newArgs.add("-heap:format=b,file=" + dumpfile); |
|
322 |
} |
|
323 |
} |
|
324 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
325 |
buildAttachArgs(newArgs, pid, exe, core, false); |
31978 | 326 |
JMap.main(newArgs.toArray(new String[newArgs.size()])); |
327 |
} |
|
328 |
||
329 |
private static void runJINFO(String[] oldArgs) { |
|
330 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
331 |
String[] longOpts = {"exe=", "core=", "pid=", |
|
332 |
"flags", "sysprops"}; |
|
333 |
||
334 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
335 |
String exe = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
336 |
String pid = null; |
31978 | 337 |
String core = null; |
338 |
String s = null; |
|
339 |
||
340 |
while((s = sg.next(null, longOpts)) != null) { |
|
341 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
342 |
exe = sg.getOptarg(); |
31978 | 343 |
continue; |
344 |
} |
|
345 |
if (s.equals("core")) { |
|
346 |
core = sg.getOptarg(); |
|
347 |
continue; |
|
348 |
} |
|
349 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
350 |
pid = sg.getOptarg(); |
31978 | 351 |
continue; |
352 |
} |
|
353 |
if (s.equals("flags")) { |
|
354 |
newArgs.add("-flags"); |
|
355 |
continue; |
|
356 |
} |
|
357 |
if (s.equals("sysprops")) { |
|
358 |
newArgs.add("-sysprops"); |
|
359 |
continue; |
|
360 |
} |
|
361 |
} |
|
362 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
363 |
buildAttachArgs(newArgs, pid, exe, core, false); |
31978 | 364 |
JInfo.main(newArgs.toArray(new String[newArgs.size()])); |
365 |
} |
|
366 |
||
37090 | 367 |
private static void runJSNAP(String[] oldArgs) { |
368 |
SAGetopt sg = new SAGetopt(oldArgs); |
|
37177 | 369 |
String[] longOpts = {"exe=", "core=", "pid=", "all"}; |
37090 | 370 |
|
371 |
ArrayList<String> newArgs = new ArrayList(); |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
372 |
String exe = null; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
373 |
String pid = null; |
37090 | 374 |
String core = null; |
375 |
String s = null; |
|
376 |
||
377 |
while((s = sg.next(null, longOpts)) != null) { |
|
378 |
if (s.equals("exe")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
379 |
exe = sg.getOptarg(); |
37090 | 380 |
continue; |
381 |
} |
|
382 |
if (s.equals("core")) { |
|
383 |
core = sg.getOptarg(); |
|
384 |
continue; |
|
385 |
} |
|
386 |
if (s.equals("pid")) { |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
387 |
pid = sg.getOptarg(); |
37090 | 388 |
continue; |
389 |
} |
|
37177 | 390 |
if (s.equals("all")) { |
391 |
newArgs.add("-a"); |
|
392 |
continue; |
|
393 |
} |
|
37090 | 394 |
} |
395 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
396 |
buildAttachArgs(newArgs, pid, exe, core, false); |
37090 | 397 |
JSnap.main(newArgs.toArray(new String[newArgs.size()])); |
398 |
} |
|
399 |
||
40101 | 400 |
private static void runDEBUGD(String[] oldArgs) { |
401 |
if ((oldArgs.length < 1) || (oldArgs.length > 3)) { |
|
402 |
debugdHelp(); |
|
403 |
} |
|
404 |
||
405 |
// By default SA agent classes prefer Windows process debugger |
|
406 |
// to windbg debugger. SA expects special properties to be set |
|
407 |
// to choose other debuggers. We will set those here before |
|
408 |
// attaching to SA agent. |
|
409 |
System.setProperty("sun.jvm.hotspot.debugger.useWindbgDebugger", "true"); |
|
410 |
||
411 |
// delegate to the actual SA debug server. |
|
412 |
sun.jvm.hotspot.DebugServer.main(oldArgs); |
|
413 |
} |
|
414 |
||
31978 | 415 |
public static void main(String[] args) { |
416 |
// Provide a help |
|
417 |
if (args.length == 0) { |
|
418 |
launcherHelp(); |
|
419 |
return; |
|
420 |
} |
|
40101 | 421 |
// No arguments imply help for debugd, jstack, jmap, jinfo but launch clhsdb and hsdb |
31978 | 422 |
if (args.length == 1 && !args[0].equals("clhsdb") && !args[0].equals("hsdb")) { |
423 |
toolHelp(args[0]); |
|
424 |
return; |
|
425 |
} |
|
426 |
||
427 |
for (String arg : args) { |
|
428 |
if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")) { |
|
429 |
toolHelp(args[0]); |
|
430 |
return; |
|
431 |
} |
|
432 |
} |
|
433 |
||
434 |
String[] oldArgs = Arrays.copyOfRange(args, 1, args.length); |
|
435 |
||
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
436 |
try { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
437 |
// Run SA interactive mode |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
438 |
if (args[0].equals("clhsdb")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
439 |
runCLHSDB(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
440 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
441 |
} |
31978 | 442 |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
443 |
if (args[0].equals("hsdb")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
444 |
runHSDB(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
445 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
446 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
447 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
448 |
// Run SA tmtools mode |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
449 |
if (args[0].equals("jstack")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
450 |
runJSTACK(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
451 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
452 |
} |
31978 | 453 |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
454 |
if (args[0].equals("jmap")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
455 |
runJMAP(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
456 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
457 |
} |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
458 |
|
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
459 |
if (args[0].equals("jinfo")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
460 |
runJINFO(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
461 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
462 |
} |
31978 | 463 |
|
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
464 |
if (args[0].equals("jsnap")) { |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
465 |
runJSNAP(oldArgs); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
466 |
return; |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
467 |
} |
31978 | 468 |
|
40101 | 469 |
if (args[0].equals("debugd")) { |
470 |
runDEBUGD(oldArgs); |
|
471 |
return; |
|
472 |
} |
|
473 |
||
37445
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
474 |
throw new SAGetoptException("Unknown tool: " + args[0]); |
5565e6e80352
8152435: (CL)HSDB should be started with no argument
ysuenaga
parents:
37177
diff
changeset
|
475 |
} catch (SAGetoptException e) { |
37101
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
476 |
System.err.println(e.getMessage()); |
496308fe87f1
8151709: jhsdb should show help message in SALauncher.
ysuenaga
parents:
37090
diff
changeset
|
477 |
toolHelp(args[0]); |
37090 | 478 |
} |
31978 | 479 |
} |
480 |
} |