1 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 ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.logging.Logger ; 36 37 38 43 public class JPDAUtils { 44 45 46 48 public static void printFeatures (Logger 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 (" ============================================"); System.out.println (" Methods for " + rt.name ()); List 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 () + " ; " + ((Method) l.get (i)).signature ()); 74 75 System.out.println (" ============================================"); } 77 78 public static void showLinesForClass (ReferenceType rt) { 79 System.out.println (" ============================================"); System.out.println (" Lines for " + rt.name ()); List 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 () + " : " + ((Location) l.get (i)).codeIndex () 90 ); 91 92 System.out.println (" ============================================"); } 94 95 public static void showRequests (EventRequestManager requestManager) { 96 System.out.println (" ============================================"); List l = requestManager.breakpointRequests (); 98 System.out.println (" Break request: " + l.size ()); 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 ()); 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 ()); 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 ()); 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 ()); 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 ()); 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 ()); 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 ()); 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 ()); 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 ()); 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 ()); k = l.size (); 150 for (i = 0; i < k; i++) 151 System.out.println (" " + l.get (i)); 152 System.out.println (" ============================================"); 154 } 155 156 public static void showConnectors (List 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 (" ============================================"); System.out.println (" Connector: " + connector); System.out.println (" name: " + connector.name ()); System.out.println (" description: " + connector.description ()); System.out.println (" transport: " + (connector.transport () != null ? connector.transport ().name () : "null")); showProperties (connector.defaultArguments ()); 168 System.out.println (" ============================================"); } 170 171 public static void showThread (ThreadReference tr) { 172 System.out.println (" ============================================"); try { 174 System.out.println (" Thread: " + tr.name ()); } catch (Exception e) { 176 System.out.println (" Thread: " + e); } 178 179 try { 180 System.out.println (" status: " + tr.status ()); } catch (Exception e) { 182 System.out.println (" status: " + e); } 184 185 try { 186 System.out.println (" isSuspended: " + tr.isSuspended ()); } catch (Exception e) { 188 System.out.println (" isSuspended: " + e); } 190 191 try { 192 System.out.println (" frameCount: " + tr.frameCount ()); } catch (Exception e) { 194 System.out.println (" frameCount: " + e); } 196 197 try { 198 System.out.println (" location: " + tr.frame (0)); } catch (Exception e) { 200 System.out.println (" location: " + e); } 202 System.out.println (" ============================================"); } 204 205 206 private static void showProperties (Map properties) { 207 Iterator i = properties.keySet ().iterator (); 208 while (i.hasNext ()) { 209 Object k = i.next (); 210 Connector.Argument a = (Connector.Argument) properties.get (k); 211 System.out.println (" property: " + k + " > " + a.name ()); System.out.println (" desc: " + a.description ()); System.out.println (" mustSpecify: " + a.mustSpecify ()); System.out.println (" value: " + a.value ()); } 216 } 217 218 public static void listGroup (String s, ThreadGroupReference g) { 219 List 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) + " : " + ((ThreadGroupReference)l.get (i)).name () 224 ); 225 listGroup (s + " ", (ThreadGroupReference)l.get (i)); } 227 l = g.threads (); 228 k = l.size (); 229 for (i = 0; i < k; i++) { 230 System.out.println (s + "Thread: " + l.get (i) + " : " + ((ThreadReference)l.get (i)).name () 232 ); 233 } 234 } 235 236 private static void listGroups (List g) { 237 System.out.println (" ============================================"); int i, k = g.size (); 239 for (i = 0; i < k; i++) { 240 System.out.println ("Thread Group: " + g.get (i) + " : " + ((ThreadGroupReference)g.get (i)).name () 242 ); 243 listGroup (" ", (ThreadGroupReference)g.get (i)); } 245 System.out.println (" ============================================"); } 247 } 248 | Popular Tags |