use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.
the class GroovyPositionManager method createPrepareRequest.
@Override
public ClassPrepareRequest createPrepareRequest(@NotNull final ClassPrepareRequestor requestor, @NotNull final SourcePosition position) throws NoDataException {
if (LOG.isDebugEnabled()) {
LOG.debug("createPrepareRequest: " + position);
}
checkGroovyFile(position);
String qName = getOuterClassName(position);
if (qName != null) {
return myDebugProcess.getRequestsManager().createClassPrepareRequest(requestor, qName);
}
qName = findEnclosingName(position);
if (qName == null)
throw NoDataException.INSTANCE;
ClassPrepareRequestor waitRequestor = new ClassPrepareRequestor() {
@Override
public void processClassPrepare(DebugProcess debuggerProcess, ReferenceType referenceType) {
final CompoundPositionManager positionManager = ((DebugProcessImpl) debuggerProcess).getPositionManager();
if (!positionManager.locationsOfLine(referenceType, position).isEmpty()) {
requestor.processClassPrepare(debuggerProcess, referenceType);
}
}
};
return myDebugProcess.getRequestsManager().createClassPrepareRequest(waitRequestor, qName + "$*");
}
use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.
the class ReloadClassesWorker method reloadClasses.
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);
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.onHotSwapFinished();
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);
}
}
}
use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.
the class SourceCodeChecker method checkAllClasses.
@TestOnly
@SuppressWarnings("UseOfSystemOutOrSystemErr")
private static void checkAllClasses(DebuggerContextImpl debuggerContext) {
DebugProcessImpl process = debuggerContext.getDebugProcess();
@SuppressWarnings("ConstantConditions") VirtualMachine machine = process.getVirtualMachineProxy().getVirtualMachine();
// only default position manager for now
PositionManagerImpl positionManager = new PositionManagerImpl(process);
List<ReferenceType> types = machine.allClasses();
System.out.println("Checking " + types.size() + " classes");
int i = 0;
for (ReferenceType type : types) {
i++;
try {
for (Location loc : type.allLineLocations()) {
SourcePosition position = ReadAction.compute(() -> {
try {
return positionManager.getSourcePosition(loc);
} catch (NoDataException ignore) {
return null;
}
});
if (position == null) {
continue;
}
if (position.getFile() instanceof PsiCompiledFile) {
VirtualFile file = position.getFile().getVirtualFile();
if (file == null || file.getUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY) == null) {
// no mapping - skip the whole file
break;
}
if (DebuggerUtilsEx.bytecodeToSourceLine(position.getFile(), loc.lineNumber()) == -1) {
continue;
}
}
if (check(loc, position, process.getProject()) == ThreeState.NO) {
System.out.println("failed " + type);
break;
}
}
} catch (AbsentInformationException ignored) {
}
}
System.out.println("Done checking");
}
use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.
the class DebuggerTestCase method createLocalProcess.
protected DebuggerSession createLocalProcess(int transport, final JavaParameters javaParameters) throws ExecutionException, InterruptedException, InvocationTargetException {
createBreakpoints(javaParameters.getMainClass());
final DebuggerSession[] debuggerSession = new DebuggerSession[] { null };
DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = transport;
GenericDebuggerRunnerSettings debuggerRunnerSettings = new GenericDebuggerRunnerSettings();
debuggerRunnerSettings.LOCAL = true;
debuggerRunnerSettings.setDebugPort(String.valueOf(DEFAULT_ADDRESS));
ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()).runnerSettings(debuggerRunnerSettings).runProfile(new MockConfiguration()).build();
final JavaCommandLineState javaCommandLineState = new JavaCommandLineState(environment) {
@Override
protected JavaParameters createJavaParameters() {
return javaParameters;
}
@Override
protected GeneralCommandLine createCommandLine() throws ExecutionException {
return getJavaParameters().toCommandLine();
}
};
final RemoteConnection debugParameters = DebuggerManagerImpl.createDebugParameters(javaCommandLineState.getJavaParameters(), debuggerRunnerSettings, true);
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
try {
debuggerSession[0] = attachVirtualMachine(javaCommandLineState, javaCommandLineState.getEnvironment(), debugParameters, false);
} catch (ExecutionException e) {
fail(e.getMessage());
}
}
});
final ProcessHandler processHandler = debuggerSession[0].getProcess().getProcessHandler();
debuggerSession[0].getProcess().addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
print(event.getText(), outputType);
}
});
DebugProcessImpl process = (DebugProcessImpl) DebuggerManagerEx.getInstanceEx(myProject).getDebugProcess(processHandler);
assertNotNull(process);
return debuggerSession[0];
}
use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.
the class MethodBreakpoint method createRequestForSubClasses.
private static void createRequestForSubClasses(@NotNull MethodBreakpointBase breakpoint, @NotNull DebugProcessImpl debugProcess, @NotNull ReferenceType baseType) {
DebuggerManagerThreadImpl.assertIsManagerThread();
RequestManagerImpl requestsManager = debugProcess.getRequestsManager();
ClassPrepareRequest request = requestsManager.createClassPrepareRequest((debuggerProcess, referenceType) -> {
if (instanceOf(referenceType, baseType)) {
createRequestForPreparedClassEmulated(breakpoint, debugProcess, referenceType, false);
}
}, null);
if (request != null) {
requestsManager.registerRequest(breakpoint, request);
request.enable();
// to force reload classes available so far
debugProcess.getVirtualMachineProxy().clearCaches();
}
AtomicReference<ProgressIndicator> indicatorRef = new AtomicReference<>();
ApplicationManager.getApplication().invokeAndWait(() -> indicatorRef.set(new ProgressWindowWithNotification(true, false, debugProcess.getProject(), "Cancel emulation")));
ProgressIndicator indicator = indicatorRef.get();
ProgressManager.getInstance().executeProcessUnderProgress(() -> processPreparedSubTypes(baseType, subType -> createRequestForPreparedClassEmulated(breakpoint, debugProcess, subType, false), indicator), indicator);
if (indicator.isCanceled()) {
breakpoint.disableEmulation();
}
}
Aggregations