From 462dc7afcea7e5844762e15908fc52b59fd1c748 Mon Sep 17 00:00:00 2001 From: Tobias Schwarz Date: Tue, 8 May 2012 14:17:34 +0200 Subject: Target Explorer: ADD attach debugger on remote application debug --- .../te/launch/core/steps/AbstractLaunchStep.java | 11 ++++ .../org.eclipse.tcf.te.launch.ui/plugin.xml | 4 +- .../ui/internal/LaunchNodePropertyTester.java | 8 +-- .../org.eclipse.tcf.te.tcf.launch.core/plugin.xml | 15 ++++-- .../interfaces/IRemoteAppLaunchAttributes.java | 2 + .../te/tcf/launch/core/services/DebugService.java | 55 ++++++++++++++----- .../tcf/launch/core/steps/AttachDebuggerStep.java | 61 ++++++++++++++++++++++ .../tcf/launch/core/steps/LaunchProcessStep.java | 19 ++++++- 8 files changed, 150 insertions(+), 25 deletions(-) create mode 100644 target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/AttachDebuggerStep.java (limited to 'target_explorer') diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/AbstractLaunchStep.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/AbstractLaunchStep.java index 6d4daf08f..18c1c5d7f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/AbstractLaunchStep.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/AbstractLaunchStep.java @@ -34,6 +34,17 @@ public abstract class AbstractLaunchStep extends AbstractStep { return (ILaunch)context.getAdapter(ILaunch.class); } + /** + * Returns the current launch mode. + * + * @param context The step context. + * @return The launch mode or null. + */ + protected String getLaunchMode(IStepContext context) { + ILaunch launch = getLaunch(context); + return launch != null ? launch.getLaunchMode() : null; + } + /** * Returns the active launch context model node that is currently used. * diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/plugin.xml index 2d249bd7e..38a3aed8e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/plugin.xml @@ -586,7 +586,7 @@ ifEmpty="false"> - + @@ -610,7 +610,7 @@ ifEmpty="false"> - + diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/internal/LaunchNodePropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/internal/LaunchNodePropertyTester.java index 079f75bb8..cca15c2c2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/internal/LaunchNodePropertyTester.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.ui/src/org/eclipse/tcf/te/launch/ui/internal/LaunchNodePropertyTester.java @@ -31,8 +31,7 @@ public class LaunchNodePropertyTester extends PropertyTester { LaunchNode node = (LaunchNode)receiver; if (property.equals("isLaunchConfigType")) { //$NON-NLS-1$ if (LaunchNode.TYPE_LAUNCH_CONFIG_TYPE.equals(node.getType())) { - boolean isValue = expectedValue == null || expectedValue.equals(node.getLaunchConfigurationType().getIdentifier()); - return isValue; + return expectedValue == null || expectedValue.equals(node.getLaunchConfigurationType().getIdentifier()); } } else if (property.equals("isLaunchConfig")) { //$NON-NLS-1$ @@ -50,7 +49,10 @@ public class LaunchNodePropertyTester extends PropertyTester { } } else if (property.equals("isValidLaunchConfig")) { //$NON-NLS-1$ - return true; + if (expectedValue instanceof String) { + return node.isValidFor((String)expectedValue); + } + return node.isValidFor(null); } } return false; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml index a1c88bf46..b7a3cbea8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml @@ -86,15 +86,14 @@ - + - - - + + + + + + create a new one lc = createNewConfig(peer); @@ -120,7 +124,7 @@ public class DebugService extends AbstractService implements IDebugService { try { // Attach the launch listener to wait firing the callback until // the TCFLaunch got connect - TCFLaunch.addListener(new TCFLaunch.LaunchListener() { + final TCFLaunch.LaunchListener listener = new TCFLaunch.LaunchListener() { @Override public void onProcessStreamError(TCFLaunch launch, String process_id, int stream_id, Exception error, int lost_size) {} @Override @@ -139,7 +143,18 @@ public class DebugService extends AbstractService implements IDebugService { callback.done(DebugService.this, Status.OK_STATUS); } } - }); + }; + if (Protocol.isDispatchThread()) { + TCFLaunch.addListener(listener); + } + else { + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + TCFLaunch.addListener(listener); + } + }); + } // Execute the launch configuration l = lc.launch(ILaunchManager.DEBUG_MODE, new NullProgressMonitor(), false, true); @@ -178,8 +193,12 @@ public class DebugService extends AbstractService implements IDebugService { peerId.set(peer.getID()); } }; - if (Protocol.isDispatchThread()) runnable.run(); - else Protocol.invokeAndWait(runnable); + if (Protocol.isDispatchThread()) { + runnable.run(); + } + else { + Protocol.invokeAndWait(runnable); + } // Get the launch manager ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager(); @@ -198,7 +217,9 @@ public class DebugService extends AbstractService implements IDebugService { // Save the working copy lc = wc.doSave(); } catch (CoreException e) { - if (Platform.inDebugMode()) e.printStackTrace(); + if (Platform.inDebugMode()) { + e.printStackTrace(); + } } } @@ -226,8 +247,12 @@ public class DebugService extends AbstractService implements IDebugService { peerId.set(peer.getID()); } }; - if (Protocol.isDispatchThread()) runnable.run(); - else Protocol.invokeAndWait(runnable); + if (Protocol.isDispatchThread()) { + runnable.run(); + } + else { + Protocol.invokeAndWait(runnable); + } // Get the launch manager ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager(); @@ -239,13 +264,15 @@ public class DebugService extends AbstractService implements IDebugService { ILaunchConfiguration[] candidates = lm.getLaunchConfigurations(lct); for (ILaunchConfiguration candidate : candidates) { // If the peer id is matching, it is a valid candidate - String lcPeerId = candidate.getAttribute(TCFLaunchDelegate.ATTR_PEER_ID, (String)null); - if (lcPeerId != null && lcPeerId.equals(peerId.get())) { - configs.add(candidate); - } + String lcPeerId = candidate.getAttribute(TCFLaunchDelegate.ATTR_PEER_ID, (String)null); + if (lcPeerId != null && lcPeerId.equals(peerId.get())) { + configs.add(candidate); + } } } catch (CoreException e) { - if (Platform.inDebugMode()) e.printStackTrace(); + if (Platform.inDebugMode()) { + e.printStackTrace(); + } } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/AttachDebuggerStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/AttachDebuggerStep.java new file mode 100644 index 000000000..673cac066 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/AttachDebuggerStep.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, 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 http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.launch.core.steps; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; +import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; +import org.eclipse.tcf.te.runtime.services.ServiceManager; +import org.eclipse.tcf.te.runtime.services.interfaces.IDebugService; +import org.eclipse.tcf.te.runtime.stepper.StepperAttributeUtil; +import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; +import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; +import org.eclipse.tcf.te.tcf.launch.core.activator.CoreBundleActivator; +import org.eclipse.tcf.te.tcf.launch.core.interfaces.IRemoteAppLaunchAttributes; + +/** + * Launch process step implementation. + */ +public class AttachDebuggerStep extends AbstractTcfLaunchStep { + + /** + * Constructor. + */ + public AttachDebuggerStep() { + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IExtendedStep#validateExecute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public void validateExecute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor) throws CoreException { + if (StepperAttributeUtil.getProperty(IRemoteAppLaunchAttributes.ATTR_PROCESS_CONTEXT, fullQualifiedId, data) == null) { + throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "missing process context")); //$NON-NLS-1$ + } + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#execute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) + */ + @Override + public void execute(IStepContext context, final IPropertiesContainer data, final IFullQualifiedId fullQualifiedId, IProgressMonitor monitor, final ICallback callback) { + IDebugService dbgService = ServiceManager.getInstance().getService(getActivePeerModel(data), IDebugService.class, false); + if (dbgService != null) { + dbgService.attach(getActivePeerModel(data), new PropertiesContainer(), callback); + } + else { + callback.done(this, new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "missing debugger service")); //$NON-NLS-1$ + } + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java index 638fd6712..177430c9f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/steps/LaunchProcessStep.java @@ -16,8 +16,11 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.tcf.services.IProcesses; import org.eclipse.tcf.te.core.utils.text.StringUtil; import org.eclipse.tcf.te.launch.core.persistence.DefaultPersistenceDelegate; +import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; @@ -62,7 +65,7 @@ public class LaunchProcessStep extends AbstractTcfLaunchStep { * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#execute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) */ @Override - public void execute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor, final ICallback callback) { + public void execute(IStepContext context, final IPropertiesContainer data, final IFullQualifiedId fullQualifiedId, IProgressMonitor monitor, final ICallback callback) { // Construct the launcher object ProcessLauncher launcher = new ProcessLauncher(); @@ -76,10 +79,22 @@ public class LaunchProcessStep extends AbstractTcfLaunchStep { launchAttributes.put(ITerminalsConnectorConstants.PROP_LOCAL_ECHO, Boolean.FALSE); launchAttributes.put(IProcessLauncher.PROP_PROCESS_ASSOCIATE_CONSOLE, Boolean.TRUE); + if (ILaunchManager.DEBUG_MODE.equals(getLaunchMode(context))) { + launchAttributes.put(IProcessLauncher.PROP_PROCESS_ATTACH, Boolean.TRUE); + } // Launch the process IPropertiesContainer container = new PropertiesContainer(); container.setProperties(launchAttributes); - launcher.launch(getActivePeerModel(data).getPeer(), container, callback); + launcher.launch(getActivePeerModel(data).getPeer(), container, new Callback(callback) { + @Override + protected void internalDone(Object caller, IStatus status) { + Object result = getResult(); + if (status.isOK() && result instanceof IProcesses.ProcessContext) { + StepperAttributeUtil.setProperty(IRemoteAppLaunchAttributes.ATTR_PROCESS_CONTEXT, fullQualifiedId.getParentId(), data, result); + } + super.internalDone(caller, status); + } + }); } } -- cgit v1.2.3