1 19 20 package org.netbeans.api.debugger.jpda; 21 22 import com.sun.jdi.Bootstrap; 23 import com.sun.jdi.VirtualMachine; 24 import com.sun.jdi.connect.AttachingConnector; 25 import com.sun.jdi.connect.Connector.Argument; 26 import com.sun.jdi.connect.IllegalConnectorArgumentsException; 27 import com.sun.jdi.connect.ListeningConnector; 28 import com.sun.jdi.request.EventRequest; 29 30 import java.beans.PropertyChangeListener ; 31 import java.io.File ; 32 import java.io.IOException ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 import java.util.Map ; 36 import org.netbeans.api.debugger.DebuggerEngine; 37 import org.netbeans.api.debugger.DebuggerInfo; 38 import org.netbeans.api.debugger.DebuggerManager; 39 import org.netbeans.api.debugger.jpda.InvalidExpressionException; 40 import org.netbeans.api.debugger.jpda.Variable; 41 import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent; 42 import org.openide.util.NbBundle; 43 44 45 57 public abstract class JPDADebugger { 58 59 60 public static final String PROP_STATE = "state"; 61 62 public static final String PROP_CURRENT_THREAD = "currentThread"; 63 64 public static final String PROP_CURRENT_CALL_STACK_FRAME = "currentCallStackFrame"; 65 66 public static final String PROP_SUSPEND = "suspend"; 68 69 public static final int SUSPEND_ALL = EventRequest.SUSPEND_ALL; 70 71 public static final int SUSPEND_EVENT_THREAD = EventRequest.SUSPEND_EVENT_THREAD; 72 73 74 public static final int STATE_STARTING = 1; 75 76 public static final int STATE_RUNNING = 2; 77 78 public static final int STATE_STOPPED = 3; 79 80 public static final int STATE_DISCONNECTED = 4; 81 82 83 public static final String ENGINE_ID = "netbeans-JPDASession/Java"; 84 85 public static final String SESSION_ID = "netbeans-JPDASession"; 86 87 88 89 99 public static void launch ( 100 String mainClassName, 101 String [] args, 102 String classPath, 103 boolean suspend 104 ) { 105 DebuggerEngine[] es = DebuggerManager.getDebuggerManager().startDebugging ( 106 DebuggerInfo.create ( 107 LaunchingDICookie.ID, 108 new Object [] { 109 LaunchingDICookie.create ( 110 mainClassName, 111 args, 112 classPath, 113 suspend 114 ) 115 } 116 ) 117 ); 118 if (es.length == 0) { 119 122 throw new RuntimeException ( 123 NbBundle.getMessage(JPDADebugger.class, "MSG_NO_DEBUGGER")); 124 } 125 } 126 127 136 public static JPDADebugger listen ( 137 ListeningConnector connector, 138 Map <String , ? extends Argument> args, 139 Object [] services 140 ) throws DebuggerStartException { 141 Object [] s = new Object [services.length + 1]; 142 System.arraycopy (services, 0, s, 1, services.length); 143 s [0] = ListeningDICookie.create ( 144 connector, 145 args 146 ); 147 DebuggerEngine[] es = DebuggerManager.getDebuggerManager (). 148 startDebugging ( 149 DebuggerInfo.create ( 150 ListeningDICookie.ID, 151 s 152 ) 153 ); 154 int i, k = es.length; 155 for (i = 0; i < k; i++) { 156 JPDADebugger d = (JPDADebugger) es [i].lookupFirst 157 (null, JPDADebugger.class); 158 if (d == null) continue; 159 d.waitRunning (); 160 return d; 161 } 162 throw new DebuggerStartException( 163 NbBundle.getMessage(JPDADebugger.class, "MSG_NO_DEBUGGER")); 164 } 165 166 175 public static void startListening ( 176 ListeningConnector connector, 177 Map <String , ? extends Argument> args, 178 Object [] services 179 ) throws DebuggerStartException { 180 Object [] s = new Object [services.length + 1]; 181 System.arraycopy (services, 0, s, 1, services.length); 182 s [0] = ListeningDICookie.create ( 183 connector, 184 args 185 ); 186 DebuggerEngine[] es = DebuggerManager.getDebuggerManager (). 187 startDebugging ( 188 DebuggerInfo.create ( 189 ListeningDICookie.ID, 190 s 191 ) 192 ); 193 if (es.length == 0) { 194 throw new DebuggerStartException( 195 NbBundle.getMessage(JPDADebugger.class, "MSG_NO_DEBUGGER")); 196 } 197 } 198 199 207 public static JPDADebugger attach ( 208 String hostName, 209 int portNumber, 210 Object [] services 211 ) throws DebuggerStartException { 212 Object [] s = new Object [services.length + 1]; 213 System.arraycopy (services, 0, s, 1, services.length); 214 s [0] = AttachingDICookie.create ( 215 hostName, 216 portNumber 217 ); 218 DebuggerEngine[] es = DebuggerManager.getDebuggerManager (). 219 startDebugging ( 220 DebuggerInfo.create ( 221 AttachingDICookie.ID, 222 s 223 ) 224 ); 225 int i, k = es.length; 226 for (i = 0; i < k; i++) { 227 JPDADebugger d = (JPDADebugger) es [i].lookupFirst 228 (null, JPDADebugger.class); 229 if (d == null) continue; 230 d.waitRunning (); 231 return d; 232 } 233 throw new DebuggerStartException( 234 NbBundle.getMessage(JPDADebugger.class, "MSG_NO_DEBUGGER")); 235 } 236 237 244 public static JPDADebugger attach ( 245 String name, 246 Object [] services 247 ) throws DebuggerStartException { 248 Object [] s = new Object [services.length + 1]; 249 System.arraycopy (services, 0, s, 1, services.length); 250 s [0] = AttachingDICookie.create ( 251 name 252 ); 253 DebuggerEngine[] es = DebuggerManager.getDebuggerManager (). 254 startDebugging ( 255 DebuggerInfo.create ( 256 AttachingDICookie.ID, 257 s 258 ) 259 ); 260 int i, k = es.length; 261 for (i = 0; i < k; i++) { 262 JPDADebugger d = (JPDADebugger) es [i].lookupFirst 263 (null, JPDADebugger.class); 264 d.waitRunning (); 265 if (d == null) continue; 266 return d; 267 } 268 throw new DebuggerStartException( 269 NbBundle.getMessage(JPDADebugger.class, "MSG_NO_DEBUGGER")); 270 } 271 272 281 public abstract int getState (); 282 283 288 public abstract int getSuspend (); 289 290 295 public abstract void setSuspend (int s); 296 297 302 public abstract JPDAThread getCurrentThread (); 303 304 309 public abstract CallStackFrame getCurrentCallStackFrame (); 310 311 318 public abstract Variable evaluate (String expression) 319 throws InvalidExpressionException; 320 321 330 public abstract void waitRunning () throws DebuggerStartException; 331 332 338 public abstract boolean canFixClasses (); 339 340 345 public abstract boolean canPopFrames (); 346 347 354 public boolean canBeModified() { 355 return true; 356 } 357 358 364 public abstract void fixClasses (Map <String , byte[]> classes); 365 366 371 public abstract SmartSteppingFilter getSmartSteppingFilter (); 372 373 379 protected void fireBreakpointEvent ( 380 JPDABreakpoint breakpoint, 381 JPDABreakpointEvent event 382 ) { 383 breakpoint.fireJPDABreakpointChange (event); 384 } 385 386 391 public abstract void addPropertyChangeListener (PropertyChangeListener l); 392 393 398 public abstract void removePropertyChangeListener ( 399 PropertyChangeListener l 400 ); 401 402 408 public abstract void addPropertyChangeListener ( 409 String propertyName, 410 PropertyChangeListener l 411 ); 412 413 419 public abstract void removePropertyChangeListener ( 420 String propertyName, 421 PropertyChangeListener l 422 ); 423 424 431 public JPDAStep createJPDAStep(int size, int depth) { 432 throw new UnsupportedOperationException ("This method must be overridden."); 433 } 434 } 435 | Popular Tags |