From 28f290e9d08aee3205b7788d5167c8af44ff10f5 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 8 Sep 2016 21:23:41 -0400 Subject: [PATCH] Bug 303808: Handle resizing of full GDB console Note that the TextCanvas used by the terminal widget that powers the full console has a default minimum of 4 lines and 80 columns. We could change those if we feel that is not adequate, or if we don't want to have such minimum values at all. This patch leaves the minimum values as they are by default. Conflicts: dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java Change-Id: Iad6339da1726db1102c123c97589f46ae681ffc7 --- .../ui/console/GdbFullCliConsolePage.java | 6 +++- .../ui/console/GdbTerminalConnector.java | 13 +++++++- .../cdt/dsf/gdb/service/GDBBackend_7_12.java | 33 ++++++++++++------- .../cdt/dsf/gdb/service/IGDBBackend.java | 10 ++++++ 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java index 5d3425e1317..22a9a1d3bc5 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch; import org.eclipse.cdt.dsf.gdb.service.IGDBBackend; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.dsf.service.DsfSession; +import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.ui.DebugUITools; @@ -49,6 +50,8 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener private final DsfSession fSession; private final ILaunch fLaunch; + private PTY fGdbPty; + private Composite fMainComposite; private final IDebuggerConsoleView fView; private final IDebuggerConsole fConsole; @@ -194,6 +197,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener if (backend != null) { if (backend.getProcess() != null) { + fGdbPty = backend.getProcessPty(); attachTerminal(backend.getProcess()); } } @@ -204,7 +208,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener } protected void attachTerminal(Process process) { - fTerminalControl.setConnector(new GdbTerminalConnector(process)); + fTerminalControl.setConnector(new GdbTerminalConnector(process, fGdbPty)); if (fTerminalControl instanceof ITerminalControl) { ((ITerminalControl)fTerminalControl).setConnectOnEnterIfClosed(false); ((ITerminalControl)fTerminalControl).setVT100LineWrapping(true); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java index 88e21d58816..d0fb6973724 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.PlatformObject; @@ -26,15 +27,18 @@ import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; */ public class GdbTerminalConnector extends PlatformObject implements ITerminalConnector { + private int fTerminalWidth, fTerminalHeight; private ITerminalControl fControl; private final Process fProcess; + private final PTY fPty; - public GdbTerminalConnector(Process process) { + public GdbTerminalConnector(Process process, PTY pty) { if (process == null) { throw new IllegalArgumentException("Invalid Process"); //$NON-NLS-1$ } fProcess = process; + fPty = pty; } @Override @@ -71,6 +75,13 @@ public class GdbTerminalConnector extends PlatformObject implements ITerminalCon @Override public void setTerminalSize(int newWidth, int newHeight) { + if (newWidth != fTerminalWidth || newHeight != fTerminalHeight) { + fTerminalWidth = newWidth; + fTerminalHeight = newHeight; + if (fPty != null) { + fPty.setTerminalSize(newWidth, newHeight); + } + } } @Override diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend_7_12.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend_7_12.java index f8b6ddb4120..7cd5029946c 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend_7_12.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend_7_12.java @@ -40,8 +40,11 @@ import org.eclipse.osgi.util.NLS; */ public class GDBBackend_7_12 extends GDBBackend { - /** The PTY that is used to enable the full GDB console */ - private PTY fPty; + /** The PTY that is used to create the MI channel */ + private PTY fMIPty; + /** The PTY that is used to create the GDB process in CLI mode */ + private PTY fCLIPty; + /** Indicate that we failed to create a PTY. */ private boolean fPtyFailure; @@ -68,8 +71,8 @@ public class GDBBackend_7_12 extends GDBBackend { } try { - fPty = new PTY(); - fPty.validateSlaveName(); + fMIPty = new PTY(); + fMIPty.validateSlaveName(); // With the PTY the stderr is redirected to the PTY's output stream. // Therefore, return a dummy stream for the error stream. @@ -80,7 +83,7 @@ public class GDBBackend_7_12 extends GDBBackend { } }; } catch (IOException e) { - fPty = null; + fMIPty = null; fPtyFailure = true; GdbPlugin.log(new Status( IStatus.INFO, GdbPlugin.PLUGIN_ID, @@ -90,23 +93,23 @@ public class GDBBackend_7_12 extends GDBBackend { @Override public OutputStream getMIOutputStream() { - if (fPty == null) { + if (fMIPty == null) { return super.getMIOutputStream(); } - return fPty.getOutputStream(); + return fMIPty.getOutputStream(); }; @Override public InputStream getMIInputStream() { - if (fPty == null) { + if (fMIPty == null) { return super.getMIInputStream(); } - return fPty.getInputStream(); + return fMIPty.getInputStream(); }; @Override public InputStream getMIErrorStream() { - if (fPty == null) { + if (fMIPty == null) { return super.getMIErrorStream(); } return fDummyErrorStream; @@ -154,7 +157,7 @@ public class GDBBackend_7_12 extends GDBBackend { "--interpreter", "console", //$NON-NLS-1$ //$NON-NLS-2$ // Now trigger the new console towards our PTY. - "-ex", "new-ui mi " + fPty.getSlaveName(), //$NON-NLS-1$ //$NON-NLS-2$ + "-ex", "new-ui mi " + fMIPty.getSlaveName(), //$NON-NLS-1$ //$NON-NLS-2$ // Now print the version so the user gets that familiar output "-ex", "show version" //$NON-NLS-1$ //$NON-NLS-2$ @@ -180,12 +183,13 @@ public class GDBBackend_7_12 extends GDBBackend { Process proc = null; String[] commandLine = getDebuggerCommandLine(); try { + fCLIPty = new PTY(Mode.TERMINAL); IPath path = getGDBWorkingDirectory(); proc = ProcessFactory.getFactory().exec( commandLine, getGDBLaunch().getLaunchEnvironment(), new File(path != null ? path.toOSString() : ""), //$NON-NLS-1$ - new PTY(Mode.TERMINAL)); + fCLIPty); } catch (IOException e) { String message = "Error while launching command: " + StringUtil.join(commandLine, " "); //$NON-NLS-1$ //$NON-NLS-2$ throw new CoreException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, message, e)); @@ -193,4 +197,9 @@ public class GDBBackend_7_12 extends GDBBackend { return proc; } + + @Override + public PTY getProcessPty() { + return fCLIPty; + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java index 4dccacc137d..c275fa1e3df 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBBackend.java @@ -16,6 +16,7 @@ import java.util.Properties; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.mi.service.IMIBackend; +import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -173,4 +174,13 @@ public interface IGDBBackend extends IMIBackend { default Process getProcess() { throw new RuntimeException(); } + + /** + * Returns the PTY used when starting the GDB process. + * Can be null if no PTY was used. + * @since 5.1 + */ + default PTY getProcessPty() { + return null; + } }