1 /* 2 * Copyright (c) 2007, 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 * @modules java.base/jdk.internal.misc:+open 27 * 28 * @summary converted from VM Testbase nsk/jdi/StepEvent/_itself_/stepEvent003. 29 * VM Testbase keywords: [jpda, jdi, feature_sde, vm6] 30 * VM Testbase readme: 31 * DESCRIPTION 32 * The test checks up that StepEvents are generated correctly if SourceDebugExtension defines following line mapping: 33 * "Java" "Test stratum" 34 * line 1 --> line 1, source 1 35 * line 2 --> line 1, source 2 36 * line 3 --> line 1, source 3 37 * (lines in "Test stratum" has same numbers but different sources) 38 * Debugger creates copy of class file for class 'nsk.share.jdi.TestClass1' with SourceDebugExtension attribute 39 * which contains informations for 1 non-Java stratum and for this stratum following line mapping is defined: 40 * "Java" "TestStratum" 41 * <init> 42 * 32 --> 1000, source1 43 * 33 --> 1000, source2 44 * ... ... 45 * sde_testMethod1 46 * 43 --> 1100, source1 47 * 44 --> 1100, source2 48 * ... ... 49 * sde_testMethod1 50 * 54 --> 1200, source1 51 * 55 --> 1200, source2 52 * ... ... 53 * Then debugger forces debuggee to load 'TestClass1' from updated class file, starts event listener thread which saves all received StepEvents, 54 * enables StepEvent request(class filter is used to receive events only for 'TestClass1') and forces debuggee to execute all methods defined in 'TestClass1'. 55 * When all methods was executed debugger checks up that StepEvents was generated for each location specified for 'TestStratum'. 56 * 57 * @library /vmTestbase 58 * /test/lib 59 * @run driver jdk.test.lib.FileInstaller . . 60 * @build nsk.jdi.StepEvent._itself_.stepEvent003.stepEvent003 61 * @run main/othervm PropertyResolvingWrapper 62 * nsk.jdi.StepEvent._itself_.stepEvent003.stepEvent003 63 * -verbose 64 * -arch=${os.family}-${os.simpleArch} 65 * -waittime=5 66 * -debugee.vmkind=java 67 * -transport.address=dynamic 68 * "-debugee.vmkeys=${test.vm.opts} ${test.java.opts}" 69 * -testClassPath ${test.class.path} 70 * -testWorkDir . 71 */ 72 73 package nsk.jdi.StepEvent._itself_.stepEvent003; 74 75 import java.io.*; 76 import java.util.*; 77 import com.sun.jdi.request.StepRequest; 78 import nsk.share.Consts; 79 import nsk.share.jdi.EventHandler; 80 import nsk.share.jdi.sde.*; 81 82 public class stepEvent003 extends SDEDebugger { main(String argv[])83 public static void main(String argv[]) { 84 System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); 85 } 86 run(String argv[], PrintStream out)87 public static int run(String argv[], PrintStream out) { 88 return new stepEvent003().runIt(argv, out); 89 } 90 91 private EventHandler eventHandler; 92 preparePatchedClassFile(String className)93 protected List<DebugLocation> preparePatchedClassFile(String className) { 94 /* 95 * Create file with following line mapping: 96 * 97 * "Java" "TestStratum" 98 * 99 * <init> 100 * 32 --> 1000, source1 101 * ... 102 * 39 --> 1000, source8 103 * 104 * sde_testMethod1 105 * 43 --> 1100, source1 106 * ... 107 * 50 --> 1100, source8 108 * 109 * sde_testMethod2 110 * 54 --> 1200, source1 111 * ... 112 * 61 --> 1200, source8 113 */ 114 115 String sourceName = testStratumSourceName; 116 String sourcePath = testStratumSourcePath; 117 String stratumName = testStratumName; 118 119 String smapFileName = "TestSMAP.smap"; 120 SmapGenerator smapGenerator = new SmapGenerator(); 121 122 SmapStratum smapStratum = new SmapStratum(stratumName); 123 124 List<DebugLocation> testStratumData = new ArrayList<DebugLocation>(); 125 126 for (int i = 0; i < 8; i++) { 127 String source = sourceName + (i + 1); 128 String path = sourcePath + (i + 1); 129 testStratumData.add(new DebugLocation(source, path, 130 "<init>", 1000 + i, INIT_LINE + i)); 131 smapStratum.addFile(source, path); 132 133 testStratumData.add(new DebugLocation(source, path, 134 "sde_testMethod1", 1100 + i, METHOD1_LINE + i)); 135 smapStratum.addFile(source, path); 136 137 testStratumData.add(new DebugLocation(source, path, 138 "sde_testMethod2", 1200 + i, METHOD2_LINE + i)); 139 smapStratum.addFile(source, path); 140 } 141 142 for (DebugLocation debugLocation : testStratumData) { 143 smapStratum.addLineData(debugLocation.inputLine, debugLocation.sourceName, 1, debugLocation.outputLine, 1); 144 } 145 146 smapGenerator.addStratum(smapStratum, false); 147 148 savePathcedClassFile(className, smapGenerator, smapFileName); 149 150 return testStratumData; 151 } 152 doTest()153 public void doTest() { 154 String className = TestClass1.class.getName(); 155 156 List<DebugLocation> locations = preparePatchedClassFile(className); 157 158 initDefaultBreakpoint(); 159 160 eventHandler = new EventHandler(debuggee, log); 161 eventHandler.startListening(); 162 163 StepEventListener stepEventListener = new StepEventListener(); 164 eventHandler.addListener(stepEventListener); 165 166 StepRequest stepRequest = debuggee.getEventRequestManager().createStepRequest( 167 debuggee.threadByName(SDEDebuggee.mainThreadName), 168 StepRequest.STEP_LINE, 169 StepRequest.STEP_INTO); 170 171 stepRequest.setSuspendPolicy(StepRequest.SUSPEND_EVENT_THREAD); 172 stepRequest.addClassFilter(TestClass1.class.getName()); 173 stepRequest.enable(); 174 175 vm.setDefaultStratum(testStratumName); 176 177 pipe.println(SDEDebuggee.COMMAND_EXECUTE_TEST_METHODS + ":" + className); 178 179 if (!isDebuggeeReady()) 180 return; 181 182 stepEventListener.waitBreakpointEvent(); 183 184 compareLocations(stepEventListener.stepLocations(), locations, testStratumName); 185 } 186 } 187