1 /* 2 * Copyright (c) 1998, 2011, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 * This source code is provided to illustrate the usage of a given feature 28 * or technique and has been deliberately simplified. Additional steps 29 * required for a production-quality application, such as security checks, 30 * input validation and proper error handling, might not be present in 31 * this sample code. 32 */ 33 34 35 package com.sun.tools.example.debug.gui; 36 37 import java.io.*; 38 import javax.swing.*; 39 import javax.swing.border.*; 40 import java.awt.*; 41 import java.awt.event.*; 42 43 import com.sun.jdi.*; 44 import com.sun.tools.example.debug.bdi.*; 45 46 public class GUI extends JPanel { 47 48 private static final long serialVersionUID = 3292463234530679091L; 49 private CommandTool cmdTool; 50 private ApplicationTool appTool; 51 //###HACK## 52 //### There is currently dirty code in Environment that 53 //### accesses this directly. 54 //private SourceTool srcTool; 55 public static SourceTool srcTool; 56 57 private SourceTreeTool sourceTreeTool; 58 private ClassTreeTool classTreeTool; 59 private ThreadTreeTool threadTreeTool; 60 private StackTraceTool stackTool; 61 private MonitorTool monitorTool; 62 63 public static final String progname = "javadt"; 64 public static final String version = "1.0Beta"; //### FIX ME. 65 public static final String windowBanner = "Java(tm) platform Debug Tool"; 66 67 private Font fixedFont = new Font("monospaced", Font.PLAIN, 10); 68 69 private GUI(Environment env) { 70 setLayout(new BorderLayout()); 71 72 setBorder(new EmptyBorder(5, 5, 5, 5)); 73 74 add(new JDBToolBar(env), BorderLayout.NORTH); 75 76 srcTool = new SourceTool(env); 77 srcTool.setPreferredSize(new java.awt.Dimension(500, 300)); 78 srcTool.setTextFont(fixedFont); 79 80 stackTool = new StackTraceTool(env); 81 stackTool.setPreferredSize(new java.awt.Dimension(500, 100)); 82 83 monitorTool = new MonitorTool(env); 84 monitorTool.setPreferredSize(new java.awt.Dimension(500, 50)); 85 86 JSplitPane right = new JSplitPane(JSplitPane.VERTICAL_SPLIT, srcTool, 87 new JSplitPane(JSplitPane.VERTICAL_SPLIT, stackTool, monitorTool)); 88 89 sourceTreeTool = new SourceTreeTool(env); 90 sourceTreeTool.setPreferredSize(new java.awt.Dimension(200, 450)); 91 92 classTreeTool = new ClassTreeTool(env); 93 classTreeTool.setPreferredSize(new java.awt.Dimension(200, 450)); 94 95 threadTreeTool = new ThreadTreeTool(env); 96 threadTreeTool.setPreferredSize(new java.awt.Dimension(200, 450)); 97 98 JTabbedPane treePane = new JTabbedPane(SwingConstants.BOTTOM); 99 treePane.addTab("Source", null, sourceTreeTool); 100 treePane.addTab("Classes", null, classTreeTool); 101 treePane.addTab("Threads", null, threadTreeTool); 102 103 JSplitPane centerTop = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePane, right); 104 105 cmdTool = new CommandTool(env); 106 cmdTool.setPreferredSize(new java.awt.Dimension(700, 150)); 107 108 appTool = new ApplicationTool(env); 109 appTool.setPreferredSize(new java.awt.Dimension(700, 200)); 110 111 JSplitPane centerBottom = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cmdTool, appTool); 112 // centerBottom.setPreferredSize(new java.awt.Dimension(700, 350)); 113 114 JSplitPane center = new JSplitPane(JSplitPane.VERTICAL_SPLIT, centerTop, centerBottom); 115 116 add(center, BorderLayout.CENTER); 117 118 119 } 120 121 private static void usage() { 122 String separator = File.pathSeparator; 123 System.out.println("Usage: " + progname + " <options> <class> <arguments>"); 124 System.out.println(); 125 System.out.println("where options include:"); 126 System.out.println(" -help print out this message and exit"); 127 System.out.println(" -sourcepath <directories separated by \"" + 128 separator + "\">"); 129 System.out.println(" list directories in which to look for source files"); 130 System.out.println(" -remote <hostname>:<port-number>"); 131 System.out.println(" host machine and port number of interpreter to attach to"); 132 System.out.println(" -dbgtrace [flags] print info for debugging " + progname); 133 System.out.println(); 134 System.out.println("options forwarded to debuggee process:"); 135 System.out.println(" -v -verbose[:class|gc|jni]"); 136 System.out.println(" turn on verbose mode"); 137 System.out.println(" -D<name>=<value> set a system property"); 138 System.out.println(" -classpath <directories separated by \"" + 139 separator + "\">"); 140 System.out.println(" list directories in which to look for classes"); 141 System.out.println(" -X<option> non-standard debuggee VM option"); 142 System.out.println(); 143 System.out.println("<class> is the name of the class to begin debugging"); 144 System.out.println("<arguments> are the arguments passed to the main() method of <class>"); 145 System.out.println(); 146 System.out.println("For command help type 'help' at " + progname + " prompt"); 147 } 148 149 public static void main(String argv[]) { 150 String clsName = ""; 151 String progArgs = ""; 152 String javaArgs = ""; 153 final Environment env = new Environment(); 154 155 JPanel mainPanel = new GUI(env); 156 157 ContextManager context = env.getContextManager(); 158 ExecutionManager runtime = env.getExecutionManager(); 159 160 for (int i = 0; i < argv.length; i++) { 161 String token = argv[i]; 162 if (token.equals("-dbgtrace")) { 163 if ((i == argv.length - 1) || 164 ! Character.isDigit(argv[i+1].charAt(0))) { 165 runtime.setTraceMode(VirtualMachine.TRACE_ALL); 166 } else { 167 String flagStr = argv[++i]; 168 runtime.setTraceMode(Integer.decode(flagStr).intValue()); 169 } 170 } else if (token.equals("-X")) { 171 System.out.println( 172 "Use 'java -X' to see the available non-standard options"); 173 System.out.println(); 174 usage(); 175 System.exit(1); 176 } else if ( 177 // Standard VM options passed on 178 token.equals("-v") || token.startsWith("-v:") || // -v[:...] 179 token.startsWith("-verbose") || // -verbose[:...] 180 token.startsWith("-D") || 181 // NonStandard options passed on 182 token.startsWith("-X") || 183 // Old-style options 184 // (These should remain in place as long as the standard VM accepts them) 185 token.equals("-noasyncgc") || token.equals("-prof") || 186 token.equals("-verify") || token.equals("-noverify") || 187 token.equals("-verifyremote") || 188 token.equals("-verbosegc") || 189 token.startsWith("-ms") || token.startsWith("-mx") || 190 token.startsWith("-ss") || token.startsWith("-oss") ) { 191 javaArgs += token + " "; 192 } else if (token.equals("-sourcepath")) { 193 if (i == (argv.length - 1)) { 194 System.out.println("No sourcepath specified."); 195 usage(); 196 System.exit(1); 197 } 198 env.getSourceManager().setSourcePath(new SearchPath(argv[++i])); 199 } else if (token.equals("-classpath")) { 200 if (i == (argv.length - 1)) { 201 System.out.println("No classpath specified."); 202 usage(); 203 System.exit(1); 204 } 205 env.getClassManager().setClassPath(new SearchPath(argv[++i])); 206 } else if (token.equals("-remote")) { 207 if (i == (argv.length - 1)) { 208 System.out.println("No remote specified."); 209 usage(); 210 System.exit(1); 211 } 212 env.getContextManager().setRemotePort(argv[++i]); 213 } else if (token.equals("-help")) { 214 usage(); 215 System.exit(0); 216 } else if (token.equals("-version")) { 217 System.out.println(progname + " version " + version); 218 System.exit(0); 219 } else if (token.startsWith("-")) { 220 System.out.println("invalid option: " + token); 221 usage(); 222 System.exit(1); 223 } else { 224 // Everything from here is part of the command line 225 clsName = token; 226 for (i++; i < argv.length; i++) { 227 progArgs += argv[i] + " "; 228 } 229 break; 230 } 231 } 232 233 context.setMainClassName(clsName); 234 context.setProgramArguments(progArgs); 235 context.setVmArguments(javaArgs); 236 237 // Force Cross Platform L&F 238 try { 239 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 240 // If you want the System L&F instead, comment out the above line and 241 // uncomment the following: 242 // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 243 } catch (Exception exc) { 244 System.err.println("Error loading L&F: " + exc); 245 } 246 247 JFrame frame = new JFrame(); 248 frame.setBackground(Color.lightGray); 249 frame.setTitle(windowBanner); 250 frame.setJMenuBar(new JDBMenuBar(env)); 251 frame.setContentPane(mainPanel); 252 253 frame.addWindowListener(new WindowAdapter() { 254 @Override 255 public void windowClosing(WindowEvent e) { 256 env.terminate(); 257 } 258 }); 259 260 frame.pack(); 261 frame.setVisible(true); 262 263 } 264 265 }