protected void commandCancelled() { if (!DebuggerManagerThreadImpl.isManagerThread()) { return; } // context thread is not suspended final DebuggerContextImpl context = getDebuggerContext(); final SuspendContextImpl suspendContext = context.getSuspendContext(); if (suspendContext == null) { return; } final ThreadReferenceProxyImpl threadToSelect = context.getThreadProxy(); if (threadToSelect == null) { return; } if (!suspendContext.isResumed()) { final SuspendContextImpl threadContext = SuspendManagerUtil.getSuspendContextForThread(suspendContext, threadToSelect); context .getDebugProcess() .getManagerThread() .schedule(new RebuildFramesListCommand(context, threadContext)); refillThreadsCombo(threadToSelect); } }
private boolean shouldApplyContext(DebuggerContextImpl context) { SuspendContextImpl suspendContext = context.getSuspendContext(); SuspendContextImpl currentContext = (SuspendContextImpl) getSession().getSuspendContext(); if (suspendContext != null && !suspendContext.equals(currentContext)) return true; JavaExecutionStack currentExecutionStack = currentContext != null ? currentContext.getActiveExecutionStack() : null; return currentExecutionStack == null || !Comparing.equal(context.getThreadProxy(), currentExecutionStack.getThreadProxy()); }
public static List<Pair<Breakpoint, Event>> getEventDescriptors( SuspendContextImpl suspendContext) { DebuggerManagerThreadImpl.assertIsManagerThread(); if (suspendContext == null || suspendContext.getEventSet() == null) { return Collections.emptyList(); } final List<Pair<Breakpoint, Event>> eventDescriptors = new ArrayList<Pair<Breakpoint, Event>>(); final RequestManagerImpl requestManager = suspendContext.getDebugProcess().getRequestsManager(); for (final Event event : suspendContext.getEventSet()) { Requestor requestor = requestManager.findRequestor(event.request()); if (requestor instanceof Breakpoint) { eventDescriptors.add(new Pair<Breakpoint, Event>((Breakpoint) requestor, event)); } } return eventDescriptors; }
protected void printLocation(SuspendContextImpl suspendContext) { try { Location location = suspendContext.getFrameProxy().location(); String message = "paused at " + location.sourceName() + ":" + location.lineNumber(); println(message, ProcessOutputTypes.SYSTEM); } catch (Throwable e) { addException(e); } }
protected EvaluationContextImpl createEvaluationContext(final SuspendContextImpl suspendContext) { try { StackFrameProxyImpl proxy = suspendContext.getFrameProxy(); assertNotNull(proxy); return new EvaluationContextImpl(suspendContext, proxy, proxy.thisObject()); } catch (EvaluateException e) { error(e); return null; } }
protected ObjectReference getThisObject(SuspendContextImpl context, LocatableEvent event) throws EvaluateException { ThreadReferenceProxyImpl thread = context.getThread(); if (thread != null) { StackFrameProxyImpl stackFrameProxy = thread.frame(0); if (stackFrameProxy != null) { return stackFrameProxy.thisObject(); } } return null; }
public boolean processLocatableEvent( final SuspendContextCommandImpl action, final LocatableEvent event) throws EventProcessingException { final SuspendContextImpl context = action.getSuspendContext(); if (!isValid()) { context.getDebugProcess().getRequestsManager().deleteRequest(this); return false; } final String[] title = {DebuggerBundle.message("title.error.evaluating.breakpoint.condition")}; try { final StackFrameProxyImpl frameProxy = context.getThread().frame(0); if (frameProxy == null) { // might be if the thread has been collected return false; } final EvaluationContextImpl evaluationContext = new EvaluationContextImpl( action.getSuspendContext(), frameProxy, getThisObject(context, event)); if (!evaluateCondition(evaluationContext, event)) { return false; } title[0] = DebuggerBundle.message("title.error.evaluating.breakpoint.action"); runAction(evaluationContext, event); } catch (final EvaluateException ex) { if (ApplicationManager.getApplication().isUnitTestMode()) { System.out.println(ex.getMessage()); return false; } throw new EventProcessingException(title[0], ex.getMessage(), ex); } return true; }
@Override public final void action() throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("trying " + this); } final SuspendContextImpl suspendContext = getSuspendContext(); if (suspendContext == null) { if (LOG.isDebugEnabled()) { LOG.debug("skip processing - context is null " + this); } notifyCancelled(); return; } if (suspendContext.myInProgress) { suspendContext.postponeCommand(this); } else { try { if (!suspendContext.isResumed()) { suspendContext.myInProgress = true; contextAction(suspendContext); } else { notifyCancelled(); } } finally { suspendContext.myInProgress = false; if (suspendContext.isResumed()) { for (SuspendContextCommandImpl postponed = suspendContext.pollPostponedCommand(); postponed != null; postponed = suspendContext.pollPostponedCommand()) { postponed.notifyCancelled(); } } else { SuspendContextCommandImpl postponed = suspendContext.pollPostponedCommand(); if (postponed != null) { final Stack<SuspendContextCommandImpl> stack = new Stack<>(); while (postponed != null) { stack.push(postponed); postponed = suspendContext.pollPostponedCommand(); } final DebuggerManagerThreadImpl managerThread = suspendContext.getDebugProcess().getManagerThread(); while (!stack.isEmpty()) { managerThread.pushBack(stack.pop()); } } } } } }
private void unsetPausedIfNeeded(DebuggerContextImpl context) { SuspendContextImpl suspendContext = context.getSuspendContext(); if (suspendContext != null && context.getThreadProxy() != suspendContext.getThread()) { ((XDebugSessionImpl) getSession()).unsetPaused(); } }
public void reloadClasses(final Map<String, HotSwapFile> modifiedClasses) { DebuggerManagerThreadImpl.assertIsManagerThread(); if (modifiedClasses == null || modifiedClasses.size() == 0) { myProgress.addMessage( myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message("status.hotswap.loaded.classes.up.to.date")); return; } final DebugProcessImpl debugProcess = getDebugProcess(); final VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy(); final Project project = debugProcess.getProject(); final BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project)).getBreakpointManager(); breakpointManager.disableBreakpoints(debugProcess); // virtualMachineProxy.suspend(); try { RedefineProcessor redefineProcessor = new RedefineProcessor(virtualMachineProxy); int processedEntriesCount = 0; for (final Map.Entry<String, HotSwapFile> entry : modifiedClasses.entrySet()) { // stop if process is finished already if (debugProcess.isDetached() || debugProcess.isDetaching()) { break; } if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) { // once at least one class has been actually reloaded, do not interrupt the whole process break; } processedEntriesCount++; final String qualifiedName = entry.getKey(); if (qualifiedName != null) { myProgress.setText(qualifiedName); myProgress.setFraction(processedEntriesCount / (double) modifiedClasses.size()); } try { redefineProcessor.processClass(qualifiedName, entry.getValue().file); } catch (IOException e) { reportProblem(qualifiedName, e); } } if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) { // once at least one class has been actually reloaded, do not interrupt the whole process return; } redefineProcessor.processPending(); myProgress.setFraction(1); final int partiallyRedefinedClassesCount = redefineProcessor.getPartiallyRedefinedClassesCount(); if (partiallyRedefinedClassesCount == 0) { myProgress.addMessage( myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message( "status.classes.reloaded", redefineProcessor.getProcessedClassesCount())); } else { final String message = DebuggerBundle.message( "status.classes.not.all.versions.reloaded", partiallyRedefinedClassesCount, redefineProcessor.getProcessedClassesCount()); myProgress.addMessage(myDebuggerSession, MessageCategory.WARNING, message); } LOG.debug("classes reloaded"); } catch (Throwable e) { processException(e); } debugProcess.getPositionManager().clearCache(); DebuggerContextImpl context = myDebuggerSession.getContextManager().getContext(); SuspendContextImpl suspendContext = context.getSuspendContext(); if (suspendContext != null) { XExecutionStack stack = suspendContext.getActiveExecutionStack(); if (stack != null) { ((JavaExecutionStack) stack).initTopFrame(); } } final Semaphore waitSemaphore = new Semaphore(); waitSemaphore.down(); //noinspection SSBasedInspection SwingUtilities.invokeLater( () -> { try { if (!project.isDisposed()) { breakpointManager.reloadBreakpoints(); debugProcess.getRequestsManager().clearWarnings(); if (LOG.isDebugEnabled()) { LOG.debug("requests updated"); LOG.debug("time stamp set"); } myDebuggerSession.refresh(false); XDebugSession session = myDebuggerSession.getXDebugSession(); if (session != null) { session.rebuildViews(); } } } catch (Throwable e) { LOG.error(e); } finally { waitSemaphore.up(); } }); waitSemaphore.waitFor(); if (!project.isDisposed()) { try { breakpointManager.enableBreakpoints(debugProcess); } catch (Exception e) { processException(e); } } }
public DebuggerContextImpl createDebuggerContext(final SuspendContextImpl suspendContext) { return createDebuggerContext(suspendContext, suspendContext.getFrameProxy()); }