1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8211736 27 * @summary Tests that the current location and prompt are printed in the debugger output 28 * when breakpoint is hit and suspend policy is set to SUSPEND_EVENT_THREAD 29 * 30 * @library /test/lib 31 * @run compile -g JdbStopThreadTest.java 32 * @run main/othervm JdbStopThreadTest 33 */ 34 35 import jdk.test.lib.process.OutputAnalyzer; 36 import lib.jdb.JdbCommand; 37 import lib.jdb.JdbTest; 38 39 class JdbStopThreadTestTarg { 40 public static void main(String[] args) { 41 test(); 42 } 43 44 private static void test() { 45 Thread thread = Thread.currentThread(); 46 print(thread); // @1 breakpoint 47 } 48 49 public static void print(Object obj) { 50 System.out.println(obj); 51 } 52 } 53 54 public class JdbStopThreadTest extends JdbTest { 55 public static void main(String argv[]) { 56 new JdbStopThreadTest().run(); 57 } 58 59 private JdbStopThreadTest() { 60 super(DEBUGGEE_CLASS); 61 } 62 63 private static final String DEBUGGEE_CLASS = JdbStopThreadTestTarg.class.getName(); 64 private static final String PATTERN_TEMPLATE = "^Breakpoint hit: \"thread=main\", " + 65 "JdbStopThreadTestTarg\\.test\\(\\), line=%LINE_NUMBER.*\n%LINE_NUMBER\\s+print\\(thread\\);.*\n\n>\\s"; 66 67 @Override 68 protected void runCases() { 69 int bpLine = parseBreakpoints(getTestSourcePath("JdbStopThreadTest.java"), 1).get(0); 70 jdb.command(JdbCommand.stopThreadAt( DEBUGGEE_CLASS ,bpLine)); 71 // Run to breakpoint #1 72 jdb.command(JdbCommand.run(), true); 73 String jdbOutput = jdb.getJdbOutput(); 74 jdb.quit(); 75 String pattern = PATTERN_TEMPLATE.replaceAll("%LINE_NUMBER", String.valueOf(bpLine)); 76 new OutputAnalyzer(jdbOutput).shouldMatch(pattern); 77 } 78 }