< prev index next >

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

Print this page

        

@@ -148,14 +148,15 @@
         # 5) ^main[89] > @
         #
         # i.e., the > prompt comes out AFTER the prompt we we need to wait for.
     */
     // compile regexp once
-    private final String promptPattern = "[a-zA-Z0-9_-][a-zA-Z0-9_-]*\\[[1-9][0-9]*\\] [ >]*$";
-    private final Pattern promptRegexp = Pattern.compile(promptPattern);
+    private final static String promptPattern = "[a-zA-Z0-9_-][a-zA-Z0-9_-]*\\[[1-9][0-9]*\\] [ >]*$";
+    final static Pattern PROMPT_REGEXP = Pattern.compile(promptPattern);
+
     public List<String> waitForPrompt(int lines, boolean allowExit) {
-        return waitForPrompt(lines, allowExit, promptRegexp);
+        return waitForPrompt(lines, allowExit, PROMPT_REGEXP);
     }
 
     // jdb prompt when debuggee is not started and is not suspended after breakpoint
     private static final String SIMPLE_PROMPT = "> ";
     public List<String> waitForSimplePrompt(int lines, boolean allowExit) {

@@ -181,31 +182,39 @@
                     // if something appeared in the jdb output, reset the timeout
                     startTime = System.currentTimeMillis();
                 }
             }
             List<String> reply = outputHandler.get();
-            for (String line: reply.subList(Math.max(0, reply.size() - lines), reply.size())) {
+            if ((promptRegexp.flags() & Pattern.MULTILINE) > 0) {
+                String replyString = reply.stream().collect(Collectors.joining(lineSeparator));
+                if (promptRegexp.matcher(replyString).find()) {
+                    logJdb(reply);
+                    return outputHandler.reset();
+                }
+            } else {
+                for (String line : reply.subList(Math.max(0, reply.size() - lines), reply.size())) {
                 if (promptRegexp.matcher(line).find()) {
                     logJdb(reply);
                     return outputHandler.reset();
                 }
             }
+            }
             if (!jdb.isAlive()) {
                 // ensure we get the whole output
                 reply = outputHandler.reset();
                 logJdb(reply);
                 if (!allowExit) {
                     throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
-                            + " seconds, looking for '" + promptPattern + "', in " + lines + " lines");
+                            + " seconds, looking for '" + promptRegexp.pattern() + "', in " + lines + " lines");
                 }
                 return reply;
             }
         }
         // timeout
         logJdb(outputHandler.get());
         throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
-                + " seconds, looking for '" + promptPattern + "', in " + lines + " lines");
+                + " seconds, looking for '" + promptRegexp.pattern() + "', in " + lines + " lines");
     }
 
     public List<String> command(JdbCommand cmd) {
         if (!jdb.isAlive()) {
             if (cmd.allowExit) {

@@ -221,11 +230,11 @@
 
         if (inputWriter.checkError()) {
             throw new RuntimeException("Unexpected IO error while writing command '" + cmd.cmd + "' to jdb stdin stream");
         }
 
-        return waitForPrompt(1, cmd.allowExit);
+        return waitForPrompt(1, cmd.allowExit, cmd.waitForPattern);
     }
 
     public List<String> command(String cmd) {
         return command(new JdbCommand(cmd));
     }
< prev index next >