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.tools;
26
27 import java.io.PrintStream;
28
29 import sun.jvm.hotspot.HotSpotAgent;
30 import sun.jvm.hotspot.debugger.DebuggerException;
31 import sun.jvm.hotspot.debugger.JVMDebugger;
32 import sun.jvm.hotspot.runtime.VM;
33
34 // generic command line or GUI tool.
35 // override run & code main as shown below.
36
37 public abstract class Tool implements Runnable {
38 private HotSpotAgent agent;
39 private JVMDebugger jvmDebugger;
40 private int debugeeType;
41
42 // debugeeType is one of constants below
43 protected static final int DEBUGEE_PID = 0;
44 protected static final int DEBUGEE_CORE = 1;
45 protected static final int DEBUGEE_REMOTE = 2;
46
47 public Tool() {
48 }
49
81 name = "java " + getName();
82 } else {
83 name = getName();
84 }
85 System.out.println("Usage: " + name + " [option] <pid>");
86 System.out.println("\t\t(to connect to a live java process)");
87 System.out.println(" or " + name + " [option] <executable> <core>");
88 System.out.println("\t\t(to connect to a core file)");
89 System.out.println(" or " + name + " [option] [server_id@]<remote server IP or hostname>");
90 System.out.println("\t\t(to connect to a remote debug server)");
91 System.out.println();
92 System.out.println("where option must be one of:");
93 printFlagsUsage();
94 }
95
96 protected void printFlagsUsage() {
97 System.out.println(" -h | -help\tto print this help message");
98 }
99
100 protected void usage() {
101 printUsage();
102 }
103
104 /*
105 Derived class main should be of the following form:
106
107 public static void main(String[] args) {
108 <derived class> obj = new <derived class>;
109 obj.execute(args);
110 }
111
112 */
113
114 protected void execute(String[] args) {
115 int returnStatus = 1;
116
117 try {
118 returnStatus = start(args);
119 } finally {
120 stop();
121 }
|
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.tools;
26
27 import java.io.PrintStream;
28
29 import sun.jvm.hotspot.HotSpotAgent;
30 import sun.jvm.hotspot.SALauncher;
31 import sun.jvm.hotspot.debugger.DebuggerException;
32 import sun.jvm.hotspot.debugger.JVMDebugger;
33 import sun.jvm.hotspot.runtime.VM;
34
35 // generic command line or GUI tool.
36 // override run & code main as shown below.
37
38 public abstract class Tool implements Runnable {
39 private HotSpotAgent agent;
40 private JVMDebugger jvmDebugger;
41 private int debugeeType;
42
43 // debugeeType is one of constants below
44 protected static final int DEBUGEE_PID = 0;
45 protected static final int DEBUGEE_CORE = 1;
46 protected static final int DEBUGEE_REMOTE = 2;
47
48 public Tool() {
49 }
50
82 name = "java " + getName();
83 } else {
84 name = getName();
85 }
86 System.out.println("Usage: " + name + " [option] <pid>");
87 System.out.println("\t\t(to connect to a live java process)");
88 System.out.println(" or " + name + " [option] <executable> <core>");
89 System.out.println("\t\t(to connect to a core file)");
90 System.out.println(" or " + name + " [option] [server_id@]<remote server IP or hostname>");
91 System.out.println("\t\t(to connect to a remote debug server)");
92 System.out.println();
93 System.out.println("where option must be one of:");
94 printFlagsUsage();
95 }
96
97 protected void printFlagsUsage() {
98 System.out.println(" -h | -help\tto print this help message");
99 }
100
101 protected void usage() {
102 StackWalker walker = StackWalker.getInstance(
103 StackWalker.Option.RETAIN_CLASS_REFERENCE);
104 Boolean throughSALauncher = walker.walk(s ->
105 s.map(StackWalker.StackFrame::getDeclaringClass)
106 .anyMatch(c -> c.equals(SALauncher.class)));
107 if (throughSALauncher.booleanValue()) {
108 String toolName = this.getClass().getSimpleName().toLowerCase();
109 SALauncher.toolHelp(toolName);
110 } else {
111 printUsage();
112 }
113 }
114
115 /*
116 Derived class main should be of the following form:
117
118 public static void main(String[] args) {
119 <derived class> obj = new <derived class>;
120 obj.execute(args);
121 }
122
123 */
124
125 protected void execute(String[] args) {
126 int returnStatus = 1;
127
128 try {
129 returnStatus = start(args);
130 } finally {
131 stop();
132 }
|