< prev index next >

test/jdk/com/sun/jdi/lib/jdb/JdbTest.java

Print this page

        

*** 21,44 **** * questions. */ package lib.jdb; - import jdk.test.lib.Utils; import jdk.test.lib.process.OutputAnalyzer; - import jdk.test.lib.process.ProcessTools; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.concurrent.TimeUnit; - import java.util.concurrent.TimeoutException; - import java.util.regex.Matcher; - import java.util.regex.Pattern; import java.util.stream.Collectors; public abstract class JdbTest { public static class LaunchOptions { --- 21,39 ----
*** 74,95 **** public JdbTest(String debuggeeClass, String sourceFilename) { this(new LaunchOptions(debuggeeClass).setSourceFilename(sourceFilename)); } protected Jdb jdb; ! protected Process debuggee; ! private final List<String> debuggeeOutput = new LinkedList<>(); private final LaunchOptions launchOptions; // returns the whole jdb output as a string public String getJdbOutput() { return jdb == null ? "" : jdb.getJdbOutput(); } // returns the whole debuggee output as a string public String getDebuggeeOutput() { ! return debuggeeOutput.stream().collect(Collectors.joining(lineSeparator)); } public void run() { try { setup(); --- 69,89 ---- public JdbTest(String debuggeeClass, String sourceFilename) { this(new LaunchOptions(debuggeeClass).setSourceFilename(sourceFilename)); } protected Jdb jdb; ! protected Debuggee debuggee; private final LaunchOptions launchOptions; // returns the whole jdb output as a string public String getJdbOutput() { return jdb == null ? "" : jdb.getJdbOutput(); } // returns the whole debuggee output as a string public String getDebuggeeOutput() { ! return debuggee == null ? "" : debuggee.getOutput(); } public void run() { try { setup();
*** 104,152 **** } } protected void setup() { /* run debuggee as: ! java -agentlib:jdwp=transport=dt_socket,address=0,server=n,suspend=y <debuggeeClass> it reports something like : Listening for transport dt_socket at address: 60810 after that connect jdb by: jdb -connect com.sun.jdi.SocketAttach:port=60810 */ // launch debuggee ! List<String> debuggeeArgs = new LinkedList<>(); ! // specify address=0 to automatically select free port ! debuggeeArgs.add("-agentlib:jdwp=transport=dt_socket,address=0,server=y,suspend=y"); ! debuggeeArgs.addAll(launchOptions.debuggeeOptions); ! debuggeeArgs.add(launchOptions.debuggeeClass); ! ProcessBuilder pbDebuggee = ProcessTools.createJavaProcessBuilder(true, debuggeeArgs.toArray(new String[0])); ! ! // debuggeeListen[0] - transport, debuggeeListen[1] - address ! String[] debuggeeListen = new String[2]; ! Pattern listenRegexp = Pattern.compile("Listening for transport \\b(.+)\\b at address: \\b(\\d+)\\b"); ! try { ! debuggee = ProcessTools.startProcess("debuggee", pbDebuggee, ! s -> debuggeeOutput.add(s), // output consumer ! s -> { // warm-up predicate ! Matcher m = listenRegexp.matcher(s); ! if (!m.matches()) { ! return false; ! } ! debuggeeListen[0] = m.group(1); ! debuggeeListen[1] = m.group(2); ! return true; ! }, ! 30, TimeUnit.SECONDS); ! } catch (IOException | InterruptedException | TimeoutException ex) { ! throw new RuntimeException("failed to launch debuggee", ex); ! } // launch jdb try { ! jdb = new Jdb("-connect", "com.sun.jdi.SocketAttach:port=" + debuggeeListen[1]); } catch (Throwable ex) { // terminate debuggee if something went wrong ! debuggee.destroy(); throw ex; } // wait while jdb is initialized jdb.waitForPrompt(1, false); } --- 98,123 ---- } } protected void setup() { /* run debuggee as: ! java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y <debuggeeClass> it reports something like : Listening for transport dt_socket at address: 60810 after that connect jdb by: jdb -connect com.sun.jdi.SocketAttach:port=60810 */ // launch debuggee ! debuggee = Debuggee.launcher(launchOptions.debuggeeClass) ! .addOptions(launchOptions.debuggeeOptions) ! .launch(); // launch jdb try { ! jdb = new Jdb("-connect", "com.sun.jdi.SocketAttach:port=" + debuggee.getAddress()); } catch (Throwable ex) { // terminate debuggee if something went wrong ! debuggee.shutdown(); throw ex; } // wait while jdb is initialized jdb.waitForPrompt(1, false); }
*** 156,174 **** protected void shutdown() { if (jdb != null) { jdb.shutdown(); } // shutdown debuggee ! if (debuggee != null && debuggee.isAlive()) { ! try { ! debuggee.waitFor(Utils.adjustTimeout(10), TimeUnit.SECONDS); ! } catch (InterruptedException e) { ! // ignore ! } finally { ! if (debuggee.isAlive()) { ! debuggee.destroy(); ! } } } } protected static final String lineSeparator = System.getProperty("line.separator"); --- 127,139 ---- protected void shutdown() { if (jdb != null) { jdb.shutdown(); } // shutdown debuggee ! if (debuggee != null) { ! if (!debuggee.waitFor(10, TimeUnit.SECONDS)) { ! debuggee.shutdown(); } } } protected static final String lineSeparator = System.getProperty("line.separator");
< prev index next >