summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Dushistova2012-01-24 11:10:50 (EST)
committer Marc Khouzam2012-01-24 11:10:50 (EST)
commite25a3409383dc97f68cd39ac5a6d5dfac36402fa (patch)
tree2117b85f55258a3e61bba3096d310d9072710638
parent7dcb19c4c143fc9bdf6154e411d3c452c5c62afd (diff)
downloadorg.eclipse.cdt-e25a3409383dc97f68cd39ac5a6d5dfac36402fa.zip
org.eclipse.cdt-e25a3409383dc97f68cd39ac5a6d5dfac36402fa.tar.gz
org.eclipse.cdt-e25a3409383dc97f68cd39ac5a6d5dfac36402fa.tar.bz2
Bug 318051: Terminating when "Remote shell" process is selected doesn't work
-rw-r--r--cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF2
-rw-r--r--cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java39
-rw-r--r--cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java64
-rw-r--r--cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java49
4 files changed, 141 insertions, 13 deletions
diff --git a/cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF b/cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF
index dda9260..2f7d271 100644
--- a/cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF
+++ b/cross/org.eclipse.cdt.launch.remote/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.launch.remote;singleton:=true
-Bundle-Version: 2.3.0.qualifier
+Bundle-Version: 2.4.0.qualifier
Bundle-Activator: org.eclipse.cdt.internal.launch.remote.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.rse.ui;bundle-version="[3.0.0,4.0.0)",
diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java
index 949bcc3..20198fc 100644
--- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java
+++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/RSEHelper.java
@@ -1,5 +1,5 @@
/********************************************************************************
- * Copyright (c) 2009, 2010 MontaVista Software, Inc. and others.
+ * Copyright (c) 2009, 2012 MontaVista Software, Inc. and others.
* 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
@@ -8,6 +8,7 @@
* Anna Dushistova (MontaVista) - initial API and implementation
* Anna Dushistova (Mentor Graphics) - [314659] moved common methods for DSF and CDI launches to this class
* Anna Dushistova (Mentor Graphics) - changed spaceEscapify visibility
+ * Anna Dushistova (MontaVista) - [318051][remote debug] Terminating when "Remote shell" process is selected doesn't work
********************************************************************************/
package org.eclipse.cdt.launch.remote;
@@ -283,6 +284,42 @@ public class RSEHelper {
return p;
}
+ public static IHostShell execCmdInRemoteShell(ILaunchConfiguration config,
+ String prelaunchCmd, String remoteCommandPath, String arguments,
+ IProgressMonitor monitor) throws Exception {
+ // The exit command is called to force the remote shell to close after
+ // our command
+ // is executed. This is to prevent a running process at the end of the
+ // debug session.
+ // See Bug 158786.
+ monitor.beginTask(NLS.bind(Messages.RemoteRunLaunchDelegate_8,
+ remoteCommandPath, arguments), 10);
+ String realRemoteCommand = arguments == null ? spaceEscapify(remoteCommandPath)
+ : spaceEscapify(remoteCommandPath) + " " + arguments; //$NON-NLS-1$
+
+ String remoteCommand = realRemoteCommand + CMD_DELIMITER + EXIT_CMD;
+
+ if (!prelaunchCmd.trim().equals("")) //$NON-NLS-1$
+ remoteCommand = prelaunchCmd + CMD_DELIMITER + remoteCommand;
+
+ IShellService shellService = null;
+ shellService = (IShellService) RSEHelper
+ .getConnectedRemoteShellService(getCurrentConnection(config),
+ new SubProgressMonitor(monitor, 7));
+
+ // This is necessary because runCommand does not actually run the
+ // command right now.
+ String env[] = new String[0];
+ IHostShell hostShell = null;
+ if (shellService != null) {
+ hostShell = shellService.launchShell(
+ "", env, new SubProgressMonitor(monitor, 3)); //$NON-NLS-1$
+ hostShell.writeToShell(remoteCommand);
+ }
+ monitor.done();
+ return hostShell;
+ }
+
public static String getRemoteHostname(ILaunchConfiguration config)
throws CoreException {
IHost currentConnection = getCurrentConnection(config);
diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java
index b57b929..600eac3 100644
--- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java
+++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteGdbLaunchDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Mentor Graphics Corporation and others.
+ * Copyright (c) 2010, 2012 Mentor Graphics Corporation 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
@@ -8,12 +8,21 @@
* Contributors:
* Anna Dushistova (Mentor Graphics) - initial API and implementation
* Anna Dushistova (Mentor Graphics) - moved to org.eclipse.cdt.launch.remote.launching
+ * Anna Dushistova (MontaVista) - [318051][remote debug] Terminating when "Remote shell" process is selected doesn't work
*******************************************************************************/
package org.eclipse.cdt.launch.remote.launching;
+import java.util.concurrent.RejectedExecutionException;
+
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
+import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
+import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor;
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
+import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunchDelegate;
+import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
+import org.eclipse.cdt.dsf.service.DsfServicesTracker;
+import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.internal.launch.remote.Activator;
import org.eclipse.cdt.internal.launch.remote.Messages;
import org.eclipse.cdt.launch.remote.IRemoteConnectionConfigurationConstants;
@@ -30,6 +39,8 @@ import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.rse.core.RSECorePlugin;
+import org.eclipse.rse.services.shells.HostShellProcessAdapter;
+import org.eclipse.rse.services.shells.IHostShell;
public class RemoteGdbLaunchDelegate extends GdbLaunchDelegate {
@@ -77,13 +88,56 @@ public class RemoteGdbLaunchDelegate extends GdbLaunchDelegate {
if (arguments != null && !arguments.equals("")) //$NON-NLS-1$
commandArguments += " " + arguments; //$NON-NLS-1$
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_9);
- remoteShellProcess = RSEHelper.remoteShellExec(config,
- prelaunchCmd, gdbserverCommand, commandArguments,
- new SubProgressMonitor(monitor, 5));
+ // extending HostShellProcessAdapter here
+ final GdbLaunch l = (GdbLaunch)launch;
+ IHostShell remoteShell = null;
+ try {
+ remoteShell = RSEHelper.execCmdInRemoteShell(config, prelaunchCmd,
+ gdbserverCommand, commandArguments,
+ new SubProgressMonitor(monitor, 5));
+ } catch (Exception e1) {
+ RSEHelper.abort(e1.getMessage(), e1,
+ ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+
+ }
+ try {
+ remoteShellProcess = new HostShellProcessAdapter(remoteShell) {
+
+ @Override
+ public synchronized void destroy() {
+ final DsfSession session = l.getSession();
+ if (session != null) {
+ try {
+ session.getExecutor().execute(new DsfRunnable() {
+ public void run() {
+ DsfServicesTracker tracker = new DsfServicesTracker(
+ Activator.getBundleContext(),
+ session.getId());
+ IGDBControl control = tracker
+ .getService(IGDBControl.class);
+ if (control != null) {
+ control.terminate(new ImmediateRequestMonitor());
+ }
+ tracker.dispose();
+ }
+ });
+ } catch (RejectedExecutionException e) {
+ // Session disposed.
+ }
+ }
+ super.destroy();
+ }
+ };
+ } catch (Exception e) {
+ if (remoteShellProcess != null) {
+ remoteShellProcess.destroy();
+ }
+ RSEHelper.abort(Messages.RemoteRunLaunchDelegate_7, e,
+ ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+ }
DebugPlugin.newProcess(launch, remoteShellProcess,
Messages.RemoteRunLaunchDelegate_RemoteShell);
-
// 3. Let debugger know how gdbserver was started on the remote
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
diff --git a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java
index 1128c7c..7feb832 100644
--- a/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java
+++ b/cross/org.eclipse.cdt.launch.remote/src/org/eclipse/cdt/launch/remote/launching/RemoteRunLaunchDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 PalmSource, Inc. and others.
+ * Copyright (c) 2006, 2012 PalmSource, Inc. 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
@@ -18,6 +18,7 @@
* Anna Dushistova (MontaVista) - [267951][remotecdt] Support systemTypes without files subsystem
* Anna Dushistova (Mentor Graphics) - [314659]Fixed deprecated methods
* Anna Dushistova (Mentor Graphics) - moved to org.eclipse.cdt.launch.remote.launching
+ * Anna Dushistova (MontaVista) - [318051][remote debug] Terminating when "Remote shell" process is selected doesn't work
*******************************************************************************/
package org.eclipse.cdt.launch.remote.launching;
@@ -53,9 +54,13 @@ import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.osgi.util.NLS;
import org.eclipse.rse.core.RSECorePlugin;
+import org.eclipse.rse.services.shells.HostShellProcessAdapter;
+import org.eclipse.rse.services.shells.IHostShell;
public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
+ private ICDISession dsession;
+
/*
* (non-Javadoc)
*
@@ -103,7 +108,7 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
if (debugMode
.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
Process remoteShellProcess = null;
- ICDISession dsession = null;
+ dsession = null;
try {
// Download the binary to the remote before debugging.
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_2);
@@ -127,10 +132,38 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
if (arguments != null && !arguments.equals("")) //$NON-NLS-1$
command_arguments += " " + arguments; //$NON-NLS-1$
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_9);
- remoteShellProcess = RSEHelper.remoteShellExec(config,
- prelaunchCmd, gdbserver_command,
- command_arguments, new SubProgressMonitor(
- monitor, 5));
+ IHostShell remoteShell = null;
+ try {
+ remoteShell = RSEHelper.execCmdInRemoteShell(config, prelaunchCmd,
+ gdbserver_command, command_arguments,
+ new SubProgressMonitor(monitor, 5));
+ } catch (Exception e1) {
+ RSEHelper.abort(e1.getMessage(), e1,
+ ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+ }
+
+ try {
+ remoteShellProcess = new HostShellProcessAdapter(remoteShell) {
+
+ @Override
+ public synchronized void destroy() {
+ ICDISession session = getSession();
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (CDIException e) {
+ }
+ }
+ super.destroy();
+ }
+ };
+ } catch (Exception e) {
+ if (remoteShellProcess != null) {
+ remoteShellProcess.destroy();
+ }
+ RSEHelper.abort(Messages.RemoteRunLaunchDelegate_7, e,
+ ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
+ }
DebugPlugin.newProcess(launch, remoteShellProcess,
Messages.RemoteRunLaunchDelegate_RemoteShell);
@@ -239,4 +272,8 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
protected String getPluginID() {
return Activator.PLUGIN_ID;
}
+
+ ICDISession getSession(){
+ return dsession;
+ }
}