From bc9547c99e2fa551d259463884d748ce380411c6 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Wed, 20 Oct 2004 19:09:39 +0000 Subject: [PATCH] 2004-10-20 Alain Magloire Use the new ICDIDebugger interface * mi/org/eclipse/cdt/debug/mi/core/MIInferior.java * mi/org/eclipse/cdt/debug/mi/core/MISession.java * mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java * src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.java * src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java * src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java * src/org/eclipse/cdt/debug/mi/core/GDBServerDebugger.java * src/org/eclipse/cdt/debug/mi/core/MIPlugin.java * src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java * plugin.xml --- debug/org.eclipse.cdt.debug.mi.core/ChangeLog | 14 + .../eclipse/cdt/debug/mi/core/MIInferior.java | 11 +- .../eclipse/cdt/debug/mi/core/MISession.java | 29 +- .../cdt/debug/mi/core/SessionProcess.java | 2 +- .../org.eclipse.cdt.debug.mi.core/plugin.xml | 4 +- .../debug/mi/core/CygwinGDBCDIDebugger.java | 86 ++++++ .../cdt/debug/mi/core/GDBCDIDebugger.java | 285 ++++++++++++++++++ .../cdt/debug/mi/core/GDBDebugger.java | 7 +- .../cdt/debug/mi/core/GDBServerDebugger.java | 4 +- .../eclipse/cdt/debug/mi/core/MIPlugin.java | 33 +- .../mi/core/MIPluginResources.properties | 3 + .../cdt/debug/mi/core/MIProcessAdapter.java | 54 ++-- 12 files changed, 477 insertions(+), 55 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.java create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index 436b6db3c98..54cf901c083 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,17 @@ +2004-10-20 Alain Magloire + Use the new ICDIDebugger interface + + * mi/org/eclipse/cdt/debug/mi/core/MIInferior.java + * mi/org/eclipse/cdt/debug/mi/core/MISession.java + * mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java + * src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.java + * src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java + * src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java + * src/org/eclipse/cdt/debug/mi/core/GDBServerDebugger.java + * src/org/eclipse/cdt/debug/mi/core/MIPlugin.java + * src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java + * plugin.xml + 2004-10-20 David Inglis Fixed terminated delay for corefile * mi/org/eclipse/cdt/debug/mi/core/MIInferior.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java index a35b9ada3f2..6df7e6c71ce 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java @@ -168,12 +168,13 @@ public class MIInferior extends Process { // - For PostMortem(Core): send event // else noop if ((session.isAttachSession() && isConnected()) || (session.isProgramSession() && !isTerminated())) { - + // Try to interrupt the inferior, first. + if (isRunning()) { + interrupt(); + } CommandFactory factory = session.getCommandFactory(); MIExecAbort abort = factory.createMIExecAbort(); - // Try to interrupt the inferior, first. - interrupt(); - session.postCommand(abort); + session.postCommand0(abort, session.getCommandTimeout()); abort.getMIInfo(); setTerminated(abort.getToken(), true); } else if (session.isCoreSession() && !isTerminated()){ @@ -248,7 +249,7 @@ public class MIInferior extends Process { } public synchronized void setTerminated() { - setTerminated(0, false); + setTerminated(0, true); } synchronized void setTerminated(int token, boolean fireEvent) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java index 9320a3eb3d9..131c459c49a 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java @@ -292,7 +292,7 @@ public class MISession extends Observable { /** * Sends a command to gdb, and wait(timeout) for a response. */ - public synchronized void postCommand(Command cmd, long timeout) throws MIException { + public void postCommand(Command cmd, long timeout) throws MIException { // Test if we are in a sane state. if (!txThread.isAlive() || !rxThread.isAlive()) { @@ -311,7 +311,10 @@ public class MISession extends Observable { if (isTerminated()) { throw new MIException(MIPlugin.getResourceString("src.MISession.Session_terminated")); //$NON-NLS-1$ } + postCommand0(cmd, timeout); + } + public synchronized void postCommand0(Command cmd, long timeout) throws MIException { // TRACING: print the command; MIPlugin.getDefault().debugLog(cmd.toString()); @@ -374,12 +377,12 @@ public class MISession extends Observable { if (isTerminated()) { return; } - + terminated = true; // Destroy any MI Inferior(Process) and streams. inferior.destroy(); - + // {in,out}Channel is use as predicate/condition // in the {RX,TX,Event}Thread to detect termination // and bail out. So they are set to null. @@ -462,23 +465,17 @@ public class MISession extends Observable { } // Allow (10 secs) for the EventThread to finish processing the queue. - Queue queue = getEventQueue(); - for (int i = 0; !queue.isEmpty() && i < 5; i++) { + if (!eventThread.equals(Thread.currentThread())) { + // Kill the event Thread. try { - java.lang.Thread.sleep(2000); + if (eventThread.isAlive()) { + eventThread.interrupt(); + eventThread.join(cmdTimeout); + } } catch (InterruptedException e) { - } + } } - // Kill the event Thread. - try { - if (eventThread.isAlive()) { - eventThread.interrupt(); - eventThread.join(cmdTimeout); - } - } catch (InterruptedException e) { - } - // Tell the observers that the session is terminated notifyObservers(new MIGDBExitEvent(this, 0)); diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java index 7ce17bb6238..65aa74c09e3 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java @@ -31,7 +31,7 @@ public class SessionProcess extends Process { * @see java.lang.Process#destroy() */ public void destroy() { - session.getGDBProcess().destroy(); + session.terminate(); } /** diff --git a/debug/org.eclipse.cdt.debug.mi.core/plugin.xml b/debug/org.eclipse.cdt.debug.mi.core/plugin.xml index 2eaae6dfaa1..b748371fabb 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/plugin.xml +++ b/debug/org.eclipse.cdt.debug.mi.core/plugin.xml @@ -28,7 +28,7 @@ name="%GDBDebugger.name" modes="run,core,attach" cpu="native" - class="org.eclipse.cdt.debug.mi.core.GDBDebugger" + class="org.eclipse.cdt.debug.mi.core.GDBCDIDebugger" id="org.eclipse.cdt.debug.mi.core.CDebugger"> 0) { + String[] oldPaths = manager.getSharedLibraryPaths(); + String[] paths = new String[oldPaths.length + p.size()]; + System.arraycopy(p.toArray(new String[p.size()]), 0, paths, 0, p.size()); + System.arraycopy(oldPaths, 0, paths, p.size(), oldPaths.length); + manager.setSharedLibraryPaths(paths); + } + } catch (CDIException e) { + throw newCoreException(MIPlugin.getResourceString("src.GDBDebugger.Error_initializing_shared_lib_options") + e.getMessage(), e); //$NON-NLS-1$ + } + } + + public static IPath getProjectPath(ILaunchConfiguration configuration) throws CoreException { + String projectName = getProjectName(configuration); + if (projectName != null) { + projectName = projectName.trim(); + if (projectName.length() > 0) { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + IPath p = project.getLocation(); + if (p != null) { + return p; + } + } + } + return Path.EMPTY; + } + + public static String getProjectName(ILaunchConfiguration configuration) throws CoreException { + return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null); + } + + protected ILaunch getLauch() { + return fLaunch; + } + + protected String renderDebuggerProcessLabel() { + String format = "{0} ({1})"; //$NON-NLS-1$ + String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis())); + return MessageFormat.format(format, new String[]{ + "Debugger Process", timestamp}); //$NON-NLS-1$ + } + + /** + * Throws a core exception with an error status object built from the given + * message, lower level exception, and error code. + * + * @param message + * the status message + * @param exception + * lower level exception associated with the error, or + * null if none + * @param code + * error code + */ + protected CoreException newCoreException(Throwable exception) { + String message = MIPlugin.getResourceString("src.GDBDebugger.Error_creating_session") + exception.getMessage();//$NON-NLS-1$ + int code = ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR; + String ID = MIPlugin.getUniqueIdentifier(); + MultiStatus status = new MultiStatus(ID, code, message, exception); + status.add(new Status(IStatus.ERROR, ID, code, exception == null ? new String() : exception.getLocalizedMessage(), exception)); + return new CoreException(status); + } + + protected CoreException newCoreException(String message, Throwable exception) { + int code = ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR; + String ID = MIPlugin.getUniqueIdentifier(); + MultiStatus status = new MultiStatus(ID, code, message, exception); + status.add(new Status(IStatus.ERROR, ID, code, exception == null ? new String() : exception.getLocalizedMessage(), exception)); + return new CoreException(status); + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java index fc941b1d44e..19fb3e25512 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.debug.core.ILaunchConfiguration; public class GDBDebugger implements ICDebugger { @@ -73,7 +74,7 @@ public class GDBDebugger implements ICDebugger { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ - session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit); + session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit, null); initializeLibraries(config, session); return session; } catch (IOException e) { @@ -105,7 +106,7 @@ public class GDBDebugger implements ICDebugger { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ - session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit); + session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit, null); initializeLibraries(config, session); return session; } catch (IOException e) { @@ -137,7 +138,7 @@ public class GDBDebugger implements ICDebugger { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ - session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit); + session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit, null); initializeLibraries(config, session); return session; } catch (IOException e) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerDebugger.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerDebugger.java index 5a1decc0d6d..149a09cd88c 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerDebugger.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerDebugger.java @@ -69,7 +69,7 @@ public class GDBServerDebugger implements ICDebugger { remote += ":"; //$NON-NLS-1$ remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); //$NON-NLS-1$ String[] args = new String[] {"remote", remote}; //$NON-NLS-1$ - session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), 0, args, cwd, gdbinit); + session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), 0, args, cwd, gdbinit, null); } else { MIPlugin plugin = MIPlugin.getDefault(); Preferences prefs = plugin.getPluginPreferences(); @@ -77,7 +77,7 @@ public class GDBServerDebugger implements ICDebugger { String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); //$NON-NLS-1$ String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid"); //$NON-NLS-1$ - session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), -1, null, cwd, gdbinit); + session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), -1, null, cwd, gdbinit, null); ICDITarget[] targets = session.getTargets(); for (int i = 0; i < targets.length; ++i) { Target target = (Target)targets[i]; diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java index 7bbdd839406..58a06c1059c 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java @@ -26,6 +26,8 @@ import org.eclipse.cdt.debug.mi.core.command.MITargetAttach; import org.eclipse.cdt.debug.mi.core.command.MITargetSelect; import org.eclipse.cdt.debug.mi.core.output.MIInfo; import org.eclipse.cdt.utils.pty.PTY; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Preferences; import org.osgi.framework.BundleContext; @@ -109,7 +111,7 @@ public class MIPlugin extends Plugin { * @return ICDISession * @throws MIException */ - public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit) throws IOException, MIException { + public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { IMITTY pty = null; boolean failed = false; @@ -117,10 +119,11 @@ public class MIPlugin extends Plugin { PTY pseudo = new PTY(); pty = new MITTYAdapter(pseudo); } catch (IOException e) { + // Should we not print/log this ? } try { - return createCSession(gdb, program, cwd, gdbinit, pty); + return createCSession(gdb, program, cwd, gdbinit, pty, monitor); } catch (IOException exc) { failed = true; throw exc; @@ -153,7 +156,7 @@ public class MIPlugin extends Plugin { * @return ICDISession * @throws IOException */ - public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit, IMITTY pty) throws IOException, MIException { + public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit, IMITTY pty, IProgressMonitor monitor) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = GDB; } @@ -162,6 +165,10 @@ public class MIPlugin extends Plugin { gdbinit = GDBINIT; } + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + String[] args; if (pty != null) { if (program == null) { @@ -177,7 +184,7 @@ public class MIPlugin extends Plugin { } } - MIProcess pgdb = new MIProcessAdapter(args); + MIProcess pgdb = new MIProcessAdapter(args, monitor); MISession session; try { @@ -213,7 +220,7 @@ public class MIPlugin extends Plugin { * @return ICDISession * @throws IOException */ - public ICDISession createCSession(String gdb, File program, File core, File cwd, String gdbinit) throws IOException, MIException { + public ICDISession createCSession(String gdb, File program, File core, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = GDB; } @@ -221,14 +228,18 @@ public class MIPlugin extends Plugin { if (gdbinit == null || gdbinit.length() == 0) { gdbinit = GDBINIT; } - + + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + String[] args; if (program == null) { args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", "-c", core.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ } else { args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", "-c", core.getAbsolutePath(), program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ } - MIProcess pgdb = new MIProcessAdapter(args); + MIProcess pgdb = new MIProcessAdapter(args, monitor); MISession session; try { session = createMISession(pgdb, null, MISession.CORE); @@ -248,7 +259,7 @@ public class MIPlugin extends Plugin { * @return ICDISession * @throws IOException */ - public ICDISession createCSession(String gdb, File program, int pid, String[] targetParams, File cwd, String gdbinit) throws IOException, MIException { + public ICDISession createCSession(String gdb, File program, int pid, String[] targetParams, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = GDB; } @@ -257,13 +268,17 @@ public class MIPlugin extends Plugin { gdbinit = GDBINIT; } + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + String[] args; if (program == null) { args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } else { args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } - MIProcess pgdb = new MIProcessAdapter(args); + MIProcess pgdb = new MIProcessAdapter(args, monitor); MISession session; try { session = createMISession(pgdb, null, MISession.ATTACH); diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPluginResources.properties b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPluginResources.properties index 234dc421691..48c9965fed1 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPluginResources.properties +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPluginResources.properties @@ -16,6 +16,8 @@ src.GDBServerDebugger.GDBServer_attaching_unsupported=GDBServer does not support src.GDBServerDebugger.GDBServer_corefiles_unsupported=GDBServer does not support core files src.GDBDebugger.Error_initializing_shared_lib_options=Error initializing shared library options: src.GDBDebugger.Error_creating_session=Error creating session: +src.GDBDebugger.Error_launch_timeout=Launch timeout +src.GDBDebugger.Error_launch_cancel=Launch cancel src.MISession.Process_Terminated=Process Terminated src.MISession.Thread_Terminated={R,T}xThread terminated src.MISession.Target_not_suspended=Target is not suspended @@ -25,3 +27,4 @@ src.CygwinGDBDebugger.Error_init_shared_lib_options=Error initializing shared li src.MIInferior.target_is_suspended=target is suspended src.MIInferior.No_session=No MI Session src.MIInferior.Failed_to_interrupt=Failed to interrupt + diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java index 053eb13c29f..20bd2d98dd0 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java @@ -20,6 +20,7 @@ import java.io.Reader; import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.cdt.utils.spawner.Spawner; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Preferences; /** @@ -28,19 +29,21 @@ public class MIProcessAdapter implements MIProcess { Process fGDBProcess; - public MIProcessAdapter(String[] args) throws IOException { - fGDBProcess = getGDBProcess(args); + public MIProcessAdapter(String[] args, IProgressMonitor monitor) throws IOException { + fGDBProcess = getGDBProcess(args, monitor); } /** * Do some basic synchronisation, gdb may take some time to load for - * whatever reasons. + * whatever reasons and we need to be able to let the user bailout. * * @param args * @return Process * @throws IOException */ - protected Process getGDBProcess(String[] args) throws IOException { + protected Process getGDBProcess(String[] args, IProgressMonitor monitor) throws IOException { + int ONE_SECOND = 1000; + if (MIPlugin.getDefault().isDebugging()) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < args.length; ++i) { @@ -65,32 +68,49 @@ public class MIProcessAdapter implements MIProcess { } } } catch (Exception e) { - // Do nothing - } - synchronized (pgdb) { - pgdb.notifyAll(); + // Do nothing, ignore the errors } } }; syncStartup.start(); - synchronized (pgdb) { - MIPlugin miPlugin = MIPlugin.getDefault(); - Preferences prefs = miPlugin.getPluginPreferences(); - int launchTimeout = prefs - .getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); - while (syncStartup.isAlive()) { + MIPlugin miPlugin = MIPlugin.getDefault(); + Preferences prefs = miPlugin.getPluginPreferences(); + int timepass = 0; + int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); + if (launchTimeout <= 0) { + // Simulate we are waiting forever. + launchTimeout = Integer.MAX_VALUE; + } + + // To respect the IProgressMonitor we can not use wait/notify + // instead we have to loop and check for the monitor to allow to cancel the thread. + // The monitor is check every 1 second delay; + for (timepass = 0; timepass < launchTimeout; timepass += ONE_SECOND) { + if (syncStartup.isAlive() && !monitor.isCanceled()) { try { - pgdb.wait(launchTimeout); - break; + Thread.sleep(ONE_SECOND); } catch (InterruptedException e) { + // ignore } + } else { + break; } } try { syncStartup.interrupt(); - syncStartup.join(1000); + syncStartup.join(ONE_SECOND); } catch (InterruptedException e) { + // ignore + } + if (monitor.isCanceled()) { + pgdb.destroy(); + String message = MIPlugin.getResourceString("src.GDBDebugger.Error_creating_session");//$NON-NLS-1$ + throw new IOException(message); + } else if (timepass > launchTimeout) { + pgdb.destroy(); + String message = MIPlugin.getResourceString("src.GDBDebugger.Error_launch_timeout"); //$NON-NLS-1$ + throw new IOException(message); } return pgdb; }