diff options
author | Marc Khouzam | 2016-10-14 19:58:23 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-11-14 20:30:23 +0000 |
commit | 39c781f81a1687260024c03dc30b8c92e19c327d (patch) | |
tree | a5a9a73307f16e870e5d0330694af33baba969c6 /core/org.eclipse.cdt.core.native | |
parent | e8480ca0f8c72f1eb1a7d31f6c48789eef1bf9ba (diff) | |
download | org.eclipse.cdt-39c781f81a1687260024c03dc30b8c92e19c327d.tar.gz org.eclipse.cdt-39c781f81a1687260024c03dc30b8c92e19c327d.tar.xz org.eclipse.cdt-39c781f81a1687260024c03dc30b8c92e19c327d.zip |
Bug 497166: Support the user using the 'run' command in the gdb console
This commit introduces a PersistentPTY. By using it, we now allow the
user to restart the process from the GDB console (by pressing 'run').
In this case, the I/O will continue using the PersistentPTY.
Previously, the PTY would have been closed, and GDB would fail to
restart the process because it would fail to use the closed PTY.
Change-Id: I395b402e297a2043af8fce33df163eddef9e6c7a
Diffstat (limited to 'core/org.eclipse.cdt.core.native')
3 files changed, 106 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF index d5dc688af3e..94f7b0d29f4 100644 --- a/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core.native;singleton:=true -Bundle-Version: 5.9.0.qualifier +Bundle-Version: 5.10.0.qualifier Bundle-Activator: org.eclipse.cdt.internal.core.natives.CNativePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core.native/pom.xml b/core/org.eclipse.cdt.core.native/pom.xml index 249c4e3223d..46091e422e6 100644 --- a/core/org.eclipse.cdt.core.native/pom.xml +++ b/core/org.eclipse.cdt.core.native/pom.xml @@ -11,7 +11,7 @@ <relativePath>../../pom.xml</relativePath> </parent> - <version>5.9.0-SNAPSHOT</version> + <version>5.10.0-SNAPSHOT</version> <artifactId>org.eclipse.cdt.core.native</artifactId> <packaging>eclipse-plugin</packaging> </project> diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/pty/PersistentPTY.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/pty/PersistentPTY.java new file mode 100644 index 00000000000..9780d405853 --- /dev/null +++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/pty/PersistentPTY.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2016 Ericsson and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.cdt.utils.pty; + +import java.io.IOException; + +import org.eclipse.core.runtime.Platform; + +/** + * A type of PTY that is persistent. This means that closing + * its streams (e.g., once the connection to the process is lost) + * will not close the PTY or the streams; instead, they will + * remain open to be used again by reconnecting to the streams. + * {@link PersistentPTY#closeStreams()} must be called to properly + * cleanup the streams once the PersistentPTY is known not be needed + * anymore. + * + * @since 5.10 + */ +public class PersistentPTY extends PTY { + + private class PersistentPTYInputStream extends PTYInputStream { + public PersistentPTYInputStream(MasterFD fd) { + super(fd); + } + + @Override + public void close() throws IOException { + // This is the change to bring persistence. + // Don't actually close the stream. + } + + public void realClose() throws IOException { + // This method should be called to actually close + // the stream once we know it won't be needed anymore + super.close(); + } + + @Override + protected void finalize() throws IOException { + realClose(); + } + } + + private class PersistentPTYOutputStream extends PTYOutputStream { + public PersistentPTYOutputStream(MasterFD fd, boolean sendEotBeforeClose) { + super(fd, sendEotBeforeClose); + } + + @Override + public void close() throws IOException { + // This is the change to bring persistence. + // Don't actually close the stream. + } + + public void realClose() throws IOException { + // This method should be called to actually close + // the stream once we know it won't be needed anymore + super.close(); + } + + @Override + protected void finalize() throws IOException { + realClose(); + } + } + + final PersistentPTYInputStream in2; + final PersistentPTYOutputStream out2; + + public PersistentPTY() throws IOException { + this(Mode.CONSOLE); + } + + public PersistentPTY(Mode mode) throws IOException { + super(mode); + in2 = new PersistentPTYInputStream(new MasterFD()); + out2 = new PersistentPTYOutputStream(new MasterFD(), !Platform.OS_WIN32.equals(Platform.getOS())); + } + + @Override + public PTYInputStream getInputStream() { + return in2; + } + + @Override + public PTYOutputStream getOutputStream() { + return out2; + } + + /** + * This method must be called once the PersistentPTY is + * no longer needed, so that its streams can be closed. + */ + public void closeStreams() throws IOException { + in2.realClose(); + out2.realClose(); + } +} |