mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 318051: Terminating when "Remote shell" process is selected doesn't work
This commit is contained in:
parent
7dcb19c4c1
commit
e25a340938
4 changed files with 141 additions and 13 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: %pluginName
|
Bundle-Name: %pluginName
|
||||||
Bundle-SymbolicName: org.eclipse.cdt.launch.remote;singleton:=true
|
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-Activator: org.eclipse.cdt.internal.launch.remote.Activator
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Require-Bundle: org.eclipse.rse.ui;bundle-version="[3.0.0,4.0.0)",
|
Require-Bundle: org.eclipse.rse.ui;bundle-version="[3.0.0,4.0.0)",
|
||||||
|
|
|
@ -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
|
* 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
|
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
|
||||||
* available at http://www.eclipse.org/legal/epl-v10.html
|
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
* Anna Dushistova (MontaVista) - initial API and implementation
|
* 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) - [314659] moved common methods for DSF and CDI launches to this class
|
||||||
* Anna Dushistova (Mentor Graphics) - changed spaceEscapify visibility
|
* 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;
|
package org.eclipse.cdt.launch.remote;
|
||||||
|
@ -283,6 +284,42 @@ public class RSEHelper {
|
||||||
return p;
|
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)
|
public static String getRemoteHostname(ILaunchConfiguration config)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
IHost currentConnection = getCurrentConnection(config);
|
IHost currentConnection = getCurrentConnection(config);
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,12 +8,21 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Anna Dushistova (Mentor Graphics) - initial API and implementation
|
* Anna Dushistova (Mentor Graphics) - initial API and implementation
|
||||||
* Anna Dushistova (Mentor Graphics) - moved to org.eclipse.cdt.launch.remote.launching
|
* 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;
|
package org.eclipse.cdt.launch.remote.launching;
|
||||||
|
|
||||||
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
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.IGDBLaunchConfigurationConstants;
|
||||||
|
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
|
||||||
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunchDelegate;
|
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.Activator;
|
||||||
import org.eclipse.cdt.internal.launch.remote.Messages;
|
import org.eclipse.cdt.internal.launch.remote.Messages;
|
||||||
import org.eclipse.cdt.launch.remote.IRemoteConnectionConfigurationConstants;
|
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.ILaunchConfiguration;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
import org.eclipse.rse.core.RSECorePlugin;
|
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 {
|
public class RemoteGdbLaunchDelegate extends GdbLaunchDelegate {
|
||||||
|
|
||||||
|
@ -77,13 +88,56 @@ public class RemoteGdbLaunchDelegate extends GdbLaunchDelegate {
|
||||||
if (arguments != null && !arguments.equals("")) //$NON-NLS-1$
|
if (arguments != null && !arguments.equals("")) //$NON-NLS-1$
|
||||||
commandArguments += " " + arguments; //$NON-NLS-1$
|
commandArguments += " " + arguments; //$NON-NLS-1$
|
||||||
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_9);
|
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_9);
|
||||||
remoteShellProcess = RSEHelper.remoteShellExec(config,
|
// extending HostShellProcessAdapter here
|
||||||
prelaunchCmd, gdbserverCommand, commandArguments,
|
final GdbLaunch l = (GdbLaunch)launch;
|
||||||
new SubProgressMonitor(monitor, 5));
|
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,
|
DebugPlugin.newProcess(launch, remoteShellProcess,
|
||||||
Messages.RemoteRunLaunchDelegate_RemoteShell);
|
Messages.RemoteRunLaunchDelegate_RemoteShell);
|
||||||
|
|
||||||
|
|
||||||
// 3. Let debugger know how gdbserver was started on the remote
|
// 3. Let debugger know how gdbserver was started on the remote
|
||||||
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
|
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -18,6 +18,7 @@
|
||||||
* Anna Dushistova (MontaVista) - [267951][remotecdt] Support systemTypes without files subsystem
|
* Anna Dushistova (MontaVista) - [267951][remotecdt] Support systemTypes without files subsystem
|
||||||
* Anna Dushistova (Mentor Graphics) - [314659]Fixed deprecated methods
|
* Anna Dushistova (Mentor Graphics) - [314659]Fixed deprecated methods
|
||||||
* Anna Dushistova (Mentor Graphics) - moved to org.eclipse.cdt.launch.remote.launching
|
* 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;
|
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.debug.core.model.IProcess;
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
import org.eclipse.rse.core.RSECorePlugin;
|
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 {
|
public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
|
||||||
|
|
||||||
|
private ICDISession dsession;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
@ -103,7 +108,7 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
|
||||||
if (debugMode
|
if (debugMode
|
||||||
.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
|
.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
|
||||||
Process remoteShellProcess = null;
|
Process remoteShellProcess = null;
|
||||||
ICDISession dsession = null;
|
dsession = null;
|
||||||
try {
|
try {
|
||||||
// Download the binary to the remote before debugging.
|
// Download the binary to the remote before debugging.
|
||||||
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_2);
|
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_2);
|
||||||
|
@ -127,10 +132,38 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
|
||||||
if (arguments != null && !arguments.equals("")) //$NON-NLS-1$
|
if (arguments != null && !arguments.equals("")) //$NON-NLS-1$
|
||||||
command_arguments += " " + arguments; //$NON-NLS-1$
|
command_arguments += " " + arguments; //$NON-NLS-1$
|
||||||
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_9);
|
monitor.setTaskName(Messages.RemoteRunLaunchDelegate_9);
|
||||||
remoteShellProcess = RSEHelper.remoteShellExec(config,
|
IHostShell remoteShell = null;
|
||||||
prelaunchCmd, gdbserver_command,
|
try {
|
||||||
command_arguments, new SubProgressMonitor(
|
remoteShell = RSEHelper.execCmdInRemoteShell(config, prelaunchCmd,
|
||||||
monitor, 5));
|
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,
|
DebugPlugin.newProcess(launch, remoteShellProcess,
|
||||||
Messages.RemoteRunLaunchDelegate_RemoteShell);
|
Messages.RemoteRunLaunchDelegate_RemoteShell);
|
||||||
|
|
||||||
|
@ -239,4 +272,8 @@ public class RemoteRunLaunchDelegate extends AbstractCLaunchDelegate {
|
||||||
protected String getPluginID() {
|
protected String getPluginID() {
|
||||||
return Activator.PLUGIN_ID;
|
return Activator.PLUGIN_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ICDISession getSession(){
|
||||||
|
return dsession;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue