static ReferenceType getReferenceTypeFromToken(String idToken) { ReferenceType cls = null; if (Character.isDigit(idToken.charAt(0))) { cls = null; } else if (idToken.startsWith("*.")) { // This notation saves typing by letting the user omit leading // package names. The first // loaded class whose name matches this limited regular // expression is selected. idToken = idToken.substring(1); for (ReferenceType type : Env.vm().allClasses()) { if (type.name().endsWith(idToken)) { cls = type; break; } } } else { // It's a class name List<ReferenceType> classes = Env.vm().classesByName(idToken); if (classes.size() > 0) { // TO DO: handle multiples cls = classes.get(0); } } return cls; }
synchronized VirtualMachine open() { if (connector instanceof LaunchingConnector) { vm = launchTarget(); } else if (connector instanceof AttachingConnector) { vm = attachTarget(); } else if (connector instanceof ListeningConnector) { vm = listenTarget(); } else { throw new InternalError(MessageOutput.format("Invalid connect type")); } vm.setDebugTraceMode(traceFlags); if (vm.canBeModified()) { setEventRequests(vm); resolveEventRequests(); } /* * Now that the vm connection is open, fetch the debugee * classpath and set up a default sourcepath. * (Unless user supplied a sourcepath on the command line) * (Bug ID 4186582) */ if (Env.getSourcePath().length() == 0) { if (vm instanceof PathSearchingVirtualMachine) { PathSearchingVirtualMachine psvm = (PathSearchingVirtualMachine) vm; Env.setSourcePath(psvm.classPath()); } else { Env.setSourcePath("."); } } return vm; }
static ThreadGroupReference group() { if (group == null) { // Current thread group defaults to the first top level // thread group. setThreadGroup((ThreadGroupReference) Env.vm().topLevelThreadGroups().get(0)); } return group; }
private static void initThreads() { if (!gotInitialThreads) { Iterator iter = Env.vm().allThreads().iterator(); while (iter.hasNext()) { ThreadReference thread = (ThreadReference) iter.next(); threads.add(new ThreadInfo(thread)); } gotInitialThreads = true; } }
public static void main(String argv[]) throws MissingResourceException { redirectOutMessage(); String cmdLine = ""; String javaArgs = ""; int traceFlags = VirtualMachine.TRACE_NONE; boolean launchImmediately = false; String connectSpec = null; MessageOutput.textResources = ResourceBundle.getBundle( "com.sun.tools.example.debug.tty.TTYResources", Locale.getDefault()); for (int i = 0; i < argv.length; i++) { String token = argv[i]; if (token.equals("-dbgtrace")) { if ((i == argv.length - 1) || !Character.isDigit(argv[i + 1].charAt(0))) { traceFlags = VirtualMachine.TRACE_ALL; } else { String flagStr = ""; try { flagStr = argv[++i]; traceFlags = Integer.decode(flagStr).intValue(); } catch (NumberFormatException nfe) { usageError("dbgtrace flag value must be an integer:", flagStr); return; } } } else if (token.equals("-X")) { usageError("Use java minus X to see"); return; } else if ( // Standard VM options passed on token.equals("-v") || token.startsWith("-v:") || // -v[:...] token.startsWith("-verbose") || // -verbose[:...] token.startsWith("-D") || // -classpath handled below // NonStandard options passed on token.startsWith("-X") || // Old-style options (These should remain in place as long as // the standard VM accepts them) token.equals("-noasyncgc") || token.equals("-prof") || token.equals("-verify") || token.equals("-noverify") || token.equals("-verifyremote") || token.equals("-verbosegc") || token.startsWith("-ms") || token.startsWith("-mx") || token.startsWith("-ss") || token.startsWith("-oss")) { javaArgs = addArgument(javaArgs, token); } else if (token.equals("-tclassic")) { usageError("Classic VM no longer supported."); return; } else if (token.equals("-tclient")) { // -client must be the first one javaArgs = "-client " + javaArgs; } else if (token.equals("-tserver")) { // -server must be the first one javaArgs = "-server " + javaArgs; } else if (token.equals("-sourcepath")) { if (i == (argv.length - 1)) { usageError("No sourcepath specified."); return; } Env.setSourcePath(argv[++i]); } else if (token.equals("-classpath")) { if (i == (argv.length - 1)) { usageError("No classpath specified."); return; } javaArgs = addArgument(javaArgs, token); javaArgs = addArgument(javaArgs, argv[++i]); } else if (token.equals("-attach")) { if (connectSpec != null) { usageError("cannot redefine existing connection", token); return; } if (i == (argv.length - 1)) { usageError("No attach address specified."); return; } String address = argv[++i]; /* * -attach is shorthand for one of the reference implementation's * attaching connectors. Use the shared memory attach if it's * available; otherwise, use sockets. Build a connect * specification string based on this decision. */ if (supportsSharedMemory()) { connectSpec = "com.sun.jdi.SharedMemoryAttach:name=" + address; } else { String suboptions = addressToSocketArgs(address); connectSpec = "com.sun.jdi.SocketAttach:" + suboptions; } } else if (token.equals("-listen") || token.equals("-listenany")) { if (connectSpec != null) { usageError("cannot redefine existing connection", token); return; } String address = null; if (token.equals("-listen")) { if (i == (argv.length - 1)) { usageError("No attach address specified."); return; } address = argv[++i]; } /* * -listen[any] is shorthand for one of the reference implementation's * listening connectors. Use the shared memory listen if it's * available; otherwise, use sockets. Build a connect * specification string based on this decision. */ if (supportsSharedMemory()) { connectSpec = "com.sun.jdi.SharedMemoryListen:"; if (address != null) { connectSpec += ("name=" + address); } } else { connectSpec = "com.sun.jdi.SocketListen:"; if (address != null) { connectSpec += addressToSocketArgs(address); } } } else if (token.equals("-launch")) { launchImmediately = true; } else if (token.equals("-listconnectors")) { Commands evaluator = new Commands(); evaluator.commandConnectors(Bootstrap.virtualMachineManager()); return; } else if (token.equals("-connect")) { /* * -connect allows the user to pick the connector * used in bringing up the target VM. This allows * use of connectors other than those in the reference * implementation. */ if (connectSpec != null) { usageError("cannot redefine existing connection", token); return; } if (i == (argv.length - 1)) { usageError("No connect specification."); return; } connectSpec = argv[++i]; } else if (token.equals("-help")) { usage(); } else if (token.equals("-version")) { Commands evaluator = new Commands(); evaluator.commandVersion(progname, Bootstrap.virtualMachineManager()); System.exit(0); } else if (token.startsWith("-")) { usageError("invalid option", token); return; } else { // Everything from here is part of the command line cmdLine = addArgument("", token); for (i++; i < argv.length; i++) { cmdLine = addArgument(cmdLine, argv[i]); } break; } } /* * Unless otherwise specified, set the default connect spec. */ /* * Here are examples of jdb command lines and how the options * are interpreted as arguments to the program being debugged. * arg1 arg2 * ---- ---- * jdb hello a b a b * jdb hello "a b" a b * jdb hello a,b a,b * jdb hello a, b a, b * jdb hello "a, b" a, b * jdb -connect "com.sun.jdi.CommandLineLaunch:main=hello a,b" illegal * jdb -connect com.sun.jdi.CommandLineLaunch:main=hello "a,b" illegal * jdb -connect 'com.sun.jdi.CommandLineLaunch:main=hello "a,b"' arg1 = a,b * jdb -connect 'com.sun.jdi.CommandLineLaunch:main=hello "a b"' arg1 = a b * jdb -connect 'com.sun.jdi.CommandLineLaunch:main=hello a b' arg1 = a arg2 = b * jdb -connect 'com.sun.jdi.CommandLineLaunch:main=hello "a," b' arg1 = a, arg2 = b */ if (connectSpec == null) { connectSpec = "com.sun.jdi.CommandLineLaunch:"; } else if (!connectSpec.endsWith(",") && !connectSpec.endsWith(":")) { connectSpec += ","; // (Bug ID 4285874) } cmdLine = cmdLine.trim(); javaArgs = javaArgs.trim(); if (cmdLine.length() > 0) { if (!connectSpec.startsWith("com.sun.jdi.CommandLineLaunch:")) { usageError("Cannot specify command line with connector:", connectSpec); return; } connectSpec += "main=" + cmdLine + ","; } if (javaArgs.length() > 0) { if (!connectSpec.startsWith("com.sun.jdi.CommandLineLaunch:")) { usageError("Cannot specify target vm arguments with connector:", connectSpec); return; } connectSpec += "options=" + javaArgs + ","; } try { if (!connectSpec.endsWith(",")) { connectSpec += ","; // (Bug ID 4285874) } Env.init(connectSpec, launchImmediately, traceFlags); new ThreadDumper(); } catch (Exception e) { MessageOutput.printException("Internal exception:", e); } }