1 11 package org.eclipse.jdt.internal.debug.core.model; 12 13 14 import java.io.IOException ; 15 import java.util.ArrayList ; 16 import java.util.Collections ; 17 import java.util.HashMap ; 18 import java.util.HashSet ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Set ; 22 23 import org.eclipse.core.resources.IMarkerDelta; 24 import org.eclipse.core.runtime.CoreException; 25 import org.eclipse.core.runtime.IProgressMonitor; 26 import org.eclipse.core.runtime.IStatus; 27 import org.eclipse.core.runtime.Status; 28 import org.eclipse.core.runtime.jobs.Job; 29 import org.eclipse.debug.core.DebugEvent; 30 import org.eclipse.debug.core.DebugException; 31 import org.eclipse.debug.core.DebugPlugin; 32 import org.eclipse.debug.core.IBreakpointManager; 33 import org.eclipse.debug.core.IBreakpointManagerListener; 34 import org.eclipse.debug.core.IDebugEventSetListener; 35 import org.eclipse.debug.core.ILaunch; 36 import org.eclipse.debug.core.ILaunchListener; 37 import org.eclipse.debug.core.model.IBreakpoint; 38 import org.eclipse.debug.core.model.IDebugTarget; 39 import org.eclipse.debug.core.model.IMemoryBlock; 40 import org.eclipse.debug.core.model.IProcess; 41 import org.eclipse.debug.core.model.IThread; 42 import org.eclipse.jdi.TimeoutException; 43 import org.eclipse.jdi.internal.VirtualMachineImpl; 44 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket; 45 import org.eclipse.jdt.core.IJavaProject; 46 import org.eclipse.jdt.debug.core.IJavaBreakpoint; 47 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 48 import org.eclipse.jdt.debug.core.IJavaThread; 49 import org.eclipse.jdt.debug.core.IJavaThreadGroup; 50 import org.eclipse.jdt.debug.core.IJavaType; 51 import org.eclipse.jdt.debug.core.IJavaValue; 52 import org.eclipse.jdt.debug.core.IJavaVariable; 53 import org.eclipse.jdt.debug.core.JDIDebugModel; 54 import org.eclipse.jdt.debug.eval.EvaluationManager; 55 import org.eclipse.jdt.debug.eval.IAstEvaluationEngine; 56 import org.eclipse.jdt.internal.debug.core.EventDispatcher; 57 import org.eclipse.jdt.internal.debug.core.IJDIEventListener; 58 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 59 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint; 60 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint; 61 62 import com.ibm.icu.text.MessageFormat; 63 import com.sun.jdi.ObjectCollectedException; 64 import com.sun.jdi.ReferenceType; 65 import com.sun.jdi.ThreadGroupReference; 66 import com.sun.jdi.ThreadReference; 67 import com.sun.jdi.Type; 68 import com.sun.jdi.VMDisconnectedException; 69 import com.sun.jdi.Value; 70 import com.sun.jdi.VirtualMachine; 71 import com.sun.jdi.event.Event; 72 import com.sun.jdi.event.ThreadDeathEvent; 73 import com.sun.jdi.event.ThreadStartEvent; 74 import com.sun.jdi.event.VMDeathEvent; 75 import com.sun.jdi.event.VMDisconnectEvent; 76 import com.sun.jdi.event.VMStartEvent; 77 import com.sun.jdi.request.ClassPrepareRequest; 78 import com.sun.jdi.request.EventRequest; 79 import com.sun.jdi.request.EventRequestManager; 80 81 84 85 public class JDIDebugTarget extends JDIDebugElement implements IJavaDebugTarget, ILaunchListener, IBreakpointManagerListener, IDebugEventSetListener { 86 87 92 private ArrayList fThreads; 93 94 97 private ArrayList fGroups; 98 99 102 private IProcess fProcess; 103 106 private VirtualMachine fVirtualMachine; 107 112 private boolean fSupportsTerminate; 113 116 private boolean fTerminated; 117 118 121 private boolean fTerminating; 122 125 private boolean fDisconnected; 126 129 private boolean fSupportsDisconnect; 130 133 private List fBreakpoints; 134 135 139 private Set fOutOfSynchTypes; 140 143 private boolean fHasHCROccurred; 144 145 149 private String fName; 150 151 155 private EventDispatcher fEventDispatcher= null; 156 157 160 private ThreadStartHandler fThreadStartHandler= null; 161 162 165 private boolean fSuspended = true; 166 167 170 private boolean fResumeOnStartup = false; 171 172 175 private ILaunch fLaunch; 176 177 180 private int fSuspendCount = 0; 181 182 186 private HashMap fEngines; 187 188 192 private String [] fStepFilters = null; 193 194 197 private int fStepFilterMask = 0; 198 199 202 private static final int STEP_FILTERS_ENABLED = 0x001; 203 204 207 private static final int FILTER_SYNTHETICS = 0x002; 208 209 212 private static final int FILTER_STATIC_INITIALIZERS = 0x004; 213 214 217 private static final int FILTER_CONSTRUCTORS = 0x008; 218 219 224 private static final int STEP_THRU_FILTERS = 0x010; 225 226 229 private static final int XOR_MASK = 0xFFF; 230 233 private boolean fIsPerformingHotCodeReplace= false; 234 235 236 253 public JDIDebugTarget(ILaunch launch, VirtualMachine jvm, String name, boolean supportTerminate, boolean supportDisconnect, IProcess process, boolean resume) { 254 super(null); 255 setLaunch(launch); 256 setResumeOnStartup(resume); 257 setSupportsTerminate(supportTerminate); 258 setSupportsDisconnect(supportDisconnect); 259 setVM(jvm); 260 jvm.setDebugTraceMode(VirtualMachine.TRACE_NONE); 261 setProcess(process); 262 setTerminated(false); 263 setTerminating(false); 264 setDisconnected(false); 265 setName(name); 266 setBreakpoints(new ArrayList (5)); 267 setThreadList(new ArrayList (5)); 268 fGroups = new ArrayList (5); 269 setOutOfSynchTypes(new ArrayList (0)); 270 setHCROccurred(false); 271 initialize(); 272 DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); 273 DebugPlugin.getDefault().getBreakpointManager().addBreakpointManagerListener(this); 274 } 275 276 282 public EventDispatcher getEventDispatcher() { 283 return fEventDispatcher; 284 } 285 286 293 private void setEventDispatcher(EventDispatcher dispatcher) { 294 fEventDispatcher = dispatcher; 295 } 296 297 304 private Iterator getThreadIterator() { 305 List threadList; 306 synchronized (fThreads) { 307 threadList= (List ) fThreads.clone(); 308 } 309 return threadList.iterator(); 310 } 311 312 320 private void setThreadList(ArrayList threads) { 321 fThreads = threads; 322 } 323 324 331 public List getBreakpoints() { 332 return fBreakpoints; 333 } 334 335 341 private void setBreakpoints(List breakpoints) { 342 fBreakpoints = breakpoints; 343 } 344 345 355 public void handleVMStart(VMStartEvent event) { 356 if (isResumeOnStartup()) { 357 try { 358 setSuspended(true); 359 resume(); 360 } catch (DebugException e) { 361 logError(e); 362 } 363 } 364 IThread[] threads = getThreads(); 367 for (int i = 0; i < threads.length; i++) { 368 JDIThread thread = (JDIThread)threads[i]; 369 if (thread.isSuspended()) { 370 try { 371 boolean suspended = thread.getUnderlyingThread().isSuspended(); 372 if (!suspended) { 373 thread.setRunning(true); 374 thread.fireResumeEvent(DebugEvent.CLIENT_REQUEST); 375 } 376 } catch (VMDisconnectedException e) { 377 } catch (ObjectCollectedException e){ 378 } catch (RuntimeException e) { 379 logError(e); 380 } 381 } 382 } 383 384 } 385 386 392 protected synchronized void initialize() { 393 setEventDispatcher(new EventDispatcher(this)); 394 setRequestTimeout(JDIDebugModel.getPreferences().getInt(JDIDebugModel.PREF_REQUEST_TIMEOUT)); 395 initializeRequests(); 396 initializeState(); 397 initializeBreakpoints(); 398 getLaunch().addDebugTarget(this); 399 DebugPlugin plugin = DebugPlugin.getDefault(); 400 plugin.addDebugEventListener(this); 401 fireCreationEvent(); 402 plugin.asyncExec(new Runnable () { 404 public void run() { 405 EventDispatcher dispatcher = getEventDispatcher(); 406 if (dispatcher != null) { 407 Thread t= new Thread (dispatcher, JDIDebugModel.getPluginIdentifier() + JDIDebugModelMessages.JDIDebugTarget_JDI_Event_Dispatcher); 408 t.setDaemon(true); 409 t.start(); 410 } 411 } 412 }); 413 } 414 415 418 protected void initializeState() { 419 420 List threads= null; 421 VirtualMachine vm = getVM(); 422 if (vm != null) { 423 try { 424 threads= vm.allThreads(); 425 } catch (RuntimeException e) { 426 internalError(e); 427 } 428 if (threads != null) { 429 Iterator initialThreads= threads.iterator(); 430 while (initialThreads.hasNext()) { 431 createThread((ThreadReference) initialThreads.next()); 432 } 433 } 434 } 435 436 if (isResumeOnStartup()) { 437 setSuspended(false); 438 } 439 } 440 441 445 protected void initializeRequests() { 446 setThreadStartHandler(new ThreadStartHandler()); 447 new ThreadDeathHandler(); 448 } 449 450 454 protected void initializeBreakpoints() { 455 IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager(); 456 manager.addBreakpointListener(this); 457 IBreakpoint[] bps = manager.getBreakpoints(JDIDebugModel.getPluginIdentifier()); 458 for (int i = 0; i < bps.length; i++) { 459 if (bps[i] instanceof IJavaBreakpoint) { 460 breakpointAdded(bps[i]); 461 } 462 } 463 } 464 465 475 protected JDIThread createThread(ThreadReference thread) { 476 JDIThread jdiThread= newThread(thread); 477 if (jdiThread == null) { 478 return null; 479 } 480 if (isDisconnected()) { 481 return null; 482 } 483 synchronized (fThreads) { 484 fThreads.add(jdiThread); 485 } 486 jdiThread.fireCreationEvent(); 487 return jdiThread; 488 } 489 490 497 protected JDIThread newThread(ThreadReference reference) { 498 try { 499 return new JDIThread(this, reference); 500 } catch (ObjectCollectedException exception) { 501 } 504 return null; 505 } 506 507 510 public IThread[] getThreads() { 511 synchronized (fThreads) { 512 return (IThread[])fThreads.toArray(new IThread[0]); 513 } 514 } 515 516 519 public boolean canResume() { 520 return (isSuspended() || hasSuspendedThreads()) 521 && isAvailable() && !isPerformingHotCodeReplace(); 522 } 523 524 529 private boolean hasSuspendedThreads() { 530 Iterator it = getThreadIterator(); 531 while(it.hasNext()){ 532 IThread thread = (IThread)it.next(); 533 if(thread.isSuspended()) 534 return true; 535 } 536 return false; 537 } 538 539 542 public boolean canSuspend() { 543 if (!isSuspended() && isAvailable()) { 544 IThread[] threads= getThreads(); 546 for (int i= 0, numThreads= threads.length; i < numThreads; i++) { 547 if (((JDIThread)threads[i]).isSuspended()) { 548 return false; 549 } 550 } 551 return true; 552 } 553 return false; 554 } 555 556 559 public boolean canTerminate() { 560 return supportsTerminate() && isAvailable(); 561 } 562 563 566 public boolean canDisconnect() { 567 return supportsDisconnect() && !isDisconnected(); 568 } 569 570 575 protected boolean supportsDisconnect() { 576 return fSupportsDisconnect; 577 } 578 579 586 private void setSupportsDisconnect(boolean supported) { 587 fSupportsDisconnect = supported; 588 } 589 590 595 protected boolean supportsTerminate() { 596 return fSupportsTerminate; 597 } 598 599 606 private void setSupportsTerminate(boolean supported) { 607 fSupportsTerminate = supported; 608 } 609 610 613 public boolean supportsHotCodeReplace() { 614 return supportsJ9HotCodeReplace() || supportsJDKHotCodeReplace(); 615 } 616 617 620 public boolean supportsInstanceBreakpoints() { 621 if (isAvailable() && JDIDebugPlugin.isJdiVersionGreaterThanOrEqual(new int[] {1,4})) { 622 VirtualMachine vm = getVM(); 623 if (vm != null) { 624 return vm.canUseInstanceFilters(); 625 } 626 } 627 return false; 628 } 629 630 635 public boolean supportsJ9HotCodeReplace() { 636 VirtualMachine vm = getVM(); 637 if (isAvailable() && vm instanceof org.eclipse.jdi.hcr.VirtualMachine) { 638 try { 639 return ((org.eclipse.jdi.hcr.VirtualMachine)vm).canReloadClasses(); 640 } catch (UnsupportedOperationException e) { 641 } 644 } 645 return false; 646 } 647 648 653 public boolean supportsJDKHotCodeReplace() { 654 if (isAvailable() && JDIDebugPlugin.isJdiVersionGreaterThanOrEqual(new int[] {1,4})) { 655 VirtualMachine vm = getVM(); 656 if (vm != null) { 657 return vm.canRedefineClasses(); 658 } 659 } 660 return false; 661 } 662 663 668 public boolean canPopFrames() { 669 if (isAvailable() && JDIDebugPlugin.isJdiVersionGreaterThanOrEqual(new int[] {1,4})) { 670 VirtualMachine vm = getVM(); 671 if (vm != null) { 672 return vm.canPopFrames(); 673 } 674 } 675 return false; 676 } 677 678 681 public void disconnect() throws DebugException { 682 683 if (!isAvailable()) { 684 return; 686 } 687 688 if (!canDisconnect()) { 689 notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_disconnect); 690 } 691 692 try { 693 disposeThreadHandler(); 694 VirtualMachine vm = getVM(); 695 if (vm != null) { 696 vm.dispose(); 697 } 698 } catch (VMDisconnectedException e) { 699 disconnected(); 702 } catch (RuntimeException e) { 703 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_disconnecting, new String [] {e.toString()}), e); 704 } 705 706 } 707 708 711 private void disposeThreadHandler() { 712 ThreadStartHandler handler = getThreadStartHandler(); 713 if (handler != null) { 714 handler.deleteRequest(); 715 } 716 } 717 718 724 public VirtualMachine getVM() { 725 return fVirtualMachine; 726 } 727 728 734 private void setVM(VirtualMachine vm) { 735 fVirtualMachine = vm; 736 } 737 738 742 public void setHCROccurred(boolean occurred) { 743 fHasHCROccurred= occurred; 744 } 745 746 public void removeOutOfSynchTypes(List qualifiedNames) { 747 fOutOfSynchTypes.removeAll(qualifiedNames); 748 } 749 750 754 private void setOutOfSynchTypes(List qualifiedNames) { 755 fOutOfSynchTypes= new HashSet (); 756 fOutOfSynchTypes.addAll(qualifiedNames); 757 } 758 759 763 public void addOutOfSynchTypes(List qualifiedNames) { 764 fOutOfSynchTypes.addAll(qualifiedNames); 765 } 766 767 771 public boolean isOutOfSynch(String qualifiedName) { 772 if (fOutOfSynchTypes == null || fOutOfSynchTypes.isEmpty()) { 773 return false; 774 } 775 return fOutOfSynchTypes.contains(qualifiedName); 776 } 777 778 781 public boolean isOutOfSynch() throws DebugException { 782 Iterator threads= getThreadIterator(); 783 while (threads.hasNext()) { 784 JDIThread thread= (JDIThread)threads.next(); 785 if (thread.isOutOfSynch()) { 786 return true; 787 } 788 } 789 return false; 790 } 791 792 795 public boolean mayBeOutOfSynch() { 796 Iterator threads= getThreadIterator(); 797 while (threads.hasNext()) { 798 JDIThread thread= (JDIThread)threads.next(); 799 if (thread.mayBeOutOfSynch()) { 800 return true; 801 } 802 } 803 return false; 804 } 805 806 811 public boolean hasHCRFailed() { 812 return fOutOfSynchTypes != null && !fOutOfSynchTypes.isEmpty(); 813 } 814 815 819 public boolean hasHCROccurred() { 820 return fHasHCROccurred; 821 } 822 823 826 public void reinstallBreakpointsIn(List resources, List classNames) { 827 List breakpoints= getBreakpoints(); 828 IJavaBreakpoint[] copy= new IJavaBreakpoint[breakpoints.size()]; 829 breakpoints.toArray(copy); 830 IJavaBreakpoint breakpoint= null; 831 String installedType= null; 832 833 for (int i= 0; i < copy.length; i++) { 834 breakpoint= copy[i]; 835 if (breakpoint instanceof JavaLineBreakpoint) { 836 try { 837 installedType= breakpoint.getTypeName(); 838 if (classNames.contains(installedType)) { 839 breakpointRemoved(breakpoint, null); 840 breakpointAdded(breakpoint); 841 } 842 } catch (CoreException ce) { 843 logError(ce); 844 continue; 845 } 846 } 847 } 848 } 849 850 857 public JDIThread findThread(ThreadReference tr) { 858 Iterator iter= getThreadIterator(); 859 while (iter.hasNext()) { 860 JDIThread thread = (JDIThread) iter.next(); 861 if (thread.getUnderlyingThread().equals(tr)) 862 return thread; 863 } 864 return null; 865 } 866 867 870 public String getName() throws DebugException { 871 if (fName == null) { 872 VirtualMachine vm = getVM(); 873 if (vm == null) { 874 requestFailed(JDIDebugModelMessages.JDIDebugTarget_Unable_to_retrieve_name___VM_disconnected__1, null); 875 } 876 try { 877 setName(vm.name()); 878 } catch (RuntimeException e) { 879 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_retrieving_name, new String [] {e.toString()}), e); 880 return null; 883 } 884 } 885 return fName; 886 } 887 888 896 protected void setName(String name) { 897 fName = name; 898 } 899 900 909 protected void setProcess(IProcess process) { 910 fProcess = process; 911 } 912 913 916 public IProcess getProcess() { 917 return fProcess; 918 } 919 920 926 public void handleVMDeath(VMDeathEvent event) { 927 terminated(); 928 } 929 930 936 public void handleVMDisconnect(VMDisconnectEvent event) { 937 if (isTerminating()) { 938 terminated(); 939 } else { 940 disconnected(); 941 } 942 } 943 944 947 public boolean isSuspended() { 948 return fSuspended; 949 } 950 951 956 private void setSuspended(boolean suspended) { 957 fSuspended = suspended; 958 } 959 960 964 public boolean isAvailable() { 965 return !(isTerminated() || isTerminating() || isDisconnected()); 966 } 967 968 971 public boolean isTerminated() { 972 return fTerminated; 973 } 974 975 981 protected void setTerminated(boolean terminated) { 982 fTerminated = terminated; 983 } 984 985 991 protected void setDisconnected(boolean disconnected) { 992 fDisconnected= disconnected; 993 } 994 995 998 public boolean isDisconnected() { 999 return fDisconnected; 1000 } 1001 1002 1012 public ClassPrepareRequest createClassPrepareRequest(String classPattern) throws CoreException { 1013 return createClassPrepareRequest(classPattern, null); 1014 } 1015 1016 1033 public ClassPrepareRequest createClassPrepareRequest(String classPattern, String classExclusionPattern) throws CoreException { 1034 return createClassPrepareRequest(classPattern, classExclusionPattern, true); 1035 } 1036 1037 1056 public ClassPrepareRequest createClassPrepareRequest(String classPattern, String classExclusionPattern, boolean enabled) throws CoreException { 1057 return createClassPrepareRequest(classPattern, classExclusionPattern, enabled, null); 1058 } 1059 1060 1081 public ClassPrepareRequest createClassPrepareRequest(String classPattern, String classExclusionPattern, boolean enabled, String sourceName) throws CoreException { 1082 EventRequestManager manager= getEventRequestManager(); 1083 if (!isAvailable() || manager == null) { 1084 requestFailed(JDIDebugModelMessages.JDIDebugTarget_Unable_to_create_class_prepare_request___VM_disconnected__2, null); 1085 } 1086 ClassPrepareRequest req= null; 1087 try { 1088 req= manager.createClassPrepareRequest(); 1089 if (classPattern != null) { 1090 req.addClassFilter(classPattern); 1091 } 1092 if (classExclusionPattern != null) { 1093 req.addClassExclusionFilter(classExclusionPattern); 1094 } 1095 req.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); 1096 if (sourceName != null) { 1097 req.addSourceNameFilter(sourceName); 1098 } 1099 if (enabled) { 1100 req.enable(); 1101 } 1102 } catch (RuntimeException e) { 1103 targetRequestFailed(JDIDebugModelMessages.JDIDebugTarget_Unable_to_create_class_prepare_request__3, e); 1104 return null; 1106 } 1107 return req; 1108 } 1109 1110 1113 public void resume() throws DebugException { 1114 setResumeOnStartup(true); 1118 resume(true); 1119 } 1120 1121 1127 public void resumeQuiet() throws DebugException { 1128 resume(false); 1129 } 1130 1131 1138 protected void resume(boolean fireNotification) throws DebugException { 1139 if ((!isSuspended() && !hasSuspendedThreads()) 1140 || !isAvailable()) { 1141 return; 1142 } 1143 try { 1144 setSuspended(false); 1145 resumeThreads(); 1146 VirtualMachine vm = getVM(); 1147 if (vm != null) { 1148 vm.resume(); 1149 } 1150 if (fireNotification) { 1151 fireResumeEvent(DebugEvent.CLIENT_REQUEST); 1152 } 1153 } catch (VMDisconnectedException e) { 1154 disconnected(); 1155 return; 1156 } catch (RuntimeException e) { 1157 setSuspended(true); 1158 fireSuspendEvent(DebugEvent.CLIENT_REQUEST); 1159 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_resume, new String [] {e.toString()}), e); 1160 } 1161 } 1162 1163 1166 public boolean supportsBreakpoint(IBreakpoint breakpoint) { 1167 return breakpoint instanceof IJavaBreakpoint; 1168 } 1169 1170 1179 public void breakpointAdded(IBreakpoint breakpoint) { 1180 if (!isAvailable()) { 1181 return; 1182 } 1183 if (supportsBreakpoint(breakpoint)) { 1184 try { 1185 JavaBreakpoint javaBreakpoint= (JavaBreakpoint) breakpoint; 1186 if (!getBreakpoints().contains(breakpoint)) { 1187 if (!javaBreakpoint.shouldSkipBreakpoint()) { 1188 javaBreakpoint.addToTarget(this); 1192 } 1193 getBreakpoints().add(breakpoint); 1194 } 1195 } catch (CoreException e) { 1196 logError(e); 1197 } 1198 } 1199 } 1200 1201 1210 public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) { 1211 } 1212 1213 1221 public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) { 1222 if (!isAvailable()) { 1223 return; 1224 } 1225 if (supportsBreakpoint(breakpoint)) { 1226 try { 1227 ((JavaBreakpoint)breakpoint).removeFromTarget(this); 1228 getBreakpoints().remove(breakpoint); 1229 Iterator threads = getThreadIterator(); 1230 while (threads.hasNext()) { 1231 ((JDIThread)threads.next()).removeCurrentBreakpoint(breakpoint); 1232 } 1233 } catch (CoreException e) { 1234 logError(e); 1235 } 1236 } 1237 } 1238 1239 1242 public void suspend() throws DebugException { 1243 if (isSuspended()) { 1244 return; 1245 } 1246 try { 1247 VirtualMachine vm = getVM(); 1248 if (vm != null) { 1249 vm.suspend(); 1250 } 1251 suspendThreads(); 1252 setSuspended(true); 1253 fireSuspendEvent(DebugEvent.CLIENT_REQUEST); 1254 } catch (RuntimeException e) { 1255 setSuspended(false); 1256 fireResumeEvent(DebugEvent.CLIENT_REQUEST); 1257 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_suspend, new String [] {e.toString()}), e); 1258 } 1259 1260 } 1261 1262 1265 protected void suspendThreads() { 1266 Iterator threads = getThreadIterator(); 1267 while (threads.hasNext()) { 1268 ((JDIThread)threads.next()).suspendedByVM(); 1269 } 1270 } 1271 1272 1275 protected void resumeThreads() throws DebugException { 1276 Iterator threads = getThreadIterator(); 1277 while (threads.hasNext()) { 1278 ((JDIThread)threads.next()).resumedByVM(); 1279 } 1280 } 1281 1282 1289 public void prepareToSuspendByBreakpoint(JavaBreakpoint breakpoint) { 1290 setSuspended(true); 1291 suspendThreads(); 1292 } 1293 1294 1301 protected void suspendedByBreakpoint(JavaBreakpoint breakpoint, boolean queueEvent) { 1302 if (queueEvent) { 1303 queueSuspendEvent(DebugEvent.BREAKPOINT); 1304 } else { 1305 fireSuspendEvent(DebugEvent.BREAKPOINT); 1306 } 1307 } 1308 1309 1315 protected void cancelSuspendByBreakpoint(JavaBreakpoint breakpoint) throws DebugException { 1316 setSuspended(false); 1317 resumeThreads(); 1318 } 1319 1320 1323 public void terminate() throws DebugException { 1324 if (!isAvailable()) { 1325 return; 1326 } 1327 if (!supportsTerminate()) { 1328 notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_termination); 1329 } 1330 try { 1331 setTerminating(true); 1332 disposeThreadHandler(); 1333 VirtualMachine vm = getVM(); 1334 if (vm != null) { 1335 vm.exit(1); 1336 } 1337 IProcess process= getProcess(); 1338 if (process != null) { 1339 process.terminate(); 1340 } 1341 } catch (VMDisconnectedException e) { 1342 terminated(); 1345 } catch (TimeoutException exception) { 1346 IProcess process = getProcess(); 1348 if (process != null && process.isTerminated()) { 1349 terminated(); 1350 } else { 1351 disconnected(); 1353 } 1354 } catch (RuntimeException e) { 1355 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_terminating, new String [] {e.toString()}), e); 1356 } 1357 } 1358 1359 1363 protected void terminated() { 1364 setTerminating(false); 1365 if (!isTerminated()) { 1366 setTerminated(true); 1367 setDisconnected(true); 1368 cleanup(); 1369 fireTerminateEvent(); 1370 } 1371 } 1372 1373 1377 protected void disconnected() { 1378 if (!isDisconnected()) { 1379 setDisconnected(true); 1380 cleanup(); 1381 fireTerminateEvent(); 1382 } 1383 } 1384 1385 1396 protected void cleanup() { 1397 removeAllThreads(); 1398 DebugPlugin plugin = DebugPlugin.getDefault(); 1399 plugin.getBreakpointManager().removeBreakpointListener(this); 1400 plugin.getLaunchManager().removeLaunchListener(this); 1401 plugin.getBreakpointManager().removeBreakpointManagerListener(this); 1402 plugin.removeDebugEventListener(this); 1403 removeAllBreakpoints(); 1404 fOutOfSynchTypes.clear(); 1405 if (fEngines != null) { 1406 Iterator engines = fEngines.values().iterator(); 1407 while (engines.hasNext()) { 1408 IAstEvaluationEngine engine = (IAstEvaluationEngine)engines.next(); 1409 engine.dispose(); 1410 } 1411 fEngines.clear(); 1412 } 1413 fVirtualMachine= null; 1414 setThreadStartHandler(null); 1415 setEventDispatcher(null); 1416 setStepFilters(new String [0]); 1417 } 1418 1419 1423 protected void removeAllThreads() { 1424 Iterator itr= getThreadIterator(); 1425 while (itr.hasNext()) { 1426 JDIThread child= (JDIThread) itr.next(); 1427 child.terminated(); 1428 } 1429 synchronized (fThreads) { 1430 fThreads.clear(); 1431 } 1432 } 1433 1434 1440 protected void removeAllBreakpoints() { 1441 Iterator breakpoints= ((ArrayList )((ArrayList )getBreakpoints()).clone()).iterator(); 1442 while (breakpoints.hasNext()) { 1443 JavaBreakpoint breakpoint= (JavaBreakpoint) breakpoints.next(); 1444 try { 1445 breakpoint.removeFromTarget(this); 1446 } catch (CoreException e) { 1447 logError(e); 1448 } 1449 } 1450 getBreakpoints().clear(); 1451 } 1452 1453 1457 protected void reinstallAllBreakpoints() { 1458 Iterator breakpoints= ((ArrayList )((ArrayList )getBreakpoints()).clone()).iterator(); 1459 while (breakpoints.hasNext()) { 1460 JavaBreakpoint breakpoint= (JavaBreakpoint) breakpoints.next(); 1461 try { 1462 breakpoint.addToTarget(this); 1463 } catch (CoreException e) { 1464 logError(e); 1465 } 1466 } 1467 } 1468 1469 1475 public List jdiClassesByName(String className) { 1476 VirtualMachine vm = getVM(); 1477 if (vm != null) { 1478 try { 1479 return vm.classesByName(className); 1480 } catch (VMDisconnectedException e) { 1481 if (!isAvailable()) { 1482 return Collections.EMPTY_LIST; 1483 } 1484 logError(e); 1485 } catch (RuntimeException e) { 1486 internalError(e); 1487 } 1488 } 1489 return Collections.EMPTY_LIST; 1490 } 1491 1492 1495 public IJavaVariable findVariable(String varName) throws DebugException { 1496 IThread[] threads = getThreads(); 1497 for (int i = 0; i < threads.length; i++) { 1498 IJavaThread thread = (IJavaThread)threads[i]; 1499 IJavaVariable var = thread.findVariable(varName); 1500 if (var != null) { 1501 return var; 1502 } 1503 } 1504 return null; 1505 } 1506 1507 1510 public Object getAdapter(Class adapter) { 1511 if (adapter == IJavaDebugTarget.class) { 1512 return this; 1513 } 1514 return super.getAdapter(adapter); 1515 } 1516 1517 1522 public void shutdown() { 1523 EventDispatcher dispatcher = ((JDIDebugTarget)getDebugTarget()).getEventDispatcher(); 1524 if (dispatcher != null) { 1525 dispatcher.shutdown(); 1526 } 1527 try { 1528 if (supportsTerminate()) { 1529 terminate(); 1530 } else if (supportsDisconnect()) { 1531 disconnect(); 1532 } 1533 } catch (DebugException e) { 1534 JDIDebugPlugin.log(e); 1535 } 1536 cleanup(); 1537 } 1538 1539 1554 protected Integer getCRC(String typeName) throws DebugException { 1555 if (getVM() instanceof org.eclipse.jdi.hcr.VirtualMachine) { 1556 List classes = jdiClassesByName(typeName); 1557 if (!classes.isEmpty()) { 1558 ReferenceType type = (ReferenceType)classes.get(0); 1559 if (type instanceof org.eclipse.jdi.hcr.ReferenceType) { 1560 try { 1561 org.eclipse.jdi.hcr.ReferenceType rt = (org.eclipse.jdi.hcr.ReferenceType)type; 1562 if (rt.isVersionKnown()) { 1563 return new Integer (rt.getClassFileVersion()); 1564 } 1565 } catch (RuntimeException e) { 1566 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_retrieving_version_information, new String [] {e.toString(), type.name()}), e); 1567 return null; 1570 } 1571 } 1572 } 1573 } 1574 return null; 1575 } 1576 1577 1580 public IJavaType[] getJavaTypes(String name) throws DebugException { 1581 try { 1582 VirtualMachine vm = getVM(); 1584 if (vm == null) { 1585 requestFailed(JDIDebugModelMessages.JDIDebugTarget_Unable_to_retrieve_types___VM_disconnected__4, null); 1586 } 1587 List classes = vm.classesByName(name); 1588 if (classes.size() == 0) { 1589 switch (name.charAt(0)) { 1590 case 'b': 1591 if (name.equals("boolean")) { return new IJavaType[] {newValue(true).getJavaType()}; 1593 } else if (name.equals("byte")) { return new IJavaType[] {newValue((byte)1).getJavaType()}; 1595 } 1596 break; 1597 case 'i': 1598 if (name.equals("int")) { return new IJavaType[] {newValue(1).getJavaType()}; 1600 } 1601 break; 1602 case 'l': 1603 if (name.equals("long")) { return new IJavaType[] {newValue(1l).getJavaType()}; 1605 } 1606 break; 1607 case 'c': 1608 if (name.equals("char")) { return new IJavaType[] {newValue(' ').getJavaType()}; 1610 } 1611 break; 1612 case 's': 1613 if (name.equals("short")) { return new IJavaType[] {newValue((short)1).getJavaType()}; 1615 } 1616 break; 1617 case 'f': 1618 if (name.equals("float")) { return new IJavaType[] {newValue(1f).getJavaType()}; 1620 } 1621 break; 1622 case 'd': 1623 if (name.equals("double")) { return new IJavaType[] {newValue(1d).getJavaType()}; 1625 } 1626 break; 1627 } 1628 return null; 1629 } 1630 IJavaType[] types = new IJavaType[classes.size()]; 1631 for (int i = 0; i < types.length; i++) { 1632 types[i] = JDIType.createType(this, (Type)classes.get(i)); 1633 } 1634 return types; 1635 } catch (RuntimeException e) { 1636 targetRequestFailed(MessageFormat.format("{0} occurred while retrieving class for name {1}", new String []{e.toString(), name}), e); return null; 1640 } 1641 } 1642 1643 1646 public IJavaValue newValue(boolean value) { 1647 VirtualMachine vm = getVM(); 1648 if (vm != null) { 1649 Value v = vm.mirrorOf(value); 1650 return JDIValue.createValue(this, v); 1651 } 1652 return null; 1653 } 1654 1655 1658 public IJavaValue newValue(byte value) { 1659 VirtualMachine vm = getVM(); 1660 if (vm != null) { 1661 Value v = vm.mirrorOf(value); 1662 return JDIValue.createValue(this, v); 1663 } 1664 return null; 1665 } 1666 1667 1670 public IJavaValue newValue(char value) { 1671 VirtualMachine vm = getVM(); 1672 if (vm != null) { 1673 Value v = vm.mirrorOf(value); 1674 return JDIValue.createValue(this, v); 1675 } 1676 return null; 1677 } 1678 1679 1682 public IJavaValue newValue(double value) { 1683 VirtualMachine vm = getVM(); 1684 if (vm != null) { 1685 Value v = vm.mirrorOf(value); 1686 return JDIValue.createValue(this, v); 1687 } 1688 return null; 1689 } 1690 1691 1694 public IJavaValue newValue(float value) { 1695 VirtualMachine vm = getVM(); 1696 if (vm != null) { 1697 Value v = vm.mirrorOf(value); 1698 return JDIValue.createValue(this, v); 1699 } 1700 return null; 1701 } 1702 1703 1706 public IJavaValue newValue(int value) { 1707 VirtualMachine vm = getVM(); 1708 if (vm != null) { 1709 Value v = vm.mirrorOf(value); 1710 return JDIValue.createValue(this, v); 1711 } 1712 return null; 1713 } 1714 1715 1718 public IJavaValue newValue(long value) { 1719 VirtualMachine vm = getVM(); 1720 if (vm != null) { 1721 Value v = vm.mirrorOf(value); 1722 return JDIValue.createValue(this, v); 1723 } 1724 return null; 1725 } 1726 1727 1730 public IJavaValue newValue(short value) { 1731 VirtualMachine vm = getVM(); 1732 if (vm != null) { 1733 Value v = vm.mirrorOf(value); 1734 return JDIValue.createValue(this, v); 1735 } 1736 return null; 1737 } 1738 1739 1742 public IJavaValue newValue(String value) { 1743 VirtualMachine vm = getVM(); 1744 if (vm != null) { 1745 Value v = vm.mirrorOf(value); 1746 return JDIValue.createValue(this, v); 1747 } 1748 return null; 1749 } 1750 1751 1754 public IJavaValue nullValue() { 1755 return JDIValue.createValue(this, null); 1756 } 1757 1758 1761 public IJavaValue voidValue() { 1762 return new JDIVoidValue(this); 1763 } 1764 1765 protected boolean isTerminating() { 1766 return fTerminating; 1767 } 1768 1769 protected void setTerminating(boolean terminating) { 1770 fTerminating = terminating; 1771 } 1772 1773 1777 class ThreadStartHandler implements IJDIEventListener { 1778 1779 protected EventRequest fRequest; 1780 1781 protected ThreadStartHandler() { 1782 createRequest(); 1783 } 1784 1785 1789 protected void createRequest() { 1790 EventRequestManager manager = getEventRequestManager(); 1791 if (manager != null) { 1792 try { 1793 EventRequest req= manager.createThreadStartRequest(); 1794 req.setSuspendPolicy(EventRequest.SUSPEND_NONE); 1795 req.enable(); 1796 addJDIEventListener(this, req); 1797 setRequest(req); 1798 } catch (RuntimeException e) { 1799 logError(e); 1800 } 1801 } 1802 } 1803 1804 1816 public boolean handleEvent(Event event, JDIDebugTarget target) { 1817 ThreadReference thread= ((ThreadStartEvent)event).thread(); 1818 try { 1819 if (thread.isCollected()) { 1820 return false; 1821 } 1822 } catch (VMDisconnectedException exception) { 1823 return false; 1824 } catch (ObjectCollectedException e) { 1825 return false; 1826 } catch (TimeoutException e) { 1827 } 1829 JDIThread jdiThread= findThread(thread); 1830 if (jdiThread == null) { 1831 jdiThread = createThread(thread); 1832 if (jdiThread == null) { 1833 return false; 1834 } 1835 } else { 1836 jdiThread.disposeStackFrames(); 1837 jdiThread.fireChangeEvent(DebugEvent.CONTENT); 1838 } 1839 return !jdiThread.isSuspended(); 1840 } 1841 1842 1845 public void wonSuspendVote(Event event, JDIDebugTarget target) { 1846 } 1848 1849 1852 protected void deleteRequest() { 1853 if (getRequest() != null) { 1854 removeJDIEventListener(this, getRequest()); 1855 setRequest(null); 1856 } 1857 } 1858 1859 protected EventRequest getRequest() { 1860 return fRequest; 1861 } 1862 1863 protected void setRequest(EventRequest request) { 1864 fRequest = request; 1865 } 1866} 1867 1868 1873 class ThreadDeathHandler implements IJDIEventListener { 1874 1875 protected ThreadDeathHandler() { 1876 createRequest(); 1877 } 1878 1879 1883 protected void createRequest() { 1884 EventRequestManager manager = getEventRequestManager(); 1885 if (manager != null) { 1886 try { 1887 EventRequest req= manager.createThreadDeathRequest(); 1888 req.setSuspendPolicy(EventRequest.SUSPEND_NONE); 1889 req.enable(); 1890 addJDIEventListener(this, req); 1891 } catch (RuntimeException e) { 1892 logError(e); 1893 } 1894 } 1895 } 1896 1897 1907 public boolean handleEvent(Event event, JDIDebugTarget target) { 1908 ThreadReference ref= ((ThreadDeathEvent)event).thread(); 1909 JDIThread thread= findThread(ref); 1910 if (thread != null) { 1911 synchronized (fThreads) { 1912 fThreads.remove(thread); 1913 } 1914 thread.terminated(); 1915 } 1916 return true; 1917 } 1918 1919 1922 public void wonSuspendVote(Event event, JDIDebugTarget target) { 1923 } 1925 1926 } 1927 1928 class CleanUpJob extends Job { 1929 1930 1933 public CleanUpJob() { 1934 super(JDIDebugModelMessages.JDIDebugTarget_0); 1935 setSystem(true); 1936 } 1937 1938 1941 protected IStatus run(IProgressMonitor monitor) { 1942 if (isAvailable()) { 1943 if (fEventDispatcher != null) { 1944 fEventDispatcher.shutdown(); 1945 } 1946 disconnected(); 1947 } 1948 return Status.OK_STATUS; 1949 } 1950 1951 1954 public boolean shouldRun() { 1955 return isAvailable(); 1956 } 1957 1958 1961 public boolean shouldSchedule() { 1962 return isAvailable(); 1963 } 1964 1965 1966 } 1967 1968 protected ThreadStartHandler getThreadStartHandler() { 1969 return fThreadStartHandler; 1970 } 1971 1972 protected void setThreadStartHandler(ThreadStartHandler threadStartHandler) { 1973 fThreadStartHandler = threadStartHandler; 1974 } 1975 1976 1981 public boolean supportsStorageRetrieval() { 1982 return false; 1983 } 1984 1985 1988 public IMemoryBlock getMemoryBlock(long startAddress, long length) 1989 throws DebugException { 1990 notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_storage_retrieval); 1991 return null; 1994 } 1995 1996 1999 public void launchRemoved(ILaunch launch) { 2000 if (!isAvailable()) { 2001 return; 2002 } 2003 if (launch.equals(getLaunch())) { 2004 disconnected(); 2007 } 2008 } 2009 2010 2013 public void launchAdded(ILaunch launch) { 2014 } 2015 2016 2019 public void launchChanged(ILaunch launch) { 2020 } 2021 2022 2029 private synchronized void setResumeOnStartup(boolean resume) { 2030 fResumeOnStartup = resume; 2031 } 2032 2033 2038 protected synchronized boolean isResumeOnStartup() { 2039 return fResumeOnStartup; 2040 } 2041 2042 2045 public String [] getStepFilters() { 2046 return fStepFilters; 2047 } 2048 2049 2052 public boolean isFilterConstructors() { 2053 return (fStepFilterMask & FILTER_CONSTRUCTORS) > 0; 2054 } 2055 2056 2059 public boolean isFilterStaticInitializers() { 2060 return (fStepFilterMask & FILTER_STATIC_INITIALIZERS) > 0; 2061 } 2062 2063 2066 public boolean isFilterSynthetics() { 2067 return (fStepFilterMask & FILTER_SYNTHETICS) > 0; 2068 } 2069 2070 2079 public boolean isStepThruFilters() { 2080 return (fStepFilterMask & STEP_THRU_FILTERS) > 0; 2081 } 2082 2083 2086 public boolean isStepFiltersEnabled() { 2087 return (fStepFilterMask & STEP_FILTERS_ENABLED) > 0; 2088 } 2089 2090 2093 public void setFilterConstructors(boolean filter) { 2094 if (filter) { 2095 fStepFilterMask = fStepFilterMask | FILTER_CONSTRUCTORS; 2096 } else { 2097 fStepFilterMask = fStepFilterMask & (FILTER_CONSTRUCTORS ^ XOR_MASK); 2098 } 2099 } 2100 2101 2104 public void setFilterStaticInitializers(boolean filter) { 2105 if (filter) { 2106 fStepFilterMask = fStepFilterMask | FILTER_STATIC_INITIALIZERS; 2107 } else { 2108 fStepFilterMask = fStepFilterMask & (FILTER_STATIC_INITIALIZERS ^ XOR_MASK); 2109 } 2110 } 2111 2112 2115 public void setFilterSynthetics(boolean filter) { 2116 if (filter) { 2117 fStepFilterMask = fStepFilterMask | FILTER_SYNTHETICS; 2118 } else { 2119 fStepFilterMask = fStepFilterMask & (FILTER_SYNTHETICS ^ XOR_MASK); 2120 } 2121 } 2122 2123 2131 public void setStepThruFilters(boolean thru) { 2132 if (thru) { 2133 fStepFilterMask = fStepFilterMask | STEP_THRU_FILTERS; 2134 } else { 2135 fStepFilterMask = fStepFilterMask & (STEP_THRU_FILTERS ^ XOR_MASK); 2136 } 2137 } 2138 2139 2142 public void setStepFilters(String [] list) { 2143 fStepFilters = list; 2144 } 2145 2146 2149 public void setStepFiltersEnabled(boolean enabled) { 2150 if (enabled) { 2151 fStepFilterMask = fStepFilterMask | STEP_FILTERS_ENABLED; 2152 } else { 2153 fStepFilterMask = fStepFilterMask & (STEP_FILTERS_ENABLED ^ XOR_MASK); 2154 } 2155 } 2156 2157 2160 public boolean hasThreads() { 2161 return fThreads.size() > 0; 2162 } 2163 2164 2167 public ILaunch getLaunch() { 2168 return fLaunch; 2169 } 2170 2171 2176 private void setLaunch(ILaunch launch) { 2177 fLaunch = launch; 2178 } 2179 2180 2187 protected int getSuspendCount() { 2188 return fSuspendCount; 2189 } 2190 2191 2198 protected void incrementSuspendCount(int eventDetail) { 2199 if (eventDetail != DebugEvent.EVALUATION_IMPLICIT) { 2200 fSuspendCount++; 2201 } 2202 } 2203 2204 2211 public IAstEvaluationEngine getEvaluationEngine(IJavaProject project) { 2212 if (fEngines == null) { 2213 fEngines = new HashMap (2); 2214 } 2215 IAstEvaluationEngine engine = (IAstEvaluationEngine)fEngines.get(project); 2216 if (engine == null) { 2217 engine = EvaluationManager.newAstEvaluationEngine(project, this); 2218 fEngines.put(project, engine); 2219 } 2220 return engine; 2221 } 2222 2223 2226 public boolean supportsMonitorInformation() { 2227 if (!isAvailable()) { 2228 return false; 2229 } 2230 VirtualMachine vm = getVM(); 2231 if (vm != null) { 2232 return vm.canGetCurrentContendedMonitor() && vm.canGetMonitorInfo() && vm.canGetOwnedMonitorInfo(); 2233 } 2234 return false; 2235 } 2236 2237 2241 public void setIsPerformingHotCodeReplace(boolean isPerformingHotCodeReplace) { 2242 fIsPerformingHotCodeReplace= isPerformingHotCodeReplace; 2243 } 2244 2245 2248 public boolean isPerformingHotCodeReplace() { 2249 return fIsPerformingHotCodeReplace; 2250 } 2251 2252 2255 public boolean supportsAccessWatchpoints() { 2256 VirtualMachine vm = getVM(); 2257 if (isAvailable() && vm != null) { 2258 return vm.canWatchFieldAccess(); 2259 } 2260 return false; 2261 } 2262 2263 2266 public boolean supportsModificationWatchpoints() { 2267 VirtualMachine vm = getVM(); 2268 if (isAvailable() && vm != null) { 2269 return vm.canWatchFieldModification(); 2270 } 2271 return false; 2272 } 2273 2274 2277 public void setDefaultStratum(String stratum) { 2278 VirtualMachine vm = getVM(); 2279 if (vm != null) { 2280 vm.setDefaultStratum(stratum); 2281 } 2282 } 2283 2284 public String getDefaultStratum() { 2285 VirtualMachine vm = getVM(); 2286 if (vm != null) { 2287 return vm.getDefaultStratum(); 2288 } 2289 return null; 2290 } 2291 2292 2295 public boolean supportsStepFilters() { 2296 return isAvailable(); 2297 } 2298 2299 2303 public void breakpointManagerEnablementChanged(boolean enabled) { 2304 if (!isAvailable()) { 2305 return; 2306 } 2307 Iterator breakpoints= ((ArrayList )((ArrayList )getBreakpoints()).clone()).iterator(); 2308 while (breakpoints.hasNext()) { 2309 JavaBreakpoint breakpoint= (JavaBreakpoint) breakpoints.next(); 2310 try { 2311 if (enabled) { 2312 breakpoint.addToTarget(this); 2313 } else if (breakpoint.shouldSkipBreakpoint()) { 2314 breakpoint.removeFromTarget(this); 2315 } 2316 } catch (CoreException e) { 2317 logError(e); 2318 } 2319 } 2320 } 2321 2322 2325 public void handleDebugEvents(DebugEvent[] events) { 2326 if (events.length == 1) { 2327 DebugEvent event = events[0]; 2328 if (event.getSource().equals(getProcess()) && event.getKind() == DebugEvent.TERMINATE) { 2329 int timeout = getRequestTimeout(); 2332 if (timeout < 0) { 2333 timeout = 3000; 2334 } 2335 new CleanUpJob().schedule(timeout); 2336 } 2337 } 2338 } 2339 2340 2343 public IDebugTarget getDebugTarget() { 2344 return this; 2345 } 2346 2347 2353 void addThreadGroup(ThreadGroupReference group) { 2354 ThreadGroupReference currentGroup = group; 2355 while(currentGroup != null){ 2356 synchronized (fGroups) { 2357 if (findThreadGroup(currentGroup) == null) { 2358 JDIThreadGroup modelGroup = new JDIThreadGroup(this, currentGroup); 2359 fGroups.add(modelGroup); 2360 currentGroup = currentGroup.parent(); 2361 } else { 2363 currentGroup = null; 2364 } 2365 } 2366 } 2367 } 2368 2369 JDIThreadGroup findThreadGroup(ThreadGroupReference group) { 2370 synchronized (fGroups) { 2371 Iterator groups = fGroups.iterator(); 2372 while (groups.hasNext()) { 2373 JDIThreadGroup modelGroup = (JDIThreadGroup) groups.next(); 2374 if (modelGroup.getUnderlyingThreadGroup().equals(group)) { 2375 return modelGroup; 2376 } 2377 } 2378 } 2379 return null; 2380 } 2381 2382 2385 public IJavaThreadGroup[] getRootThreadGroups() throws DebugException { 2386 try { 2387 VirtualMachine vm = getVM(); 2388 if (vm == null) { 2389 return new IJavaThreadGroup[0]; 2390 } 2391 List groups = vm.topLevelThreadGroups(); 2392 List modelGroups = new ArrayList (groups.size()); 2393 Iterator iterator = groups.iterator(); 2394 while (iterator.hasNext()) { 2395 ThreadGroupReference ref = (ThreadGroupReference) iterator.next(); 2396 JDIThreadGroup group = findThreadGroup(ref); 2397 if (group != null) { 2398 modelGroups.add(group); 2399 } 2400 } 2401 return (IJavaThreadGroup[]) modelGroups.toArray(new IJavaThreadGroup[modelGroups.size()]); 2402 } catch (RuntimeException e) { 2403 targetRequestFailed(JDIDebugModelMessages.JDIDebugTarget_1, e); 2404 } 2405 return null; 2406 } 2407 2408 2411 public IJavaThreadGroup[] getAllThreadGroups() throws DebugException { 2412 synchronized (fGroups) { 2413 return (IJavaThreadGroup[]) fGroups.toArray(new IJavaThreadGroup[fGroups.size()]); 2414 } 2415 } 2416 2417 2420 public boolean supportsInstanceRetrieval() { 2421 VirtualMachine vm = getVM(); 2422 if (vm != null) { 2423 return vm.canGetInstanceInfo(); 2424 } 2425 return false; 2426 } 2427 2428 2441 public byte[] sendJDWPCommand(byte commandSet, byte commandId, byte[] data) throws IOException { 2442 int command = (256 * commandSet) + commandId; 2443 JdwpReplyPacket reply = ((VirtualMachineImpl)getVM()).requestVM(command, data); 2444 return reply.getPacketAsBytes(); 2445 } 2446 2447 2450 public boolean supportsForceReturn() { 2451 VirtualMachine machine = getVM(); 2452 if(machine == null) { 2453 return false; 2454 } 2455 return machine.canForceEarlyReturn(); 2456 } 2457} 2458 | Popular Tags |