1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19/** 20 * @author Aleksander V. Budniy 21 */ 22 23/** 24 * Created on 5.06.2006 25 */ 26package org.apache.harmony.jpda.tests.jdwp.DebuggerOnDemand; 27 28import org.apache.harmony.jpda.tests.framework.TestErrorException; 29import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 30 31/** 32 * This debugger is invoked by debuggee on demand. 33 * Upon launching debugger establishes synch connection with debuggee and with Test. 34 * Debugger gets RefTypeID of tested class, sets breakpoint inside testMethod, 35 * waits for breakpoint, gets frames, and prints them. Then it releases debuggee. 36 * After every relevant step, debugger send message (OK or FAIL) to Test. 37 * 38 * @see org.apache.harmony.jpda.tests.jdwp.DebuggerOnDemand.OnthowDebuggerLaunchDebuggee 39 */ 40 41public class OnthrowLaunchDebugger002 extends LaunchedDebugger { 42 43 protected String getDebuggeeClassName() { 44 return ""; 45 } 46 47 String breakpointMethodName = "testMethod"; 48 49 public void testDebugger() { 50 logWriter.println("***> Debugger started"); 51 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 52 53 // find checked method 54 long refTypeID = 0; 55 try { 56 refTypeID = getClassIDBySignature(DEBUGGEE_CLASS_SIGNATURE); 57 } catch (TestErrorException e) { 58 logWriter.println("##EXCPETION: " + e); 59 testSynchronizer.sendMessage("FAIL"); 60 fail("exception during getting class signature"); 61 } 62 63 logWriter.println("**> Set breakpoint at the beginning of " + breakpointMethodName); 64 long requestID = 0; 65 try { 66 requestID = debuggeeWrapper.vmMirror.setBreakpointAtMethodBegin( 67 refTypeID, breakpointMethodName); 68 } catch (TestErrorException e) { 69 logWriter.println("##EXCEPTION: " + e); 70 testSynchronizer.sendMessage("FAIL"); 71 fail("exception setting breakpoint"); 72 } 73 74 logWriter.println("**> RequestID = " + requestID); 75 logWriter.println("**> Release debuggee"); 76 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 77 78 // receive event 79 logWriter.println("**> Wait for breakpoint in " + breakpointMethodName); 80 long breakpointThreadID = 0; 81 try { 82 breakpointThreadID = debuggeeWrapper.vmMirror.waitForBreakpoint(requestID); 83 } catch (TestErrorException e) { 84 logWriter.println("##EXCEPTION: " + e); 85 testSynchronizer.sendMessage("FAIL"); 86 fail("exception during waiting for breakpoint"); 87 } 88 89 testSynchronizer.sendMessage("OK"); 90 logWriter.println("**> breakpointThreadID = " + breakpointThreadID); 91 92 //print stack frames 93 logWriter.println(""); 94 logWriter.println("**> Get frames, thread = " + breakpointThreadID); 95 FrameInfo[] frameInfos = null; 96 try { 97 frameInfos = jdwpGetFrames(breakpointThreadID, 0, -1); 98 } catch (TestErrorException e) { 99 logWriter.println("##EXCEPTION: " + e); 100 testSynchronizer.sendMessage("FAIL"); 101 fail("exception during getting frames"); 102 } 103 try { 104 printStackFrame(frameInfos.length, frameInfos); 105 } catch (TestErrorException e) { 106 logWriter.println("##EXCEPTION: " + e); 107 testSynchronizer.sendMessage("FAIL"); 108 fail("exception during printing frames"); 109 } 110 testSynchronizer.sendMessage("OK"); 111 112 logWriter.println("**> Resume debuggee"); 113 debuggeeWrapper.vmMirror.resume(); 114 115 testSynchronizer.sendMessage("END"); 116 logWriter.println("***> Debugger finished"); 117 } 118} 119