KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > util > JPDAUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.util;
21
22 import com.sun.jdi.AbsentInformationException;
23 import com.sun.jdi.Location;
24 import com.sun.jdi.Method;
25 import com.sun.jdi.ReferenceType;
26 import com.sun.jdi.ThreadGroupReference;
27 import com.sun.jdi.ThreadReference;
28 import com.sun.jdi.VirtualMachine;
29 import com.sun.jdi.connect.Connector;
30 import com.sun.jdi.request.EventRequestManager;
31
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.logging.Logger JavaDoc;
36
37
38 /**
39 * Utilities for debugger.
40 *
41 * @author Jan Jancura
42 */

43 public class JPDAUtils {
44
45
46     // testing methods .........................................................................
47

48     public static void printFeatures (Logger JavaDoc logger, VirtualMachine virtualMachine) {
49         logger.fine ("canAddMethod " + virtualMachine.canAddMethod ());
50         logger.fine ("canBeModified " + virtualMachine.canBeModified ());
51         logger.fine ("canGetBytecodes " + virtualMachine.canGetBytecodes ());
52         logger.fine ("canGetCurrentContendedMonitor " + virtualMachine.canGetCurrentContendedMonitor ());
53         logger.fine ("canGetMonitorInfo " + virtualMachine.canGetMonitorInfo ());
54         logger.fine ("canGetOwnedMonitorInfo " + virtualMachine.canGetOwnedMonitorInfo ());
55         logger.fine ("canGetSourceDebugExtension " + virtualMachine.canGetSourceDebugExtension ());
56         logger.fine ("canGetSyntheticAttribute " + virtualMachine.canGetSyntheticAttribute ());
57         logger.fine ("canPopFrames " + virtualMachine.canPopFrames ());
58         logger.fine ("canRedefineClasses " + virtualMachine.canRedefineClasses ());
59         logger.fine ("canRequestVMDeathEvent " + virtualMachine.canRequestVMDeathEvent ());
60         logger.fine ("canUnrestrictedlyRedefineClasses " + virtualMachine.canUnrestrictedlyRedefineClasses ());
61         logger.fine ("canUseInstanceFilters " + virtualMachine.canUseInstanceFilters ());
62         logger.fine ("canWatchFieldAccess " + virtualMachine.canWatchFieldAccess ());
63         logger.fine ("canWatchFieldModification " + virtualMachine.canWatchFieldModification ());
64     }
65    
66     public static void showMethods (ReferenceType rt) {
67         System.out.println (" ============================================"); // NOI18N
68
System.out.println (" Methods for " + rt.name ()); // NOI18N
69
List JavaDoc l = rt.methods ();
70         int i, k = l.size ();
71         for (i = 0; i < k; i++)
72             System.out.println (((Method) l.get (i)).name () + " ; " + // NOI18N
73
((Method) l.get (i)).signature ());
74
75         System.out.println (" ============================================"); // NOI18N
76
}
77
78     public static void showLinesForClass (ReferenceType rt) {
79         System.out.println (" ============================================"); // NOI18N
80
System.out.println (" Lines for " + rt.name ()); // NOI18N
81
List JavaDoc l = null;
82         try {
83             l = rt.allLineLocations ();
84         } catch (AbsentInformationException e) {
85         }
86         int i, k = l.size ();
87         for (i = 0; i < k; i++)
88             System.out.println (" " + ((Location) l.get (i)).lineNumber () + " : " + // NOI18N
89
((Location) l.get (i)).codeIndex ()
90                                );
91
92         System.out.println (" ============================================"); // NOI18N
93
}
94
95     public static void showRequests (EventRequestManager requestManager) {
96         System.out.println (" ============================================"); // NOI18N
97
List JavaDoc l = requestManager.breakpointRequests ();
98         System.out.println (" Break request: " + l.size ()); // NOI18N
99
int i, k = l.size ();
100         for (i = 0; i < k; i++)
101             System.out.println (" " + l.get (i));
102         l = requestManager.classPrepareRequests ();
103         System.out.println (" Class prepare request: " + l.size ()); // NOI18N
104
k = l.size ();
105         for (i = 0; i < k; i++)
106             System.out.println (" " + l.get (i));
107         l = requestManager.accessWatchpointRequests ();
108         System.out.println (" Access watch request: " + l.size ()); // NOI18N
109
k = l.size ();
110         for (i = 0; i < k; i++)
111             System.out.println (" " + l.get (i));
112         l = requestManager.classUnloadRequests ();
113         System.out.println (" Class unload request: " + l.size ()); // NOI18N
114
k = l.size ();
115         for (i = 0; i < k; i++)
116             System.out.println (" " + l.get (i));
117         l = requestManager.exceptionRequests ();
118         System.out.println (" Exception request: " + l.size ()); // NOI18N
119
k = l.size ();
120         for (i = 0; i < k; i++)
121             System.out.println (" " + l.get (i));
122         l = requestManager.methodEntryRequests ();
123         System.out.println (" Method entry request: " + l.size ()); // NOI18N
124
k = l.size ();
125         for (i = 0; i < k; i++)
126             System.out.println (" " + l.get (i));
127         l = requestManager.methodExitRequests ();
128         System.out.println (" Method exit request: " + l.size ()); // NOI18N
129
k = l.size ();
130         for (i = 0; i < k; i++)
131             System.out.println (" " + l.get (i));
132         l = requestManager.modificationWatchpointRequests ();
133         System.out.println (" Modif watch request: " + l.size ()); // NOI18N
134
k = l.size ();
135         for (i = 0; i < k; i++)
136             System.out.println (" " + l.get (i));
137         l = requestManager.stepRequests ();
138         System.out.println (" Step request: " + l.size ()); // NOI18N
139
k = l.size ();
140         for (i = 0; i < k; i++)
141             System.out.println (" " + l.get (i));
142         l = requestManager.threadDeathRequests ();
143         System.out.println (" Thread death entry request: " + l.size ()); // NOI18N
144
k = l.size ();
145         for (i = 0; i < k; i++)
146             System.out.println (" " + l.get (i));
147         l = requestManager.threadStartRequests ();
148         System.out.println (" Thread start request: " + l.size ()); // NOI18N
149
k = l.size ();
150         for (i = 0; i < k; i++)
151             System.out.println (" " + l.get (i));
152         System.out.println (" ============================================"); // NOI18N
153

154     }
155
156     public static void showConnectors (List JavaDoc l) {
157         int i, k = l.size ();
158         for (i = 0; i < k; i++) showConnector ((Connector) l.get (i));
159     }
160
161     public static void showConnector (Connector connector) {
162         System.out.println (" ============================================"); // NOI18N
163
System.out.println (" Connector: " + connector); // NOI18N
164
System.out.println (" name: " + connector.name ()); // NOI18N
165
System.out.println (" description: " + connector.description ()); // NOI18N
166
System.out.println (" transport: " + (connector.transport () != null ? connector.transport ().name () : "null")); // NOI18N
167
showProperties (connector.defaultArguments ());
168         System.out.println (" ============================================"); // NOI18N
169
}
170
171     public static void showThread (ThreadReference tr) {
172         System.out.println (" ============================================"); // NOI18N
173
try {
174             System.out.println (" Thread: " + tr.name ()); // NOI18N
175
} catch (Exception JavaDoc e) {
176             System.out.println (" Thread: " + e); // NOI18N
177
}
178         
179         try {
180             System.out.println (" status: " + tr.status ()); // NOI18N
181
} catch (Exception JavaDoc e) {
182             System.out.println (" status: " + e); // NOI18N
183
}
184         
185         try {
186             System.out.println (" isSuspended: " + tr.isSuspended ()); // NOI18N
187
} catch (Exception JavaDoc e) {
188             System.out.println (" isSuspended: " + e); // NOI18N
189
}
190         
191         try {
192             System.out.println (" frameCount: " + tr.frameCount ()); // NOI18N
193
} catch (Exception JavaDoc e) {
194             System.out.println (" frameCount: " + e); // NOI18N
195
}
196         
197         try {
198             System.out.println (" location: " + tr.frame (0)); // NOI18N
199
} catch (Exception JavaDoc e) {
200             System.out.println (" location: " + e); // NOI18N
201
}
202         System.out.println (" ============================================"); // NOI18N
203
}
204
205
206     private static void showProperties (Map JavaDoc properties) {
207         Iterator JavaDoc i = properties.keySet ().iterator ();
208         while (i.hasNext ()) {
209             Object JavaDoc k = i.next ();
210             Connector.Argument a = (Connector.Argument) properties.get (k);
211             System.out.println (" property: " + k + " > " + a.name ()); // NOI18N
212
System.out.println (" desc: " + a.description ()); // NOI18N
213
System.out.println (" mustSpecify: " + a.mustSpecify ()); // NOI18N
214
System.out.println (" value: " + a.value ()); // NOI18N
215
}
216     }
217
218     public static void listGroup (String JavaDoc s, ThreadGroupReference g) {
219         List JavaDoc l = g.threadGroups ();
220         int i, k = l.size ();
221         for (i = 0; i < k; i++) {
222             System.out.println (s + "Thread Group: " + l.get (i) + " : " + // NOI18N
223
((ThreadGroupReference)l.get (i)).name ()
224                                );
225             listGroup (s + " ", (ThreadGroupReference)l.get (i)); // NOI18N
226
}
227         l = g.threads ();
228         k = l.size ();
229         for (i = 0; i < k; i++) {
230             System.out.println (s + "Thread: " + l.get (i) + " : " + // NOI18N
231
((ThreadReference)l.get (i)).name ()
232                                );
233         }
234     }
235
236     private static void listGroups (List JavaDoc g) {
237         System.out.println (" ============================================"); // NOI18N
238
int i, k = g.size ();
239         for (i = 0; i < k; i++) {
240             System.out.println ("Thread Group: " + g.get (i) + " : " + // NOI18N
241
((ThreadGroupReference)g.get (i)).name ()
242                                );
243             listGroup (" ", (ThreadGroupReference)g.get (i)); // NOI18N
244
}
245         System.out.println (" ============================================"); // NOI18N
246
}
247 }
248
Popular Tags