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 - The process execution pipeline is now fully asynchronous
- Debugger - Debugger
- Zig compilation will no longer cause random IDE freezes - Zig compilation will no longer cause random IDE freezes
- Debugging with GDB no longer causes random internal IDE warnings
- LSP - LSP
- Rare error when checking LSP presence - 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"); ExtensionPointName<ZigDebuggerDriverConfigurationProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.falsepattern.zigbrains.debuggerDriverProvider");
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
static @NotNull Stream<DebuggerDriverConfiguration> findDebuggerConfigurations(Project project, boolean isElevated, boolean emulateTerminal) { static @NotNull Stream<Supplier<DebuggerDriverConfiguration>> findDebuggerConfigurations(Project project, boolean isElevated, boolean emulateTerminal) {
return (Stream<DebuggerDriverConfiguration>) EXTENSION_POINT_NAME.getExtensionList() return EXTENSION_POINT_NAME.getExtensionList()
.stream() .stream()
.map(it -> it.getDebuggerConfiguration(project, isElevated, emulateTerminal)) .map(it -> it.getDebuggerConfiguration(project, isElevated, emulateTerminal))
.filter(Objects::nonNull) .filter(Objects::nonNull);
.map((Function<? super Supplier<DebuggerDriverConfiguration>, ?>) Supplier::get);
} }
@Nullable Supplier<DebuggerDriverConfiguration> getDebuggerConfiguration(Project project, boolean isElevated, boolean emulateTerminal); @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.ConsoleView;
import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.intellij.xdebugger.XDebugProcess; import com.intellij.xdebugger.XDebugProcess;
import com.intellij.xdebugger.XDebugProcessStarter; import com.intellij.xdebugger.XDebugProcessStarter;
import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XDebugSession;
@ -44,27 +45,24 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.concurrency.AsyncPromise; 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 abstract class ZigDebugRunnerBase<ProfileState extends ProfileStateBase<?>> extends ZigProgramRunnerBase<ProfileState> {
public ZigDebugRunnerBase() { public ZigDebugRunnerBase() {
super(DefaultDebugExecutor.EXECUTOR_ID); super(DefaultDebugExecutor.EXECUTOR_ID);
} }
@Override private boolean doExecuteAsyncWithDriver(ProfileState state,
protected void doExecuteAsync(ProfileState state,
AbstractZigToolchain toolchain, AbstractZigToolchain toolchain,
ExecutionEnvironment environment, ExecutionEnvironment environment,
AsyncPromise<@Nullable RunContentDescriptor> runContentDescriptorPromise) AsyncPromise<@Nullable RunContentDescriptor> runContentDescriptorPromise,
throws ExecutionException { DebuggerDriverConfiguration debuggerDriver) throws ExecutionException {
val project = environment.getProject();
val drivers = ZigDebuggerDriverConfigurationProvider.findDebuggerConfigurations(project, false, false)
.toList();
for (val debuggerDriver: drivers) {
if (debuggerDriver == null)
continue;
ZigDebugParametersBase<ProfileState> runParameters = getDebugParameters(state, environment, debuggerDriver, toolchain); ZigDebugParametersBase<ProfileState> runParameters = getDebugParameters(state, environment, debuggerDriver, toolchain);
if (runParameters == null) { if (runParameters == null) {
continue; return false;
} }
val console = state.getConsoleBuilder().getConsole(); val console = state.getConsoleBuilder().getConsole();
if (runParameters instanceof PreLaunchAware pla) { if (runParameters instanceof PreLaunchAware pla) {
@ -77,7 +75,7 @@ public abstract class ZigDebugRunnerBase<ProfileState extends ProfileStateBase<?
val runContentDescriptor = runContentBuilder.showRunContent(null); val runContentDescriptor = runContentBuilder.showRunContent(null);
runContentDescriptorPromise.setResult(runContentDescriptor); runContentDescriptorPromise.setResult(runContentDescriptor);
}); });
return; return true;
} }
} }
ApplicationManager.getApplication().invokeLater(() -> { ApplicationManager.getApplication().invokeLater(() -> {
@ -100,9 +98,43 @@ public abstract class ZigDebugRunnerBase<ProfileState extends ProfileStateBase<?
runContentDescriptorPromise.setError(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; return;
} }
runContentDescriptorPromise.setResult(null);
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) {
val project = environment.getProject();
val drivers = ZigDebuggerDriverConfigurationProvider.findDebuggerConfigurations(project, false, false)
.collect(Collectors.toCollection(ArrayList::new));
ApplicationManager.getApplication()
.invokeLater(() -> doExecuteAsyncFetchNextDriver(state, toolchain, environment, runContentDescriptorPromise, drivers));
} }
@Override @Override