From 475a55a1e448785e972bac27878e8634400abcb0 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Tue, 29 Jul 2008 18:25:42 +0000 Subject: [PATCH] Bug 241985 Cleanup of GDBControl constructor --- .../launching/GdbLaunchDelegate.java | 48 ++----------------- .../provisional/launching/LaunchUtils.java | 40 ++++++++++++++++ .../launching/ServicesLaunchSequence.java | 7 +-- .../service/command/GDBControl.java | 22 +++++---- 4 files changed, 59 insertions(+), 58 deletions(-) diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/GdbLaunchDelegate.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/GdbLaunchDelegate.java index 2e83ff83d97..ad78c221f60 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/GdbLaunchDelegate.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/GdbLaunchDelegate.java @@ -17,7 +17,6 @@ import java.util.concurrent.ExecutionException; import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -88,8 +87,8 @@ public class GdbLaunchDelegate extends LaunchConfigurationDelegate return; } - SessionType sessionType = getSessionType(config); - boolean attach = getIsAttach(config); + SessionType sessionType = LaunchUtils.getSessionType(config); + boolean attach = LaunchUtils.getIsAttach(config); final GdbLaunch launch = (GdbLaunch)l; @@ -159,25 +158,7 @@ public class GdbLaunchDelegate extends LaunchConfigurationDelegate return new FinalLaunchSequence(executor, launch, type, attach); } - private SessionType getSessionType(ILaunchConfiguration config) { - try { - String debugMode = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ); - if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { - return SessionType.LOCAL; - } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) { - return SessionType.LOCAL; - } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) { - return SessionType.CORE; - } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE)) { - return SessionType.REMOTE; - } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE_ATTACH)) { - return SessionType.REMOTE; - } - } catch (CoreException e) { - } - return SessionType.LOCAL; - } - + private boolean isNonStopSession(ILaunchConfiguration config) { try { boolean nonStopMode = config.getAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_NON_STOP, @@ -187,31 +168,12 @@ public class GdbLaunchDelegate extends LaunchConfigurationDelegate } return false; } - - private boolean getIsAttach(ILaunchConfiguration config) { - try { - String debugMode = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ); - if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { - return false; - } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) { - return true; - } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) { - return false; - } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE)) { - return false; - } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE_ATTACH)) { - return true; - } - } catch (CoreException e) { - } - return false; - } - + @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) && getSessionType(config) == SessionType.CORE) return true; + if (mode.equals(ILaunchManager.DEBUG_MODE) && LaunchUtils.getSessionType(config) == SessionType.CORE) return true; return super.preLaunchCheck(config, mode, monitor); } diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/LaunchUtils.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/LaunchUtils.java index 64e46f219dc..01d354f0a89 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/LaunchUtils.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/LaunchUtils.java @@ -37,6 +37,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.dd.gdb.internal.GdbPlugin; import org.eclipse.dd.gdb.internal.provisional.IGDBLaunchConfigurationConstants; +import org.eclipse.dd.gdb.internal.provisional.service.command.GDBControl.SessionType; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.ILaunchConfiguration; @@ -227,5 +228,44 @@ public class LaunchUtils { return version; } + + public static boolean getIsAttach(ILaunchConfiguration config) { + try { + String debugMode = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ); + if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { + return false; + } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) { + return true; + } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) { + return false; + } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE)) { + return false; + } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE_ATTACH)) { + return true; + } + } catch (CoreException e) { + } + return false; + } + + public static SessionType getSessionType(ILaunchConfiguration config) { + try { + String debugMode = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ); + if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { + return SessionType.LOCAL; + } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) { + return SessionType.LOCAL; + } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) { + return SessionType.CORE; + } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE)) { + return SessionType.REMOTE; + } else if (debugMode.equals(IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE_ATTACH)) { + return SessionType.REMOTE; + } + } catch (CoreException e) { + } + return SessionType.LOCAL; + } + } diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/ServicesLaunchSequence.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/ServicesLaunchSequence.java index e0fa84e73ae..efe32c29bba 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/ServicesLaunchSequence.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/ServicesLaunchSequence.java @@ -41,12 +41,7 @@ public class ServicesLaunchSequence extends Sequence { // Create the connection. // fCommandControl = fLaunch.getServiceFactory().createService(fSession, GDBControl.class); - - fCommandControl.setAttach(fAttach); - fCommandControl.setExecPath(fExecPath); - fCommandControl.setGdbPath(LaunchUtils.getGDBPath(fLaunch.getLaunchConfiguration())); - fCommandControl.setSessionType(fSessionType); - + fCommandControl.initData(fLaunch.getLaunchConfiguration()); fCommandControl.initialize(requestMonitor); } }, diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/command/GDBControl.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/command/GDBControl.java index 87805819814..d7eeaeb4424 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/command/GDBControl.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/command/GDBControl.java @@ -30,6 +30,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; @@ -43,6 +44,7 @@ import org.eclipse.dd.dsf.service.DsfServiceEventHandler; import org.eclipse.dd.dsf.service.DsfSession; import org.eclipse.dd.gdb.internal.GdbPlugin; import org.eclipse.dd.gdb.internal.provisional.launching.GdbLaunch; +import org.eclipse.dd.gdb.internal.provisional.launching.LaunchUtils; import org.eclipse.dd.mi.service.command.AbstractCLIProcess; import org.eclipse.dd.mi.service.command.AbstractMIControl; import org.eclipse.dd.mi.service.command.CLIEventProcessor; @@ -59,6 +61,7 @@ import org.eclipse.dd.mi.service.command.commands.MIInferiorTTYSet; import org.eclipse.dd.mi.service.command.output.MIBreakInsertInfo; import org.eclipse.dd.mi.service.command.output.MIInfo; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunchConfiguration; import org.osgi.framework.BundleContext; /** @@ -117,15 +120,16 @@ public class GDBControl extends AbstractMIControl { fControlDmc = new GDBControlDMContext(session.getId(), "gdbcontrol[" + ++fgInstanceCounter + "]"); //$NON-NLS-1$ //$NON-NLS-2$ } - public void setGdbPath(IPath path) { fGdbPath = path; } - - public void setExecPath(IPath path) { fExecPath = path; } - - public void setSessionType(SessionType type) { fSessionType = type; } - - public void setAttach(boolean attach) { fAttach = attach; } - - public void setLaunchTimeout(int timeout) { fGDBLaunchTimeout = timeout; } + public void initData(ILaunchConfiguration config) { + fSessionType = LaunchUtils.getSessionType(config); + fAttach = LaunchUtils.getIsAttach(config); + fGdbPath = LaunchUtils.getGDBPath(config); + try { + fExecPath = LaunchUtils.verifyProgramPath(config, LaunchUtils.getCProject(config)); + } catch (CoreException e) { + fExecPath = new Path(""); //$NON-NLS-1$ + } + } @Deprecated public GDBControl(DsfSession session, IPath gdbPath, IPath execPath, SessionType sessionType, boolean attach, int gdbLaunchTimeout) {