From 89f4a41f0e91e813f237cf02337edd181e06fc3b Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 19 Mar 2008 13:24:30 +0000 Subject: [PATCH] Merge the GdbRemoteLaunchDelegate and the GdbLocalLaunchDelegate into a single GdbLaunchDelegate --- plugins/org.eclipse.dd.gdb.launch/plugin.xml | 4 +- .../dd/gdb/launch/launching/GdbLaunch.java | 4 +- ...chDelegate.java => GdbLaunchDelegate.java} | 31 +- .../launching/GdbRemoteLaunchDelegate.java | 292 ------------------ .../dd/gdb/internal/ui/GdbAdapterFactory.java | 6 +- .../CBreakpointGdbThreadFilterPage.java | 4 +- 6 files changed, 32 insertions(+), 309 deletions(-) rename plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/{GdbLocalLaunchDelegate.java => GdbLaunchDelegate.java} (90%) delete mode 100644 plugins/org.eclipse.dd.gdb.launch/src/org/eclipse/dd/gdb/launch/launching/GdbRemoteLaunchDelegate.java diff --git a/plugins/org.eclipse.dd.gdb.launch/plugin.xml b/plugins/org.eclipse.dd.gdb.launch/plugin.xml index cc2a0d580d0..0b49da90602 100644 --- a/plugins/org.eclipse.dd.gdb.launch/plugin.xml +++ b/plugins/org.eclipse.dd.gdb.launch/plugin.xml @@ -4,7 +4,7 @@ cliProcessRef = new AtomicReference(); - final AtomicReference inferiorProcessRef = new AtomicReference(); - try { - launch.getDsfExecutor().submit( new Callable() { - public Object call() throws CoreException { - DsfServicesTracker tracker = new DsfServicesTracker(GdbLaunchPlugin.getBundleContext(), launch.getSession().getId()); - GDBControl gdb = tracker.getService(GDBControl.class); - if (gdb != null) { - cliProcessRef.set(gdb.getCLIProcess()); - inferiorProcessRef.set(gdb.getInferiorProcess()); - } - tracker.dispose(); - return null; - } - }).get(); - launch.addProcess(DebugPlugin.newProcess(launch, cliProcessRef.get(), "gdb")); //$NON-NLS-1$ - launch.addProcess(DebugPlugin.newProcess(launch, inferiorProcessRef.get(), exePath.lastSegment())); - } catch (InterruptedException e) { - throw new CoreException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, 0, "Interrupted while waiting for get process callable.", e)); //$NON-NLS-1$ - } catch (ExecutionException e) { - throw (CoreException)e.getCause(); - } catch (RejectedExecutionException e) { - throw new CoreException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, 0, "Debugger shut down before launch was completed.", e)); //$NON-NLS-1$ - } - - // Create a memory retrieval and register it with session - try { - launch.getDsfExecutor().submit( new Callable() { - public Object call() throws CoreException { - DsfServicesTracker tracker = new DsfServicesTracker(GdbLaunchPlugin.getBundleContext(), launch.getSession().getId()); - GDBControl gdbControl = tracker.getService(GDBControl.class); - if (gdbControl != null) { - IMemoryBlockRetrieval memRetrieval = new DsfMemoryBlockRetrieval( - GDB_DEBUG_MODEL_ID, config, (IMemoryDMContext)gdbControl.getControlDMContext()); - launch.getSession().registerModelAdapter(IMemoryBlockRetrieval.class, memRetrieval); - ((DsfMemoryBlockRetrieval) memRetrieval).initialize(); - } - tracker.dispose(); - return null; - } - }).get(); - } catch (InterruptedException e) { - throw new CoreException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, 0, "Interrupted while waiting for get process callable.", e)); //$NON-NLS-1$ - } catch (ExecutionException e) { - throw (CoreException)e.getCause(); - } catch (RejectedExecutionException e) { - throw new CoreException(new Status(IStatus.ERROR, GdbLaunchPlugin.PLUGIN_ID, 0, "Debugger shut down before launch was completed.", e)); //$NON-NLS-1$ - } - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#getPluginID() - */ - @Override - protected String getPluginID() { - return LaunchUIPlugin.getUniqueIdentifier(); - } - - /** - * Performs a runtime exec on the given command line in the context of the - * specified working directory, and returns the resulting process. If the - * current runtime does not support the specification of a working - * directory, the status handler for error code - * ERR_WORKING_DIRECTORY_NOT_SUPPORTED is queried to see if - * the exec should be re-executed without specifying a working directory. - * - * @param cmdLine - * the command line - * @param workingDirectory - * the working directory, or null - * @return the resulting process or null if the exec is - * cancelled - * @see Runtime - */ - protected Process exec( String[] cmdLine, String[] environ, File workingDirectory, boolean usePty ) throws CoreException { - Process p = null; - try { - if ( workingDirectory == null ) { - p = ProcessFactory.getFactory().exec( cmdLine, environ ); - } - else { - if ( usePty && PTY.isSupported() ) { - p = ProcessFactory.getFactory().exec( cmdLine, environ, workingDirectory, new PTY() ); - } - else { - p = ProcessFactory.getFactory().exec( cmdLine, environ, workingDirectory ); - } - } - } - catch( IOException e ) { - if ( p != null ) { - p.destroy(); - } - abort( "Error starting process.", e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR ); //$NON-NLS-1$ - } - catch( NoSuchMethodError e ) { - // attempting launches on 1.2.* - no ability to set working - // directory - IStatus status = new Status( IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(), ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_NOT_SUPPORTED, LaunchMessages.getString( "LocalDsfLaunchDelegate.9" ), e ); //$NON-NLS-1$ - IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler( status ); - if ( handler != null ) { - Object result = handler.handleStatus( status, this ); - if ( result instanceof Boolean && ((Boolean)result).booleanValue() ) { - p = exec( cmdLine, environ, null, usePty ); - } - } - } - return p; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.launch.AbstractCLaunchDelegate#preLaunchCheck(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - public boolean preLaunchCheck( ILaunchConfiguration config, String mode, IProgressMonitor monitor ) throws CoreException { - // no pre launch check for core file - if ( mode.equals( ILaunchManager.DEBUG_MODE ) ) { - if ( ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE.equals( config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ) ) ) - return true; - } - return super.preLaunchCheck( config, mode, monitor ); - } - - /////////////////////////////////////////////////////////////////////////// - // ILaunchConfigurationDelegate2 - @Override - public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { - return false; - } - - @Override - public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { - return true; - } - - @Override - public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException { - // Need to configure the source locator before creating the launch - // because once the launch is created and added to launch manager, - // the adapters will be created for the whole session, including - // the source lookup adapter. - ISourceLocator locator = getSourceLocator(configuration); - - return new GdbLaunch(configuration, mode, locator); - } - - private ISourceLocator getSourceLocator(ILaunchConfiguration configuration) throws CoreException { - String type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String)null); - if (type == null) { - type = configuration.getType().getSourceLocatorId(); - } - if (type != null) { - IPersistableSourceLocator locator = DebugPlugin.getDefault().getLaunchManager().newSourceLocator(type); - String memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String)null); - if (memento == null) { - locator.initializeDefaults(configuration); - } else { - if(locator instanceof IPersistableSourceLocator2) - ((IPersistableSourceLocator2)locator).initializeFromMemento(memento, configuration); - else - locator.initializeFromMemento(memento); - } - return locator; - } - return null; - } -} diff --git a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java index c38adc21aff..0a8e25f346b 100644 --- a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java +++ b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java @@ -28,8 +28,7 @@ import org.eclipse.dd.dsf.service.DsfSession; import org.eclipse.dd.gdb.internal.ui.actions.DsfTerminateCommand; import org.eclipse.dd.gdb.internal.ui.viewmodel.GdbViewModelAdapter; import org.eclipse.dd.gdb.launch.launching.GdbLaunch; -import org.eclipse.dd.gdb.launch.launching.GdbLocalLaunchDelegate; -import org.eclipse.dd.gdb.launch.launching.GdbRemoteLaunchDelegate; +import org.eclipse.dd.gdb.launch.launching.GdbLaunchDelegate; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchesListener2; @@ -102,8 +101,7 @@ public class GdbAdapterFactory fDebugModelProvider = new IDebugModelProvider() { // @see org.eclipse.debug.core.model.IDebugModelProvider#getModelIdentifiers() public String[] getModelIdentifiers() { - return new String[] { GdbLocalLaunchDelegate.GDB_DEBUG_MODEL_ID, - GdbRemoteLaunchDelegate.GDB_DEBUG_MODEL_ID}; + return new String[] { GdbLaunchDelegate.GDB_DEBUG_MODEL_ID }; } }; session.registerModelAdapter(IDebugModelProvider.class, fDebugModelProvider); diff --git a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/breakpoints/CBreakpointGdbThreadFilterPage.java b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/breakpoints/CBreakpointGdbThreadFilterPage.java index 29ff31a6c1d..994ba97c6e0 100644 --- a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/breakpoints/CBreakpointGdbThreadFilterPage.java +++ b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/breakpoints/CBreakpointGdbThreadFilterPage.java @@ -13,7 +13,7 @@ package org.eclipse.dd.gdb.internal.ui.breakpoints; import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.core.runtime.CoreException; import org.eclipse.dd.gdb.breakpoints.CBreakpointGdbThreadsFilterExtension; -import org.eclipse.dd.gdb.launch.launching.GdbLocalLaunchDelegate; +import org.eclipse.dd.gdb.launch.launching.GdbLaunchDelegate; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -50,7 +50,7 @@ public class CBreakpointGdbThreadFilterPage extends PropertyPage { try { CBreakpointGdbThreadsFilterExtension filter = (CBreakpointGdbThreadsFilterExtension) bp.getExtension( - GdbLocalLaunchDelegate.GDB_DEBUG_MODEL_ID, CBreakpointGdbThreadsFilterExtension.class); + GdbLaunchDelegate.GDB_DEBUG_MODEL_ID, CBreakpointGdbThreadsFilterExtension.class); filter.initialize(bp); return filter; } catch (CoreException e) {}