| /******************************************************************************* |
| * Copyright (c) 2009, 2010 Nokia 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: |
| * Nokia - Initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.cdt.debug.edc.windows.launch; |
| |
| import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; |
| import org.eclipse.cdt.debug.core.model.IRestart; |
| import org.eclipse.cdt.debug.edc.IEDCConstants; |
| import org.eclipse.cdt.debug.edc.internal.EDCDebugger; |
| import org.eclipse.cdt.debug.edc.internal.TCFServiceManager; |
| import org.eclipse.cdt.debug.edc.internal.launch.CSourceLookup; |
| import org.eclipse.cdt.debug.edc.internal.services.dsf.Breakpoints; |
| import org.eclipse.cdt.debug.edc.internal.services.dsf.RunControl; |
| import org.eclipse.cdt.debug.edc.launch.AbstractFinalLaunchSequence; |
| import org.eclipse.cdt.debug.edc.launch.ChooseProcessItem; |
| import org.eclipse.cdt.debug.edc.launch.EDCLaunch; |
| import org.eclipse.cdt.debug.edc.ui.console.AbstractLoggingConsoleFactory; |
| import org.eclipse.cdt.debug.edc.ui.console.DebugProgramOutputConsoleFactory; |
| import org.eclipse.cdt.debug.edc.windows.RestartCommand; |
| import org.eclipse.cdt.debug.edc.windows.WindowsDebugger; |
| import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; |
| import org.eclipse.cdt.dsf.concurrent.DsfExecutor; |
| import org.eclipse.cdt.dsf.concurrent.RequestMonitor; |
| import org.eclipse.cdt.dsf.debug.service.ISourceLookup.ISourceLookupDMContext; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.debug.core.ILaunchConfiguration; |
| import org.eclipse.tm.tcf.protocol.IChannel; |
| import org.eclipse.tm.tcf.protocol.IService; |
| |
| @SuppressWarnings("restriction") |
| public class WindowsFinalLaunchSequence extends AbstractFinalLaunchSequence { |
| |
| /** |
| * init TCF breakpoints service and use it if any. |
| * Don't report error if the TCF agent does not offer |
| * breakpoints service....07/12/2011 |
| */ |
| private Step initOptionalBreakpointsServiceStep = new Step() { |
| |
| @Override |
| public String getTaskName() { |
| return "Init Breakpoints service"; |
| } |
| |
| @Override |
| public void execute(RequestMonitor requestMonitor) { |
| assert getTCFPeer() != null : "initFindPeerStep must be run prior to this one"; |
| Breakpoints breakpoints = tracker.getService(Breakpoints.class); |
| |
| // Following is similar to but different from |
| // findTCFServiceForDSFService() |
| try { |
| IService service = getTCFService(org.eclipse.tm.tcf.services.IBreakpoints.NAME); |
| if (service == null) { |
| // agent does not offer the service, it's fine. |
| } |
| else |
| breakpoints.tcfServiceReady(service); |
| } catch (CoreException e1) { |
| if (e1.getStatus().matches(IStatus.CANCEL)) |
| requestMonitor.cancel(); |
| requestMonitor.setStatus(e1.getStatus()); |
| } |
| |
| requestMonitor.done(); |
| } |
| |
| }; |
| |
| // logging |
| protected Step initLoggingStep = new Step() { |
| |
| @Override |
| public void execute(final RequestMonitor requestMonitor) { |
| TCFServiceManager tcfServiceManager = (TCFServiceManager) EDCDebugger.getDefault().getServiceManager(); |
| final IChannel channel = tcfServiceManager.getChannelForPeer(getTCFPeer()); |
| |
| if (enableOutputLogging()) { |
| AbstractLoggingConsoleFactory.openConsole(DebugProgramOutputConsoleFactory.CONSOLE_TYPE, |
| DebugProgramOutputConsoleFactory.CONSOLE_TITLE, |
| DebugProgramOutputConsoleFactory.LOG_ID, channel, true); |
| } else { |
| AbstractLoggingConsoleFactory.setChannel(DebugProgramOutputConsoleFactory.CONSOLE_TYPE, |
| DebugProgramOutputConsoleFactory.LOG_ID, channel); |
| } |
| |
| requestMonitor.done(); |
| } |
| }; |
| |
| /** |
| * Just here so subclasses can override if needed |
| * @since 2.0 |
| */ |
| protected boolean enableOutputLogging() { |
| return true; |
| } |
| |
| private Step configureSourceLookupStep = new Step() { |
| |
| @Override |
| public void execute(final RequestMonitor requestMonitor) { |
| RunControl runControlService = tracker.getService(RunControl.class); |
| CSourceLookup sourceLookup = tracker.getService(CSourceLookup.class); |
| ISourceLookupDMContext sourceLookupDmc = (ISourceLookupDMContext) (runControlService.getRootDMC()); |
| try { |
| sourceLookup.addSourceLookupDirector(sourceLookupDmc, (CSourceLookupDirector) getLaunch().createSourceLocator()); |
| } catch (CoreException e) { |
| WindowsDebugger.getMessageLogger().logError(null, e); |
| } |
| requestMonitor.done(); |
| } |
| }; |
| // experimental "Restart" command support. |
| // |
| protected Step initRestartStep = new Step() { |
| |
| @Override |
| public void execute(final RequestMonitor requestMonitor) { |
| |
| TCFServiceManager tcfServiceManager = (TCFServiceManager) EDCDebugger.getDefault().getServiceManager(); |
| IChannel channel = tcfServiceManager.getChannelForPeer(getTCFPeer()); |
| |
| getLaunch().getSession().registerModelAdapter(IRestart.class, |
| new RestartCommand(getLaunch().getSession(), getLaunch(), channel)); |
| requestMonitor.done(); |
| } |
| }; |
| |
| /** |
| * @since 2.0 |
| */ |
| protected Step initLaunchDescriptionStep = new Step() { |
| |
| @Override |
| public void execute(final RequestMonitor requestMonitor) { |
| String targetDescription = getTCFPeer().getAttributes().get("Description"); |
| WindowsFinalLaunchSequence.this.getLaunch().setDescription(targetDescription); |
| requestMonitor.done(); |
| } |
| }; |
| |
| public WindowsFinalLaunchSequence(DsfExecutor executor, EDCLaunch launch, IProgressMonitor pm) { |
| super(executor, launch, pm, "Configure Windows Debugger:", "Abort configuring Windows debugger"); |
| |
| boolean doAttach; |
| |
| ILaunchConfiguration config = launch.getLaunchConfiguration(); |
| doAttach = false; |
| try { |
| String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, |
| ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN); |
| if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) { |
| doAttach = true; |
| } |
| } catch (CoreException e) { |
| } |
| |
| if (launch.isFirstLaunch()) |
| { |
| steps.add(trackerStep); |
| steps.add(initFindPeerStep); |
| steps.add(initLaunchDescriptionStep); |
| steps.add(initRunControlStep); |
| steps.add(initLoggingStep); |
| steps.add(initRestartStep); |
| steps.add(initRegistersServiceStep); |
| steps.add(initMemoryServiceStep); |
| steps.add(initProcessesServiceStep); |
| steps.add(initOptionalBreakpointsServiceStep); |
| steps.add(doAttach ? attachStep : launchStep); |
| steps.add(cleanupStep); |
| } |
| else |
| { |
| steps.add(trackerStep); |
| steps.add(initFindPeerStep); |
| steps.add(initLoggingStep); |
| steps.add(configureSourceLookupStep); |
| steps.add(doAttach ? attachStep : launchStep); |
| } |
| } |
| |
| @Override |
| protected ChooseProcessItem chooseProcess(ChooseProcessItem[] processes, String defaultSelection) |
| throws CoreException { |
| return WindowsDebugger.chooseProcess(processes); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.cdt.debug.edc.launch.AbstractFinalLaunchSequence#useLocalAgentOnly() |
| */ |
| @Override |
| protected boolean useLocalAgentOnly() { |
| return true; |
| } |
| |
| @Override |
| protected void specifyRequiredPeer() { |
| peerAttributes.put(IEDCConstants.PEER_ATTR_DEBUG_SUPPORT, "Win32 Debug API"); |
| } |
| } |