001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.jpda.util;
043:
044: import com.sun.jdi.AbsentInformationException;
045: import com.sun.jdi.Location;
046: import com.sun.jdi.Method;
047: import com.sun.jdi.ReferenceType;
048: import com.sun.jdi.ThreadGroupReference;
049: import com.sun.jdi.ThreadReference;
050: import com.sun.jdi.VirtualMachine;
051: import com.sun.jdi.connect.Connector;
052: import com.sun.jdi.request.EventRequestManager;
053:
054: import java.util.Iterator;
055: import java.util.List;
056: import java.util.Map;
057: import java.util.logging.Logger;
058:
059: /**
060: * Utilities for debugger.
061: *
062: * @author Jan Jancura
063: */
064: public class JPDAUtils {
065:
066: // testing methods .........................................................................
067:
068: public static void printFeatures(Logger logger,
069: VirtualMachine virtualMachine) {
070: logger.fine("canAddMethod " + virtualMachine.canAddMethod());
071: logger.fine("canBeModified " + virtualMachine.canBeModified());
072: logger.fine("canGetBytecodes "
073: + virtualMachine.canGetBytecodes());
074: logger.fine("canGetCurrentContendedMonitor "
075: + virtualMachine.canGetCurrentContendedMonitor());
076: logger.fine("canGetMonitorInfo "
077: + virtualMachine.canGetMonitorInfo());
078: logger.fine("canGetOwnedMonitorInfo "
079: + virtualMachine.canGetOwnedMonitorInfo());
080: logger.fine("canGetSourceDebugExtension "
081: + virtualMachine.canGetSourceDebugExtension());
082: logger.fine("canGetSyntheticAttribute "
083: + virtualMachine.canGetSyntheticAttribute());
084: logger.fine("canPopFrames " + virtualMachine.canPopFrames());
085: logger.fine("canRedefineClasses "
086: + virtualMachine.canRedefineClasses());
087: logger.fine("canRequestVMDeathEvent "
088: + virtualMachine.canRequestVMDeathEvent());
089: logger.fine("canUnrestrictedlyRedefineClasses "
090: + virtualMachine.canUnrestrictedlyRedefineClasses());
091: logger.fine("canUseInstanceFilters "
092: + virtualMachine.canUseInstanceFilters());
093: logger.fine("canWatchFieldAccess "
094: + virtualMachine.canWatchFieldAccess());
095: logger.fine("canWatchFieldModification "
096: + virtualMachine.canWatchFieldModification());
097: }
098:
099: public static void showMethods(ReferenceType rt) {
100: System.out
101: .println(" ============================================"); // NOI18N
102: System.out.println(" Methods for " + rt.name()); // NOI18N
103: List l = rt.methods();
104: int i, k = l.size();
105: for (i = 0; i < k; i++)
106: System.out.println(((Method) l.get(i)).name() + " ; " + // NOI18N
107: ((Method) l.get(i)).signature());
108:
109: System.out
110: .println(" ============================================"); // NOI18N
111: }
112:
113: public static void showLinesForClass(ReferenceType rt) {
114: System.out
115: .println(" ============================================"); // NOI18N
116: System.out.println(" Lines for " + rt.name()); // NOI18N
117: List l = null;
118: try {
119: l = rt.allLineLocations();
120: } catch (AbsentInformationException e) {
121: }
122: int i, k = l.size();
123: for (i = 0; i < k; i++)
124: System.out.println(" "
125: + ((Location) l.get(i)).lineNumber() + " : " + // NOI18N
126: ((Location) l.get(i)).codeIndex());
127:
128: System.out
129: .println(" ============================================"); // NOI18N
130: }
131:
132: public static void showRequests(EventRequestManager requestManager) {
133: System.out
134: .println(" ============================================"); // NOI18N
135: List l = requestManager.breakpointRequests();
136: System.out.println(" Break request: " + l.size()); // NOI18N
137: int i, k = l.size();
138: for (i = 0; i < k; i++)
139: System.out.println(" " + l.get(i));
140: l = requestManager.classPrepareRequests();
141: System.out.println(" Class prepare request: " + l.size()); // NOI18N
142: k = l.size();
143: for (i = 0; i < k; i++)
144: System.out.println(" " + l.get(i));
145: l = requestManager.accessWatchpointRequests();
146: System.out.println(" Access watch request: " + l.size()); // NOI18N
147: k = l.size();
148: for (i = 0; i < k; i++)
149: System.out.println(" " + l.get(i));
150: l = requestManager.classUnloadRequests();
151: System.out.println(" Class unload request: " + l.size()); // NOI18N
152: k = l.size();
153: for (i = 0; i < k; i++)
154: System.out.println(" " + l.get(i));
155: l = requestManager.exceptionRequests();
156: System.out.println(" Exception request: " + l.size()); // NOI18N
157: k = l.size();
158: for (i = 0; i < k; i++)
159: System.out.println(" " + l.get(i));
160: l = requestManager.methodEntryRequests();
161: System.out.println(" Method entry request: " + l.size()); // NOI18N
162: k = l.size();
163: for (i = 0; i < k; i++)
164: System.out.println(" " + l.get(i));
165: l = requestManager.methodExitRequests();
166: System.out.println(" Method exit request: " + l.size()); // NOI18N
167: k = l.size();
168: for (i = 0; i < k; i++)
169: System.out.println(" " + l.get(i));
170: l = requestManager.modificationWatchpointRequests();
171: System.out.println(" Modif watch request: " + l.size()); // NOI18N
172: k = l.size();
173: for (i = 0; i < k; i++)
174: System.out.println(" " + l.get(i));
175: l = requestManager.stepRequests();
176: System.out.println(" Step request: " + l.size()); // NOI18N
177: k = l.size();
178: for (i = 0; i < k; i++)
179: System.out.println(" " + l.get(i));
180: l = requestManager.threadDeathRequests();
181: System.out.println(" Thread death entry request: " + l.size()); // NOI18N
182: k = l.size();
183: for (i = 0; i < k; i++)
184: System.out.println(" " + l.get(i));
185: l = requestManager.threadStartRequests();
186: System.out.println(" Thread start request: " + l.size()); // NOI18N
187: k = l.size();
188: for (i = 0; i < k; i++)
189: System.out.println(" " + l.get(i));
190: System.out
191: .println(" ============================================"); // NOI18N
192:
193: }
194:
195: public static void showConnectors(List l) {
196: int i, k = l.size();
197: for (i = 0; i < k; i++)
198: showConnector((Connector) l.get(i));
199: }
200:
201: public static void showConnector(Connector connector) {
202: System.out
203: .println(" ============================================"); // NOI18N
204: System.out.println(" Connector: " + connector); // NOI18N
205: System.out.println(" name: " + connector.name()); // NOI18N
206: System.out.println(" description: "
207: + connector.description()); // NOI18N
208: System.out.println(" transport: "
209: + (connector.transport() != null ? connector
210: .transport().name() : "null")); // NOI18N
211: showProperties(connector.defaultArguments());
212: System.out
213: .println(" ============================================"); // NOI18N
214: }
215:
216: public static void showThread(ThreadReference tr) {
217: System.out
218: .println(" ============================================"); // NOI18N
219: try {
220: System.out.println(" Thread: " + tr.name()); // NOI18N
221: } catch (Exception e) {
222: System.out.println(" Thread: " + e); // NOI18N
223: }
224:
225: try {
226: System.out.println(" status: " + tr.status()); // NOI18N
227: } catch (Exception e) {
228: System.out.println(" status: " + e); // NOI18N
229: }
230:
231: try {
232: System.out.println(" isSuspended: " + tr.isSuspended()); // NOI18N
233: } catch (Exception e) {
234: System.out.println(" isSuspended: " + e); // NOI18N
235: }
236:
237: try {
238: System.out.println(" frameCount: " + tr.frameCount()); // NOI18N
239: } catch (Exception e) {
240: System.out.println(" frameCount: " + e); // NOI18N
241: }
242:
243: try {
244: System.out.println(" location: " + tr.frame(0)); // NOI18N
245: } catch (Exception e) {
246: System.out.println(" location: " + e); // NOI18N
247: }
248: System.out
249: .println(" ============================================"); // NOI18N
250: }
251:
252: private static void showProperties(Map properties) {
253: Iterator i = properties.keySet().iterator();
254: while (i.hasNext()) {
255: Object k = i.next();
256: Connector.Argument a = (Connector.Argument) properties
257: .get(k);
258: System.out.println(" property: " + k + " > " + a.name()); // NOI18N
259: System.out.println(" desc: " + a.description()); // NOI18N
260: System.out.println(" mustSpecify: " + a.mustSpecify()); // NOI18N
261: System.out.println(" value: " + a.value()); // NOI18N
262: }
263: }
264:
265: public static void listGroup(String s, ThreadGroupReference g) {
266: List l = g.threadGroups();
267: int i, k = l.size();
268: for (i = 0; i < k; i++) {
269: System.out.println(s + "Thread Group: " + l.get(i) + " : " + // NOI18N
270: ((ThreadGroupReference) l.get(i)).name());
271: listGroup(s + " ", (ThreadGroupReference) l.get(i)); // NOI18N
272: }
273: l = g.threads();
274: k = l.size();
275: for (i = 0; i < k; i++) {
276: System.out.println(s + "Thread: " + l.get(i) + " : " + // NOI18N
277: ((ThreadReference) l.get(i)).name());
278: }
279: }
280:
281: private static void listGroups(List g) {
282: System.out
283: .println(" ============================================"); // NOI18N
284: int i, k = g.size();
285: for (i = 0; i < k; i++) {
286: System.out.println("Thread Group: " + g.get(i) + " : " + // NOI18N
287: ((ThreadGroupReference) g.get(i)).name());
288: listGroup(" ", (ThreadGroupReference) g.get(i)); // NOI18N
289: }
290: System.out
291: .println(" ============================================"); // NOI18N
292: }
293: }
|