fix: GDB warning spam fix

This commit is contained in:
FalsePattern 2024-10-25 13:33:43 +02:00
parent 7f30c1aea4
commit 18adeffcce
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
3 changed files with 85 additions and 53 deletions

View file

@ -28,6 +28,7 @@ Changelog structure reference:
- The process execution pipeline is now fully asynchronous
- Debugger
- Zig compilation will no longer cause random IDE freezes
- Debugging with GDB no longer causes random internal IDE warnings
- LSP
- Rare error when checking LSP presence

View file

@ -31,12 +31,11 @@ public interface ZigDebuggerDriverConfigurationProvider {
ExtensionPointName<ZigDebuggerDriverConfigurationProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.falsepattern.zigbrains.debuggerDriverProvider");
@SuppressWarnings("unchecked")
static @NotNull Stream<DebuggerDriverConfiguration> findDebuggerConfigurations(Project project, boolean isElevated, boolean emulateTerminal) {
return (Stream<DebuggerDriverConfiguration>) EXTENSION_POINT_NAME.getExtensionList()
.stream()
.map(it -> it.getDebuggerConfiguration(project, isElevated, emulateTerminal))
.filter(Objects::nonNull)
.map((Function<? super Supplier<DebuggerDriverConfiguration>, ?>) Supplier::get);
static @NotNull Stream<Supplier<DebuggerDriverConfiguration>> findDebuggerConfigurations(Project project, boolean isElevated, boolean emulateTerminal) {
return EXTENSION_POINT_NAME.getExtensionList()
.stream()
.map(it -> it.getDebuggerConfiguration(project, isElevated, emulateTerminal))
.filter(Objects::nonNull);
}
@Nullable Supplier<DebuggerDriverConfiguration> getDebuggerConfiguration(Project project, boolean isElevated, boolean emulateTerminal);

View file

@ -33,6 +33,7 @@ import com.intellij.execution.runners.RunContentBuilder;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.intellij.xdebugger.XDebugProcess;
import com.intellij.xdebugger.XDebugProcessStarter;
import com.intellij.xdebugger.XDebugSession;
@ -44,65 +45,96 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.concurrency.AsyncPromise;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public abstract class ZigDebugRunnerBase<ProfileState extends ProfileStateBase<?>> extends ZigProgramRunnerBase<ProfileState> {
public ZigDebugRunnerBase() {
super(DefaultDebugExecutor.EXECUTOR_ID);
}
private boolean doExecuteAsyncWithDriver(ProfileState state,
AbstractZigToolchain toolchain,
ExecutionEnvironment environment,
AsyncPromise<@Nullable RunContentDescriptor> runContentDescriptorPromise,
DebuggerDriverConfiguration debuggerDriver) throws ExecutionException {
ZigDebugParametersBase<ProfileState> runParameters = getDebugParameters(state, environment, debuggerDriver, toolchain);
if (runParameters == null) {
return false;
}
val console = state.getConsoleBuilder().getConsole();
if (runParameters instanceof PreLaunchAware pla) {
val listener = new PreLaunchProcessListener(console);
pla.preLaunch(listener);
if (listener.isBuildFailed()) {
val executionResult = new DefaultExecutionResult(console, listener.getProcessHandler());
ApplicationManager.getApplication().invokeLater(() -> {
val runContentBuilder = new RunContentBuilder(executionResult, environment);
val runContentDescriptor = runContentBuilder.showRunContent(null);
runContentDescriptorPromise.setResult(runContentDescriptor);
});
return true;
}
}
ApplicationManager.getApplication().invokeLater(() -> {
val debuggerManager = XDebuggerManager.getInstance(environment.getProject());
try {
val xDebugSession = debuggerManager.startSession(environment, new XDebugProcessStarter() {
@Override
public @NotNull XDebugProcess start(@NotNull XDebugSession session)
throws ExecutionException {
val project = session.getProject();
val textConsoleBuilder = new SharedConsoleBuilder(console);
val debugProcess = new ZigLocalDebugProcess(runParameters, session, textConsoleBuilder);
ProcessTerminatedListener.attach(debugProcess.getProcessHandler(), project);
debugProcess.start();
return debugProcess;
}
});
runContentDescriptorPromise.setResult(xDebugSession.getRunContentDescriptor());
} catch (ExecutionException e) {
runContentDescriptorPromise.setError(e);
}
});
return true;
}
private void doExecuteAsyncFetchNextDriver(ProfileState state,
AbstractZigToolchain toolchain,
ExecutionEnvironment environment,
AsyncPromise<@Nullable RunContentDescriptor> runContentDescriptorPromise,
List<Supplier<DebuggerDriverConfiguration>> drivers) {
if (drivers.isEmpty()) {
runContentDescriptorPromise.setResult(null);
return;
}
val driverSupplier = drivers.removeFirst();
val driver = driverSupplier.get();
AppExecutorUtil.getAppExecutorService().execute(() -> {
try {
if (!doExecuteAsyncWithDriver(state, toolchain, environment, runContentDescriptorPromise, driver)) {
ApplicationManager.getApplication().invokeLater(() -> doExecuteAsyncFetchNextDriver(state, toolchain, environment, runContentDescriptorPromise, drivers));
}
} catch (ExecutionException e) {
runContentDescriptorPromise.setError(e);
}
});
}
@Override
protected void doExecuteAsync(ProfileState state,
AbstractZigToolchain toolchain,
ExecutionEnvironment environment,
AsyncPromise<@Nullable RunContentDescriptor> runContentDescriptorPromise)
throws ExecutionException {
AsyncPromise<@Nullable RunContentDescriptor> runContentDescriptorPromise) {
val project = environment.getProject();
val drivers = ZigDebuggerDriverConfigurationProvider.findDebuggerConfigurations(project, false, false)
.toList();
.collect(Collectors.toCollection(ArrayList::new));
for (val debuggerDriver: drivers) {
if (debuggerDriver == null)
continue;
ZigDebugParametersBase<ProfileState> runParameters = getDebugParameters(state, environment, debuggerDriver, toolchain);
if (runParameters == null) {
continue;
}
val console = state.getConsoleBuilder().getConsole();
if (runParameters instanceof PreLaunchAware pla) {
val listener = new PreLaunchProcessListener(console);
pla.preLaunch(listener);
if (listener.isBuildFailed()) {
val executionResult = new DefaultExecutionResult(console, listener.getProcessHandler());
ApplicationManager.getApplication().invokeLater(() -> {
val runContentBuilder = new RunContentBuilder(executionResult, environment);
val runContentDescriptor = runContentBuilder.showRunContent(null);
runContentDescriptorPromise.setResult(runContentDescriptor);
});
return;
}
}
ApplicationManager.getApplication().invokeLater(() -> {
val debuggerManager = XDebuggerManager.getInstance(environment.getProject());
try {
val xDebugSession = debuggerManager.startSession(environment, new XDebugProcessStarter() {
@Override
public @NotNull XDebugProcess start(@NotNull XDebugSession session)
throws ExecutionException {
val project = session.getProject();
val textConsoleBuilder = new SharedConsoleBuilder(console);
val debugProcess = new ZigLocalDebugProcess(runParameters, session, textConsoleBuilder);
ProcessTerminatedListener.attach(debugProcess.getProcessHandler(), project);
debugProcess.start();
return debugProcess;
}
});
runContentDescriptorPromise.setResult(xDebugSession.getRunContentDescriptor());
} catch (ExecutionException e) {
runContentDescriptorPromise.setError(e);
}
});
return;
}
runContentDescriptorPromise.setResult(null);
ApplicationManager.getApplication()
.invokeLater(() -> doExecuteAsyncFetchNextDriver(state, toolchain, environment, runContentDescriptorPromise, drivers));
}
@Override