1 /* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 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; 33 import sun.jvm.hotspot.tools.JSnap; 34 35 public class SALauncher { 36 37 private static boolean launcherHelp() { 38 System.out.println(" clhsdb \tcommand line debugger"); 39 System.out.println(" debugd \tdebug server"); 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"); 44 System.out.println(" jsnap --help\tto get more information"); 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 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 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"); 381 } 382 if (s.equals("core")) { 383 core = sg.getOptarg(); 384 continue; 385 } 386 if (s.equals("pid")) { 387 pid = sg.getOptarg(); 388 continue; 389 } 390 if (s.equals("all")) { 391 newArgs.add("-a"); 392 continue; 393 } 394 } 395 396 buildAttachArgs(newArgs, pid, exe, core, false); 397 JSnap.main(newArgs.toArray(new String[newArgs.size()])); 398 } 399 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 415 public static void main(String[] args) { 416 // Provide a help 417 if (args.length == 0) { 418 launcherHelp(); 419 return; 420 } 421 // No arguments imply help for debugd, jstack, jmap, jinfo but launch clhsdb and hsdb 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 } | 1 /* 2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. 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; 33 import sun.jvm.hotspot.tools.JSnap; 34 35 public class SALauncher { 36 37 private static boolean launcherHelp() { 38 System.out.println(" clhsdb \tcommand line debugger"); 39 System.out.println(" hsdb \tui debugger"); 40 System.out.println(" debugd --help\tto get more information"); 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"); 44 System.out.println(" jsnap --help\tto get more information"); 45 return false; 46 } 47 48 private static boolean commonHelp() { 49 // --pid <pid> 50 // --exe <exe> 51 // --core <core> 52 System.out.println(" --exe\t<executable image name>"); 53 System.out.println(" --core\t<path to coredump>"); 54 System.out.println(" --pid\t<pid of process to attach>"); 55 return false; 56 } 57 58 private static boolean debugdHelp() { 59 // [options] <pid> [server-id] 60 // [options] <executable> <core> [server-id] 61 System.out.println(" --serverid\t<unique id for this debug server>"); 62 return commonHelp(); 63 } 64 65 private static boolean jinfoHelp() { 66 // --flags -> -flags 67 // --sysprops -> -sysprops 68 System.out.println(" --flags\tto print VM flags"); 69 System.out.println(" --sysprops\tto print Java System properties"); 70 System.out.println(" <no option>\tto print both of the above"); 71 return commonHelp(); 72 } 73 74 private static boolean jmapHelp() { 75 // --heap -> -heap 76 // --binaryheap -> -heap:format=b 77 // --histo -> -histo 78 // --clstats -> -clstats 79 // --finalizerinfo -> -finalizerinfo 80 81 System.out.println(" <no option>\tto print same info as Solaris pmap"); 82 System.out.println(" --heap\tto print java heap summary"); 373 } 374 if (s.equals("core")) { 375 core = sg.getOptarg(); 376 continue; 377 } 378 if (s.equals("pid")) { 379 pid = sg.getOptarg(); 380 continue; 381 } 382 if (s.equals("all")) { 383 newArgs.add("-a"); 384 continue; 385 } 386 } 387 388 buildAttachArgs(newArgs, pid, exe, core, false); 389 JSnap.main(newArgs.toArray(new String[newArgs.size()])); 390 } 391 392 private static void runDEBUGD(String[] oldArgs) { 393 // By default SA agent classes prefer Windows process debugger 394 // to windbg debugger. SA expects special properties to be set 395 // to choose other debuggers. We will set those here before 396 // attaching to SA agent. 397 System.setProperty("sun.jvm.hotspot.debugger.useWindbgDebugger", "true"); 398 399 SAGetopt sg = new SAGetopt(oldArgs); 400 String[] longOpts = {"exe=", "core=", "pid=", "serverid="}; 401 402 ArrayList<String> newArgs = new ArrayList<>(); 403 String exe = null; 404 String pid = null; 405 String core = null; 406 String s = null; 407 String serverid = null; 408 409 while((s = sg.next(null, longOpts)) != null) { 410 if (s.equals("exe")) { 411 exe = sg.getOptarg(); 412 continue; 413 } 414 if (s.equals("core")) { 415 core = sg.getOptarg(); 416 continue; 417 } 418 if (s.equals("pid")) { 419 pid = sg.getOptarg(); 420 continue; 421 } 422 if (s.equals("serverid")) { 423 serverid = sg.getOptarg(); 424 continue; 425 } 426 } 427 428 buildAttachArgs(newArgs, pid, exe, core, false); 429 if (serverid != null) { 430 newArgs.add(serverid); 431 } 432 433 // delegate to the actual SA debug server. 434 sun.jvm.hotspot.DebugServer.main(newArgs.toArray(new String[newArgs.size()])); 435 } 436 437 public static void main(String[] args) { 438 // Provide a help 439 if (args.length == 0) { 440 launcherHelp(); 441 return; 442 } 443 // No arguments imply help for debugd, jstack, jmap, jinfo but launch clhsdb and hsdb 444 if (args.length == 1 && !args[0].equals("clhsdb") && !args[0].equals("hsdb")) { 445 toolHelp(args[0]); 446 return; 447 } 448 449 for (String arg : args) { 450 if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")) { 451 toolHelp(args[0]); 452 return; 453 } 454 } |