102 } catch (IOException | InterruptedException | TimeoutException ex) { |
102 } catch (IOException | InterruptedException | TimeoutException ex) { |
103 throw new RuntimeException("failed to launch debuggee", ex); |
103 throw new RuntimeException("failed to launch debuggee", ex); |
104 } |
104 } |
105 |
105 |
106 // launch jdb |
106 // launch jdb |
107 ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getTestJDKTool("jdb")); |
|
108 pb.command().add("-connect"); |
|
109 pb.command().add("com.sun.jdi.SocketAttach:port=" + debuggeeListen[1]); |
|
110 System.out.println("Launching jdb:" + pb.command().stream().collect(Collectors.joining(" "))); |
|
111 try { |
107 try { |
112 jdb = pb.start(); |
108 ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getTestJDKTool("jdb")); |
113 } catch (IOException ex) { |
109 pb.command().add("-connect"); |
114 throw new RuntimeException("failed to launch pdb", ex); |
110 pb.command().add("com.sun.jdi.SocketAttach:port=" + debuggeeListen[1]); |
115 } |
111 System.out.println("Launching jdb:" + pb.command().stream().collect(Collectors.joining(" "))); |
116 StreamPumper stdout = new StreamPumper(jdb.getInputStream()); |
112 try { |
117 StreamPumper stderr = new StreamPumper(jdb.getErrorStream()); |
113 jdb = pb.start(); |
118 |
114 } catch (IOException ex) { |
119 stdout.addPump(new StreamPumper.StreamPump(outputHandler)); |
115 throw new RuntimeException("failed to launch pdb", ex); |
120 stderr.addPump(new StreamPumper.StreamPump(outputHandler)); |
116 } |
121 |
117 StreamPumper stdout = new StreamPumper(jdb.getInputStream()); |
122 stdout.process(); |
118 StreamPumper stderr = new StreamPumper(jdb.getErrorStream()); |
123 stderr.process(); |
119 |
124 |
120 stdout.addPump(new StreamPumper.StreamPump(outputHandler)); |
125 inputWriter = new PrintWriter(jdb.getOutputStream(), true); |
121 stderr.addPump(new StreamPumper.StreamPump(outputHandler)); |
126 |
122 |
|
123 stdout.process(); |
|
124 stderr.process(); |
|
125 |
|
126 inputWriter = new PrintWriter(jdb.getOutputStream(), true); |
|
127 } catch (Throwable ex) { |
|
128 // terminate debuggee if something went wrong |
|
129 debuggee.destroy(); |
|
130 throw ex; |
|
131 } |
127 } |
132 } |
128 |
133 |
129 private final Process jdb; |
134 private final Process jdb; |
130 private final Process debuggee; |
135 private final Process debuggee; |
131 private final OutputHandler outputHandler = new OutputHandler(); |
136 private final OutputHandler outputHandler = new OutputHandler(); |
355 |
360 |
356 // gets output after the last {@ reset}. |
361 // gets output after the last {@ reset}. |
357 // returned data becomes invalid after {@reset}. |
362 // returned data becomes invalid after {@reset}. |
358 public synchronized List<String> get() { |
363 public synchronized List<String> get() { |
359 if (updated()) { |
364 if (updated()) { |
360 String[] newLines = outStream.toString().split(lineSeparator); |
365 // we don't want to discard empty lines |
|
366 String[] newLines = outStream.toString().split("\\R", -1); |
361 if (!cachedData.isEmpty()) { |
367 if (!cachedData.isEmpty()) { |
362 // concat the last line if previous data had no EOL |
368 // concat the last line if previous data had no EOL |
363 newLines[0] = cachedData.remove(cachedData.size()-1) + newLines[0]; |
369 newLines[0] = cachedData.remove(cachedData.size()-1) + newLines[0]; |
364 } |
370 } |
365 cachedData.addAll(Arrays.asList(newLines)); |
371 cachedData.addAll(Arrays.asList(newLines)); |