190 }
191 }
192 if (!jdb.isAlive()) {
193 // ensure we get the whole output
194 reply = outputHandler.reset();
195 logJdb(reply);
196 if (!allowExit) {
197 throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
198 + " seconds, looking for '" + promptPattern + "', in " + lines + " lines");
199 }
200 return reply;
201 }
202 }
203 // timeout
204 logJdb(outputHandler.get());
205 throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
206 + " seconds, looking for '" + promptPattern + "', in " + lines + " lines");
207 }
208
209 public List<String> command(JdbCommand cmd) {
210 if (!jdb.isAlive()) {
211 if (cmd.allowExit) {
212 // return remaining output
213 return outputHandler.reset();
214 }
215 throw new RuntimeException("Attempt to send command '" + cmd.cmd + "' to terminated jdb");
216 }
217
218 log("> " + cmd.cmd);
219
220 inputWriter.println(cmd.cmd);
221
222 if (inputWriter.checkError()) {
223 throw new RuntimeException("Unexpected IO error while writing command '" + cmd.cmd + "' to jdb stdin stream");
224 }
225
226 return waitForPrompt(1, cmd.allowExit);
227 }
228
229 public List<String> command(String cmd) {
230 return command(new JdbCommand(cmd));
231 }
232
233 // sends "cont" command up to maxTimes until debuggee exit
234 public void contToExit(int maxTimes) {
235 boolean exited = false;
236 JdbCommand cont = JdbCommand.cont().allowExit();
237 for (int i = 0; i < maxTimes && jdb.isAlive(); i++) {
238 String reply = command(cont).stream().collect(Collectors.joining(lineSeparator));
239 if (reply.contains(APPLICATION_EXIT)) {
240 exited = true;
241 break;
242 }
243 }
244 if (!exited && jdb.isAlive()) {
245 throw new RuntimeException("Debuggee did not exit after " + maxTimes + " <cont> commands");
246 }
|
190 }
191 }
192 if (!jdb.isAlive()) {
193 // ensure we get the whole output
194 reply = outputHandler.reset();
195 logJdb(reply);
196 if (!allowExit) {
197 throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
198 + " seconds, looking for '" + promptPattern + "', in " + lines + " lines");
199 }
200 return reply;
201 }
202 }
203 // timeout
204 logJdb(outputHandler.get());
205 throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
206 + " seconds, looking for '" + promptPattern + "', in " + lines + " lines");
207 }
208
209 public List<String> command(JdbCommand cmd) {
210 return command(cmd, false);
211 }
212
213 public List<String> command(JdbCommand cmd, boolean waitForSimplePrompt) {
214 if (!jdb.isAlive()) {
215 if (cmd.allowExit) {
216 // return remaining output
217 return outputHandler.reset();
218 }
219 throw new RuntimeException("Attempt to send command '" + cmd.cmd + "' to terminated jdb");
220 }
221
222 log("> " + cmd.cmd);
223
224 inputWriter.println(cmd.cmd);
225
226 if (inputWriter.checkError()) {
227 throw new RuntimeException("Unexpected IO error while writing command '" + cmd.cmd + "' to jdb stdin stream");
228 }
229
230 return waitForSimplePrompt ? waitForSimplePrompt(1, cmd.allowExit) : waitForPrompt(1, cmd.allowExit);
231 }
232
233 public List<String> command(String cmd) {
234 return command(new JdbCommand(cmd));
235 }
236
237 // sends "cont" command up to maxTimes until debuggee exit
238 public void contToExit(int maxTimes) {
239 boolean exited = false;
240 JdbCommand cont = JdbCommand.cont().allowExit();
241 for (int i = 0; i < maxTimes && jdb.isAlive(); i++) {
242 String reply = command(cont).stream().collect(Collectors.joining(lineSeparator));
243 if (reply.contains(APPLICATION_EXIT)) {
244 exited = true;
245 break;
246 }
247 }
248 if (!exited && jdb.isAlive()) {
249 throw new RuntimeException("Debuggee did not exit after " + maxTimes + " <cont> commands");
250 }
|