use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class DebugProcessEvents method vmAttached.
private void vmAttached() {
DebuggerManagerThreadImpl.assertIsManagerThread();
LOG.assertTrue(!isAttached());
if (myState.compareAndSet(State.INITIAL, State.ATTACHED)) {
final VirtualMachineProxyImpl machineProxy = getVirtualMachineProxy();
final EventRequestManager requestManager = machineProxy.eventRequestManager();
if (machineProxy.canGetMethodReturnValues()) {
myReturnValueWatcher = new MethodReturnValueWatcher(requestManager);
}
final ThreadStartRequest threadStartRequest = requestManager.createThreadStartRequest();
threadStartRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
threadStartRequest.enable();
final ThreadDeathRequest threadDeathRequest = requestManager.createThreadDeathRequest();
threadDeathRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
threadDeathRequest.enable();
// fill position managers
((DebuggerManagerImpl) DebuggerManager.getInstance(getProject())).getCustomPositionManagerFactories().map(factory -> factory.fun(this)).filter(Objects::nonNull).forEach(this::appendPositionManager);
Stream.of(Extensions.getExtensions(PositionManagerFactory.EP_NAME, getProject())).map(factory -> factory.createPositionManager(this)).filter(Objects::nonNull).forEach(this::appendPositionManager);
myDebugProcessDispatcher.getMulticaster().processAttached(this);
createStackCapturingBreakpoints();
// breakpoints should be initialized after all processAttached listeners work
ApplicationManager.getApplication().runReadAction(() -> {
XDebugSession session = getSession().getXDebugSession();
if (session != null) {
session.initBreakpoints();
}
});
final String addressDisplayName = DebuggerBundle.getAddressDisplayName(getConnection());
final String transportName = DebuggerBundle.getTransportName(getConnection());
showStatusText(DebuggerBundle.message("status.connected", addressDisplayName, transportName));
LOG.debug("leave: processVMStartEvent()");
}
}
use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class DebugProcessEvents method processLocatableEvent.
private void processLocatableEvent(final SuspendContextImpl suspendContext, final LocatableEvent event) {
ThreadReference thread = event.thread();
//LOG.assertTrue(thread.isSuspended());
preprocessEvent(suspendContext, thread);
//we use schedule to allow processing other events during processing this one
//this is especially necessary if a method is breakpoint condition
getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {
@Override
public void contextAction() throws Exception {
final SuspendManager suspendManager = getSuspendManager();
SuspendContextImpl evaluatingContext = SuspendManagerUtil.getEvaluatingContext(suspendManager, suspendContext.getThread());
if (evaluatingContext != null && !DebuggerSession.enableBreakpointsDuringEvaluation()) {
// is inside evaluation, so ignore any breakpoints
suspendManager.voteResume(suspendContext);
return;
}
final LocatableEventRequestor requestor = (LocatableEventRequestor) getRequestsManager().findRequestor(event.request());
boolean resumePreferred = requestor != null && DebuggerSettings.SUSPEND_NONE.equals(requestor.getSuspendPolicy());
boolean requestHit;
try {
requestHit = (requestor != null) && requestor.processLocatableEvent(this, event);
} catch (final LocatableEventRequestor.EventProcessingException ex) {
if (LOG.isDebugEnabled()) {
LOG.debug(ex.getMessage());
}
final boolean[] considerRequestHit = new boolean[] { true };
DebuggerInvocationUtil.invokeAndWait(getProject(), () -> {
final String displayName = requestor instanceof Breakpoint ? ((Breakpoint) requestor).getDisplayName() : requestor.getClass().getSimpleName();
final String message = DebuggerBundle.message("error.evaluating.breakpoint.condition.or.action", displayName, ex.getMessage());
considerRequestHit[0] = Messages.showYesNoDialog(getProject(), message, ex.getTitle(), Messages.getQuestionIcon()) == Messages.YES;
}, ModalityState.NON_MODAL);
requestHit = considerRequestHit[0];
resumePreferred = !requestHit;
}
if (requestHit && requestor instanceof Breakpoint) {
// if requestor is a breakpoint and this breakpoint was hit, no matter its suspend policy
ApplicationManager.getApplication().runReadAction(() -> {
XDebugSession session = getSession().getXDebugSession();
if (session != null) {
XBreakpoint breakpoint = ((Breakpoint) requestor).getXBreakpoint();
if (breakpoint != null) {
((XDebugSessionImpl) session).processDependencies(breakpoint);
}
}
});
}
if (!requestHit || resumePreferred) {
suspendManager.voteResume(suspendContext);
} else {
if (myReturnValueWatcher != null) {
myReturnValueWatcher.disable();
}
//if (suspendContext.getSuspendPolicy() == EventRequest.SUSPEND_ALL) {
// // there could be explicit resume as a result of call to voteSuspend()
// // e.g. when breakpoint was considered invalid, in that case the filter will be applied _after_
// // resuming and all breakpoints in other threads will be ignored.
// // As resume() implicitly cleares the filter, the filter must be always applied _before_ any resume() action happens
// myBreakpointManager.applyThreadFilter(DebugProcessEvents.this, event.thread());
//}
suspendManager.voteSuspend(suspendContext);
showStatusText(DebugProcessEvents.this, event);
}
}
});
}
use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class ConstructorInstancesTracker method obsolete.
public void obsolete() {
if (myNewObjects != null) {
myNewObjects.forEach(ObjectReference::enableCollection);
}
myNewObjects = null;
if (!myIsBackgroundMode || myIsBackgroundTrackingEnabled) {
myBreakpoint.enable();
}
final XDebugSession session = XDebuggerManager.getInstance(myProject).getCurrentSession();
if (session != null) {
final DebugProcess process = DebuggerManager.getInstance(myProject).getDebugProcess(session.getDebugProcess().getProcessHandler());
final MemoryViewDebugProcessData data = process.getUserData(MemoryViewDebugProcessData.KEY);
if (data != null) {
data.getTrackedStacks().release();
}
}
}
use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class ShowInstancesByClassAction method perform.
@Override
protected void perform(XValueNodeImpl node, @NotNull String nodeName, AnActionEvent e) {
final Project project = e.getProject();
if (project != null) {
final XDebugSession debugSession = XDebuggerManager.getInstance(project).getCurrentSession();
final ObjectReference ref = getObjectReference(node);
if (debugSession != null && ref != null) {
final ReferenceType referenceType = ref.referenceType();
new InstancesWindow(debugSession, l -> {
final List<ObjectReference> instances = referenceType.instances(l);
return instances == null ? Collections.emptyList() : instances;
}, referenceType.name()).show();
}
}
}
use of com.intellij.xdebugger.XDebugSession in project intellij-community by JetBrains.
the class DebuggerContextUtil method findNearest.
public static SourcePosition findNearest(@NotNull DebuggerContextImpl context, @NotNull PsiElement psi, @NotNull PsiFile file) {
if (psi instanceof PsiCompiledElement) {
// it makes no sense to compute text range of compiled element
return null;
}
final DebuggerSession session = context.getDebuggerSession();
if (session != null) {
try {
final XDebugSession debugSession = session.getXDebugSession();
if (debugSession != null) {
final XSourcePosition position = debugSession.getCurrentPosition();
Editor editor = ((FileEditorManagerImpl) FileEditorManager.getInstance(file.getProject())).getSelectedTextEditor(true);
//final Editor editor = fileEditor instanceof TextEditorImpl ? ((TextEditorImpl)fileEditor).getEditor() : null;
if (editor != null && position != null && position.getFile().equals(file.getOriginalFile().getVirtualFile())) {
PsiMethod method = PsiTreeUtil.getParentOfType(PositionUtil.getContextElement(context), PsiMethod.class, false);
final Collection<TextRange> ranges = IdentifierHighlighterPass.getUsages(psi, method != null ? method : file, false);
final int breakPointLine = position.getLine();
int bestLine = -1;
int bestOffset = -1;
for (TextRange range : ranges) {
final int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
if (line > bestLine && line < breakPointLine) {
bestLine = line;
bestOffset = range.getStartOffset();
} else if (line == breakPointLine) {
bestOffset = range.getStartOffset();
break;
}
}
if (bestOffset > -1) {
return SourcePosition.createFromOffset(file, bestOffset);
}
}
}
} catch (Exception ignore) {
}
}
return null;
}
Aggregations