static String excludesString() { StringBuffer buffer = new StringBuffer(); for (String pattern : excludes()) { buffer.append(pattern); buffer.append(","); } return buffer.toString(); }
static String excludesString() { Iterator iter = excludes().iterator(); StringBuffer buffer = new StringBuffer(); while (iter.hasNext()) { String pattern = (String) iter.next(); buffer.append(pattern); buffer.append(","); } return buffer.toString(); }
private int printThreadGroup(OutputSink out, ThreadGroupReference tg, int iThread) { out.println("Group " + tg.name() + ":"); List<ThreadReference> tlist = tg.threads(); int maxId = 0; int maxName = 0; for (int i = 0; i < tlist.size(); i++) { ThreadReference thr = tlist.get(i); int len = Utils.description(thr).length(); if (len > maxId) { maxId = len; } String name = thr.name(); int iDot = name.lastIndexOf('.'); if (iDot >= 0 && name.length() > iDot) { name = name.substring(iDot + 1); } if (name.length() > maxName) { maxName = name.length(); } } String maxNumString = String.valueOf(iThread + tlist.size()); int maxNumDigits = maxNumString.length(); for (int i = 0; i < tlist.size(); i++) { ThreadReference thr = tlist.get(i); char buf[] = new char[80]; for (int j = 0; j < 79; j++) { buf[j] = ' '; } buf[79] = '\0'; StringBuffer sbOut = new StringBuffer(); sbOut.append(buf); // Right-justify the thread number at start of output string String numString = String.valueOf(iThread + i + 1); sbOut.insert(maxNumDigits - numString.length(), numString); sbOut.insert(maxNumDigits, "."); int iBuf = maxNumDigits + 2; sbOut.insert(iBuf, Utils.description(thr)); iBuf += maxId + 1; String name = thr.name(); int iDot = name.lastIndexOf('.'); if (iDot >= 0 && name.length() > iDot) { name = name.substring(iDot + 1); } sbOut.insert(iBuf, name); iBuf += maxName + 1; sbOut.insert(iBuf, Utils.getStatus(thr)); sbOut.setLength(79); out.println(sbOut.toString()); } for (ThreadGroupReference tg0 : tg.threadGroups()) { if (!tg.equals(tg0)) { // TODO ref mgt iThread += printThreadGroup(out, tg0, iThread + tlist.size()); } } return tlist.size(); }
@NonNls String getSignature() { if (eof()) return ""; switch (get()) { case 'Z': return "boolean"; case 'B': return "byte"; case 'C': return "char"; case 'S': return "short"; case 'I': return "int"; case 'J': return "long"; case 'F': return "float"; case 'D': return "double"; case 'V': return "void"; case 'L': int start = pos; pos = buffer.indexOf(';', start) + 1; LOG.assertTrue(pos > 0); return buffer.substring(start, pos - 1).replace('/', '.'); case '[': return getSignature() + "[]"; case '(': StringBuffer result = new StringBuffer("("); String separator = ""; while (peek() != ')') { result.append(separator); result.append(getSignature()); separator = ", "; } get(); result.append(")"); return getSignature() + " " + getClassName() + "." + getMethodName() + " " + result; default: // LOG.assertTrue(false, "unknown signature " + buffer); return null; } }
private boolean doLoad(boolean suspended, StringTokenizer t) throws NoSessionException { String clname; if (!t.hasMoreTokens()) { clname = context.getMainClassName(); if (!clname.equals("")) { // Run from prevously-set class name. try { String vmArgs = context.getVmArguments(); runtime.run(suspended, vmArgs, clname, context.getProgramArguments()); return true; } catch (VMLaunchFailureException e) { env.failure("Attempt to launch main class \"" + clname + "\" failed."); } } else { env.failure("No main class specifed and no current default defined."); } } else { clname = t.nextToken(); StringBuffer sbuf = new StringBuffer(); // Allow VM arguments to be specified here? while (t.hasMoreTokens()) { String tok = t.nextToken(); sbuf.append(tok); if (t.hasMoreTokens()) { sbuf.append(' '); } } String args = sbuf.toString(); try { String vmArgs = context.getVmArguments(); runtime.run(suspended, vmArgs, clname, args); context.setMainClassName(clname); // context.setVmArguments(vmArgs); context.setProgramArguments(args); return true; } catch (VMLaunchFailureException e) { env.failure("Attempt to launch main class \"" + clname + "\" failed."); } } return false; }
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); }