1 /* 2 * Copyright (c) 2001, 2015, 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 4331522 27 * @summary addClassFilter("Foo") acts like "Foo*" 28 * 29 * @author Robert Field/Jim Holmlund 30 * 31 * @modules jdk.jdi 32 * @run build JDIScaffold VMConnection 33 * @run compile -g HelloWorld.java 34 * @run driver FilterMatch 35 */ 36 37 /* Look at patternMatch in JDK file: 38 * .../src/share/back/eventHandler.c 39 */ 40 41 /* 42 * This test tests patterns passed to addClassFilter that do match 43 * the classname of the event. See also testcase FilterNoMatch.java. 44 */ 45 46 import java.util.*; 47 import com.sun.jdi.*; 48 import com.sun.jdi.event.*; 49 import com.sun.jdi.request.*; 50 51 public class FilterMatch extends JDIScaffold { 52 53 static boolean listenCalled; 54 55 public static void main(String args[]) throws Exception { 56 new FilterMatch().startTests(); 57 } 58 59 public FilterMatch() { 60 super(); 61 } 62 63 private void listen() { 64 TargetAdapter adapter = new TargetAdapter() { 65 EventSet set = null; 66 67 public boolean eventSetReceived(EventSet set) { 68 this.set = set; 69 return false; 70 } 71 72 // This gets called if all filters match. 73 public boolean stepCompleted(StepEvent event) { 74 listenCalled = true; 75 System.out.println("listen: line#=" + event.location().lineNumber() 76 + " event=" + event); 77 // disable the step and then run to completion 78 StepRequest str= (StepRequest)event.request(); 79 str.disable(); 80 set.resume(); 81 return false; 82 } 83 }; 84 listenCalled = false; 85 addListener(adapter); 86 } 87 88 protected void runTests() throws Exception { 89 String[] args = new String[2]; 90 args[0] = "-connect"; 91 args[1] = "com.sun.jdi.CommandLineLaunch:main=HelloWorld"; 92 93 connect(args); 94 waitForVMStart(); 95 96 // VM has started, but hasn't started running the test program yet. 97 EventRequestManager requestManager = vm().eventRequestManager(); 98 ReferenceType referenceType = resumeToPrepareOf("HelloWorld").referenceType(); 99 100 // The debuggee is stopped 101 // I don't think we really have to set a bkpt and then do a step, 102 // we should just be able to do a step. Problem is the 103 // createStepRequest call needs a thread and I don't know 104 // yet where to get one other than from the bkpt handling :-( 105 Location location = findLocation(referenceType, 3); 106 BreakpointRequest request 107 = requestManager.createBreakpointRequest(location); 108 109 request.enable(); 110 111 // This does a resume, so we shouldn't come back to it until 112 // the debuggee has run and hit the bkpt. 113 BreakpointEvent event = (BreakpointEvent)waitForRequestedEvent(request); 114 115 // The bkpt was hit; remove it. 116 requestManager.deleteEventRequest(request); // remove BP 117 118 StepRequest request1 = requestManager.createStepRequest(event.thread(), 119 StepRequest.STEP_LINE,StepRequest.STEP_OVER); 120 121 // These patterns all match HelloWorld. Since they all match, our 122 // listener should get called and the test will pass. If any of them 123 // are erroneously determined to _not_ match, then our listener will 124 // not get called and the test will fail. 125 request1.addClassFilter("*"); 126 127 request1.addClassFilter("H*"); 128 request1.addClassFilter("He*"); 129 request1.addClassFilter("HelloWorld*"); 130 131 request1.addClassFilter("*d"); 132 request1.addClassFilter("*ld"); 133 request1.addClassFilter("*HelloWorld"); 134 135 request1.addClassFilter("HelloWorld"); 136 137 // As a test, uncomment this line and the test should fail. 138 //request1.addClassFilter("x"); 139 140 request1.enable(); 141 listen(); 142 143 vm().resume(); 144 145 waitForVMDeath(); 146 147 if ( !listenCalled){ 148 throw new Exception( "Failed: Event filtered out."); 149 } 150 System.out.println( "Passed: Event not filtered out."); 151 } 152 }