001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Aleksander V. Budniy
021: * @version $Revision: $
022: */
023:
024: /**
025: * Created on 5.06.2006
026: */package org.apache.harmony.jpda.tests.jdwp.DebuggerOnDemand;
027:
028: import org.apache.harmony.jpda.tests.framework.TestErrorException;
029: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
030:
031: /**
032: * This debugger is invoked by debuggee on demand.
033: * Upon launching debugger establishes synch connection with debuggee and with Test.
034: * Debugger gets RefTypeID of tested class, sets breakpoint inside testMethod,
035: * waits for breakpoint, gets frames, and prints them. Then it releases debuggee.
036: * After every relevant step, debugger send message (OK or FAIL) to Test.
037: *
038: * @see org.apache.harmony.jpda.tests.jdwp.DebuggerOnDemand.OnthowDebuggerLaunchDebuggee
039: */
040:
041: public class OnthrowLaunchDebugger002 extends LaunchedDebugger {
042:
043: protected String getDebuggeeClassName() {
044: return "";
045: }
046:
047: String breakpointMethodName = "testMethod";
048:
049: public void testDebugger() {
050: logWriter.println("***> Debugger started");
051: synchronizer
052: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
053:
054: // find checked method
055: long refTypeID = 0;
056: try {
057: refTypeID = getClassIDBySignature(DEBUGGEE_CLASS_SIGNATURE);
058: } catch (TestErrorException e) {
059: logWriter.println("##EXCPETION: " + e);
060: testSynchronizer.sendMessage("FAIL");
061: fail("exception during getting class signature");
062: }
063:
064: logWriter.println("**> Set breakpoint at the beginning of "
065: + breakpointMethodName);
066: long requestID = 0;
067: try {
068: requestID = debuggeeWrapper.vmMirror
069: .setBreakpointAtMethodBegin(refTypeID,
070: breakpointMethodName);
071: } catch (TestErrorException e) {
072: logWriter.println("##EXCEPTION: " + e);
073: testSynchronizer.sendMessage("FAIL");
074: fail("exception setting breakpoint");
075: }
076:
077: logWriter.println("**> RequestID = " + requestID);
078: logWriter.println("**> Release debuggee");
079: synchronizer
080: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
081:
082: // receive event
083: logWriter.println("**> Wait for breakpoint in "
084: + breakpointMethodName);
085: long breakpointThreadID = 0;
086: try {
087: breakpointThreadID = debuggeeWrapper.vmMirror
088: .waitForBreakpoint(requestID);
089: } catch (TestErrorException e) {
090: logWriter.println("##EXCEPTION: " + e);
091: testSynchronizer.sendMessage("FAIL");
092: fail("exception during waiting for breakpoint");
093: }
094:
095: testSynchronizer.sendMessage("OK");
096: logWriter.println("**> breakpointThreadID = "
097: + breakpointThreadID);
098:
099: //print stack frames
100: logWriter.println("");
101: logWriter.println("**> Get frames, thread = "
102: + breakpointThreadID);
103: FrameInfo[] frameInfos = null;
104: try {
105: frameInfos = jdwpGetFrames(breakpointThreadID, 0, -1);
106: } catch (TestErrorException e) {
107: logWriter.println("##EXCEPTION: " + e);
108: testSynchronizer.sendMessage("FAIL");
109: fail("exception during getting frames");
110: }
111: try {
112: printStackFrame(frameInfos.length, frameInfos);
113: } catch (TestErrorException e) {
114: logWriter.println("##EXCEPTION: " + e);
115: testSynchronizer.sendMessage("FAIL");
116: fail("exception during printing frames");
117: }
118: testSynchronizer.sendMessage("OK");
119:
120: logWriter.println("**> Resume debuggee");
121: debuggeeWrapper.vmMirror.resume();
122:
123: testSynchronizer.sendMessage("END");
124: logWriter.println("***> Debugger finished");
125: }
126:
127: public static void main(String[] args) {
128: junit.textui.TestRunner.run(OnthrowLaunchDebugger002.class);
129: }
130: }
|