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 8193879
  27  * @summary Stops the thread at the breakpoint and invokes methods
  28  * when debugger trace mode is on.
  29  *
  30  * @library /test/lib
  31  * @run compile -g JdbStopThreadWithTraceOnTest.java
  32  * @run main/othervm JdbStopThreadWithTraceOnTest
  33  */
  34 
  35 import jdk.test.lib.process.OutputAnalyzer;
  36 import lib.jdb.JdbCommand;
  37 import lib.jdb.JdbTest;
  38 
  39 class JdbStopThreadWithTraceOnTestTarg {
  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 JdbStopThreadWithTraceOnTest extends JdbTest {
  55     public static void main(String argv[]) {
  56         new JdbStopThreadWithTraceOnTest().run();
  57     }
  58 
  59     private JdbStopThreadWithTraceOnTest() {
  60         super(new LaunchOptions(DEBUGGEE_CLASS).addDebuggerOptions(DEBUGGER_TRACE_OPTIONS));
  61     }
  62 
  63     private static final String DEBUGGEE_CLASS = JdbStopThreadWithTraceOnTestTarg.class.getName();
  64     private static final String[] DEBUGGER_TRACE_OPTIONS = {"-dbgtrace", "0x00ffffff"};
  65 
  66 
  67     @Override
  68     protected void runCases() {
  69         int bpLine = parseBreakpoints(getTestSourcePath("JdbStopThreadWithTraceOnTest.java"), 1).get(0);
  70         jdb.command("stop thread at " + DEBUGGEE_CLASS + ":" + bpLine);
  71         // Run to breakpoint #1
  72         jdb.command(JdbCommand.run(), true);
  73 
  74         // Set the current thread
  75         jdb.command("thread 1");
  76 
  77         // Invoke the method
  78         jdb.command(JdbCommand.eval(DEBUGGEE_CLASS + ".print(thread)"));
  79 
  80         jdb.command(JdbCommand.quit());
  81 
  82         new OutputAnalyzer(jdb.getJdbOutput())
  83                 .shouldContain(DEBUGGEE_CLASS + ".print(thread)");
  84     }
  85 }