Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/ChangeLog14
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MIInferior.java11
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java29
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java2
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/plugin.xml4
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.java86
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java285
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java7
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerDebugger.java4
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java33
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPluginResources.properties3
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java54
12 files changed, 477 insertions, 55 deletions
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">
</debugger>
<debugger
@@ -36,7 +36,7 @@
name="%CygwinGDBDebugger.name"
modes="run,core,attach"
cpu="native"
- class="org.eclipse.cdt.debug.mi.core.CygwinGDBDebugger"
+ class="org.eclipse.cdt.debug.mi.core.CygwinGDBCDIDebugger"
id="org.eclipse.cdt.debug.mi.core.CygwinCDebugger">
</debugger>
<debugger
diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.java
new file mode 100644
index 00000000000..3cc8545bed9
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.mi.core;
+
+import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
+import org.eclipse.cdt.debug.core.cdi.ICDISession;
+import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
+import org.eclipse.cdt.debug.mi.core.cdi.Session;
+import org.eclipse.cdt.debug.mi.core.cdi.model.Target;
+import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
+import org.eclipse.cdt.debug.mi.core.command.MIGDBSet;
+import org.eclipse.cdt.debug.mi.core.output.MIInfo;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunchConfiguration;
+
+/**
+ * @author User
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class CygwinGDBCDIDebugger extends GDBCDIDebugger {
+ static final CygwinCommandFactory commandFactory = new CygwinCommandFactory();
+
+ protected void initializeLibraries(ILaunchConfiguration config, Session session) throws CoreException {
+ // the "search-solib-path" and "stop-on-solib-events" options are not supported in CygWin
+ }
+
+ public ICDISession createLaunchSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
+ Session session = (Session) super.createLaunchSession(config, exe, monitor);
+ ICDITarget[] targets = session.getTargets();
+ for (int i = 0; i < targets.length; ++i) {
+ Target target = (Target)targets[i];
+ MISession miSession = target.getMISession();
+ miSession.setCommandFactory(commandFactory);
+ // For windows we need to start the inferior in a new console window
+ // to separate the Inferior std{in,out,err} from gdb std{in,out,err}
+ try {
+ CommandFactory factory = miSession.getCommandFactory();
+ MIGDBSet set = factory.createMIGDBSet(new String[] { "new-console" }); //$NON-NLS-1$
+ miSession.postCommand(set);
+ MIInfo info = set.getMIInfo();
+ if (info == null) {
+ throw new MIException(MIPlugin.getResourceString("src.common.No_answer")); //$NON-NLS-1$
+ }
+ } catch (MIException e) {
+ // We ignore this exception, for example
+ // on GNU/Linux the new-console is an error.
+ }
+ }
+ return session;
+ }
+
+ public ICDISession createAttachSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
+ Session session = (Session) super.createAttachSession(config, exe, monitor);
+ ICDITarget[] targets = session.getTargets();
+ for (int i = 0; i < targets.length; ++i) {
+ Target target = (Target)targets[i];
+ target.getMISession().setCommandFactory(commandFactory);
+ }
+ initializeLibraries(config, session);
+ return session;
+ }
+
+ public ICDISession createCoreSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
+ Session session = (Session) super.createCoreSession(config, exe, monitor);
+ ICDITarget[] targets = session.getTargets();
+ for (int i = 0; i < targets.length; ++i) {
+ Target target = (Target)targets[i];
+ target.getMISession().setCommandFactory(commandFactory);
+ }
+ initializeLibraries(config, session);
+ return session;
+ }
+
+}
diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java
new file mode 100644
index 00000000000..24497b91598
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java
@@ -0,0 +1,285 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.debug.mi.core;
+
+import java.io.File;
+import java.text.DateFormat;
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
+import org.eclipse.cdt.debug.core.ICDIDebugger;
+import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
+import org.eclipse.cdt.debug.core.cdi.CDIException;
+import org.eclipse.cdt.debug.core.cdi.ICDISession;
+import org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryManager;
+import org.eclipse.cdt.debug.mi.core.cdi.Session;
+import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryManager;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+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.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.IProcess;
+
+/**
+ * @author User
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class GDBCDIDebugger implements ICDIDebugger {
+
+ ILaunch fLaunch;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.debug.core.ICDIDebugger#createDebuggerSession(org.eclipse.debug.core.ILaunch, org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public ICDISession createDebuggerSession(ILaunch launch, IBinaryExecutable exe, IProgressMonitor monitor)
+ throws CoreException {
+ fLaunch = launch;
+ ILaunchConfiguration config = launch.getLaunchConfiguration();
+ ICDISession dsession = null;
+ String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
+ ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
+
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+
+ if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
+ dsession = createLaunchSession(config, exe, monitor);
+ } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) {
+ dsession = createAttachSession(config, exe, monitor);
+ } else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) {
+ dsession = createCoreSession(config, exe, monitor);
+ }
+ if (dsession != null) {
+ Process debugger;
+ try {
+ debugger = dsession.getSessionProcess();
+ if (debugger != null ) {
+ IProcess debuggerProcess = DebugPlugin.newProcess(launch, debugger, renderDebuggerProcessLabel());
+ launch.addProcess(debuggerProcess);
+ }
+ } catch (CDIException e) {
+ // Should we just ignore ?
+ }
+ }
+
+ return dsession;
+ }
+
+ public ICDISession createLaunchSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
+ Session session = null;
+ boolean failed = false;
+ try {
+ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
+ File cwd = getProjectPath(config).toFile();
+ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
+ session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), cwd, gdbinit, monitor);
+ initializeLibraries(config, session);
+ return session;
+ } catch (Exception e) {
+ // Catch all wrap them up and rethrow
+ failed = true;
+ if (e instanceof CoreException) {
+ throw (CoreException)e;
+ }
+ throw newCoreException(e);
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
+ }
+ }
+
+ public ICDISession createAttachSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
+ Session session = null;
+ boolean failed = false;
+ try {
+ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
+ int pid = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, -1);
+ File cwd = getProjectPath(config).toFile();
+ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
+ session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), pid, null, cwd, gdbinit, monitor);
+ initializeLibraries(config, session);
+ return session;
+ } catch (Exception e) {
+ // Catch all wrap them up and rethrow
+ failed = true;
+ if (e instanceof CoreException) {
+ throw (CoreException)e;
+ }
+ throw newCoreException(e);
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
+ }
+ }
+
+ public ICDISession createCoreSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
+ Session session = null;
+ boolean failed = false;
+ try {
+ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
+ File cwd = getProjectPath(config).toFile();
+ IPath coreFile = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, (String)null));
+ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
+ session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), coreFile.toFile(), cwd, gdbinit, monitor);
+ initializeLibraries(config, session);
+ return session;
+ } catch (Exception e) {
+ // Catch all wrap them up and rethrow
+ failed = true;
+ if (e instanceof CoreException) {
+ throw (CoreException)e;
+ }
+ throw newCoreException(e);
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
+ }
+ }
+
+ protected void initializeLibraries(ILaunchConfiguration config, Session session) throws CoreException {
+ try {
+ ICDISharedLibraryManager manager = session.getSharedLibraryManager();
+ if (manager instanceof SharedLibraryManager) {
+ SharedLibraryManager mgr = (SharedLibraryManager)manager;
+ boolean autolib = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_AUTO_SOLIB, IMILaunchConfigurationConstants.DEBUGGER_AUTO_SOLIB_DEFAULT);
+ boolean stopOnSolibEvents = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_STOP_ON_SOLIB_EVENTS, IMILaunchConfigurationConstants.DEBUGGER_STOP_ON_SOLIB_EVENTS_DEFAULT);
+ try {
+ mgr.setAutoLoadSymbols(autolib);
+ mgr.setStopOnSolibEvents(stopOnSolibEvents);
+ // The idea is that if the user set autolib, by default
+ // we provide with the capability of deferred breakpoints
+ // And we set setStopOnSolib events for them(but they should not see those things.
+ //
+ // If the user explicitly set stopOnSolibEvents well it probably
+ // means that they wanted to see those events so do no do deferred breakpoints.
+ if (autolib && !stopOnSolibEvents) {
+ mgr.setDeferredBreakpoint(true);
+ mgr.setStopOnSolibEvents(true);
+ }
+ } catch (CDIException e) {
+ // Ignore this error
+ // it seems to be a real problem on many gdb platform
+ }
+ }
+ List p = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH, Collections.EMPTY_LIST);
+ if (p.size() > 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
+ * <code>null</code> 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;
}

Back to the top