/* We look for System property sun.jvm.hotspot.jdi.<vm version>. * This property should have the value of JDK HOME directory for * the given <vm version>. */ private static String getSAClassPathForVM(String vmVersion) { final String prefix = "sun.jvm.hotspot.jdi."; // look for exact match of VM version String jvmHome = System.getProperty(prefix + vmVersion); if (DEBUG) { System.out.println("looking for System property " + prefix + vmVersion); } if (jvmHome == null) { // omit chars after first '-' in VM version and try // for example, in '1.5.0-b55' we take '1.5.0' int index = vmVersion.indexOf('-'); if (index != -1) { vmVersion = vmVersion.substring(0, index); if (DEBUG) { System.out.println("looking for System property " + prefix + vmVersion); } jvmHome = System.getProperty(prefix + vmVersion); } if (jvmHome == null) { // System property is not set if (DEBUG) { System.out.println("can't locate JDK home for " + vmVersion); } return null; } } if (DEBUG) { System.out.println("JDK home for " + vmVersion + " is " + jvmHome); } // sa-jdi is in $JDK_HOME/lib directory StringBuffer buf = new StringBuffer(); buf.append(jvmHome); buf.append(File.separatorChar); buf.append("lib"); buf.append(File.separatorChar); buf.append("sa-jdi.jar"); return buf.toString(); }
private VirtualMachine launch(DebuggerInfo info) throws DebuggerException { // create process & read password for local debugging // create main class & arguments ............................................... StringBuffer sb = new StringBuffer(); sb.append(mainClassName); String[] infoArgs = info.getArguments(); int i, k = infoArgs.length; for (i = 0; i < k; i++) sb.append(" \"").append(infoArgs[i]).append('"'); // NOI18N String main = new String(sb); // create connector .............................................................. VirtualMachineManager vmm = Bootstrap.virtualMachineManager(); java.util.List lcs = vmm.launchingConnectors(); k = lcs.size(); for (i = 0; i < k; i++) if (((LaunchingConnector) lcs.get(i)).name().indexOf("RawCommandLineLaunch") >= 0) // NOI18N break; if (i == k) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_find_launcher")) .format( new Object[] { "RawCommandLineLaunch" // NOI18N })); } LaunchingConnector lc = (LaunchingConnector) lcs.get(i); String transport = lc.transport().name(); // create commandLine & NbProcessDescriptor .............................. NbProcessDescriptor debugerProcess; if (info instanceof ProcessDebuggerInfo) debugerProcess = ((ProcessDebuggerInfo) info).getDebuggerProcess(); else debugerProcess = ProcessDebuggerType.DEFAULT_DEBUGGER_PROCESS; // generate password String password; if (transport.equals("dt_shmem")) { // NOI18N connector = getAttachingConnectorFor("dt_shmem"); password = generatePassword(); args = connector.defaultArguments(); ((Argument) args.get("name")).setValue(password); } else { try { java.net.ServerSocket ss = new java.net.ServerSocket(0); password = "" + ss.getLocalPort(); // NOI18N ss.close(); } catch (java.io.IOException e) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_Cannot_find_empty_local_port")) .format(new Object[] {e.toString()})); } connector = getAttachingConnectorFor("dt_socket"); args = connector.defaultArguments(); ((Argument) args.get("port")).setValue(password); } HashMap map = Utils.processDebuggerInfo( info, "-Xdebug -Xnoagent -Xrunjdwp:transport=" + // NOI18N transport + ",address=" + // NOI18N password + ",suspend=y ", // NOI18N main); MapFormat format = new MapFormat(map); String commandLine = format.format( debugerProcess.getProcessName() + " " + // NOI18N debugerProcess.getArguments()); println(commandLine, ERR_OUT); /* We mus wait on process start to connect... try { process = debugerProcess.exec (format); } catch (java.io.IOException exc) { finishDebugger (); throw new DebuggerException ( new MessageFormat (bundle.getString ("EXC_While_create_debuggee")). format (new Object[] { debugerProcess.getProcessName (), exc.toString () }), exc ); } return connect ( null, connector, args );*/ /* S ystem.out.println ("attaching: "); Utils.showConnectors (vmm.attachingConnectors ()); S ystem.out.println ("launching: "); Utils.showConnectors (vmm.launchingConnectors ()); S ystem.out.println ("listening: "); Utils.showConnectors (vmm.listeningConnectors ());*/ // set debugger-start arguments Map params = lc.defaultArguments(); ((Argument) params.get("command")) .setValue( // NOI18N commandLine); ((Argument) params.get("address")) .setValue( // NOI18N password); // launch VM try { return lc.launch(params); } catch (VMStartException exc) { showOutput(process = exc.process(), ERR_OUT, ERR_OUT); finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_create_debuggee")) .format( new Object[] {format.format(debugerProcess.getProcessName()), exc.toString()}), exc); } catch (Exception exc) { finishDebugger(); throw new DebuggerException( new MessageFormat(bundle.getString("EXC_While_create_debuggee")) .format( new Object[] {format.format(debugerProcess.getProcessName()), exc.toString()}), exc); } }
private static String generatePassword() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < 4; i++) sb.append((char) (random.nextInt(26) + 'a')); return new String(sb); }