Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/debug
diff options
context:
space:
mode:
authorAlain Magloire2003-11-22 19:04:45 -0500
committerAlain Magloire2003-11-22 19:04:45 -0500
commitd280153d954bd660073d2b2dd8eaba45dde8e5fa (patch)
tree959c95c161427255a5d724c226880832593f10fb /debug
parentd8c43f191530393ae100ea123922cb06308d566c (diff)
downloadorg.eclipse.cdt-d280153d954bd660073d2b2dd8eaba45dde8e5fa.tar.gz
org.eclipse.cdt-d280153d954bd660073d2b2dd8eaba45dde8e5fa.tar.xz
org.eclipse.cdt-d280153d954bd660073d2b2dd8eaba45dde8e5fa.zip
make sure in the event of an exception that
the session is terminated and all the threads specific to debug are shutdown.
Diffstat (limited to 'debug')
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java128
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java52
-rw-r--r--debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerDebugger.java18
-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/MISession.java36
5 files changed, 204 insertions, 63 deletions
diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java
index 53f86a78e10..4a371189762 100644
--- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java
+++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinGDBDebugger.java
@@ -28,15 +28,15 @@ import org.eclipse.debug.core.ILaunchConfiguration;
*/
public class CygwinGDBDebugger extends GDBDebugger {
- static final CygwinCommandFactory commandFactory =
- new CygwinCommandFactory();
+ static final CygwinCommandFactory commandFactory = new CygwinCommandFactory();
protected void initializeLibraries(ILaunchConfiguration config, Session session) throws CDIException {
try {
ICDISharedLibraryManager manager = session.getSharedLibraryManager();
if (manager instanceof SharedLibraryManager) {
- SharedLibraryManager mgr = (SharedLibraryManager)manager;
- boolean stopOnSolibEvents = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_STOP_ON_SOLIB_EVENTS, false);
+ SharedLibraryManager mgr = (SharedLibraryManager) manager;
+ boolean stopOnSolibEvents =
+ config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_STOP_ON_SOLIB_EVENTS, false);
try {
mgr.setStopOnSolibEvents(stopOnSolibEvents);
// By default, we provide with the capability of deferred breakpoints
@@ -57,7 +57,7 @@ public class CygwinGDBDebugger extends GDBDebugger {
if (p.size() > 0) {
String[] oldPaths = manager.getSharedLibraryPaths();
String[] paths = new String[oldPaths.length + p.size()];
- System.arraycopy((String[])p.toArray(new String[p.size()]), 0, paths, 0, p.size());
+ System.arraycopy((String[]) p.toArray(new String[p.size()]), 0, paths, 0, p.size());
System.arraycopy(oldPaths, 0, paths, p.size(), oldPaths.length);
manager.setSharedLibraryPaths(paths);
}
@@ -66,52 +66,90 @@ public class CygwinGDBDebugger extends GDBDebugger {
}
}
- public ICDISession createLaunchSession(
- ILaunchConfiguration config,
- IFile exe)
- throws CDIException {
- Session session = (Session) super.createLaunchSession(config, exe);
- session.getMISession().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}
- MISession mi = session.getMISession();
+ public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException {
+ Session session = null;
+ boolean failed = false;
try {
- CommandFactory factory = mi.getCommandFactory();
- MIGDBSet set = factory.createMIGDBSet(new String[]{"new-console"});
- mi.postCommand(set);
- MIInfo info = set.getMIInfo();
- if (info == null) {
- throw new MIException("No answer");
+ session = (Session) super.createLaunchSession(config, exe);
+ session.getMISession().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}
+ MISession mi = session.getMISession();
+ try {
+ CommandFactory factory = mi.getCommandFactory();
+ MIGDBSet set = factory.createMIGDBSet(new String[] { "new-console" });
+ mi.postCommand(set);
+ MIInfo info = set.getMIInfo();
+ if (info == null) {
+ throw new MIException("No answer");
+ }
+ } catch (MIException e) {
+ // We ignore this exception, for example
+ // on GNU/Linux the new-console is an error.
+ }
+ initializeLibraries(config, session);
+ return session;
+ } catch (CDIException e) {
+ failed = true;
+ throw e;
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
}
- } catch (MIException e) {
- // We ignore this exception, for example
- // on GNU/Linux the new-console is an error.
}
- initializeLibraries(config, session);
- return session;
}
- public ICDISession createAttachSession(
- ILaunchConfiguration config,
- IFile exe,
- int pid)
- throws CDIException {
- Session session =
- (Session) super.createAttachSession(config, exe, pid);
- session.getMISession().setCommandFactory(commandFactory);
- initializeLibraries(config, session);
- return session;
+ public ICDISession createAttachSession(ILaunchConfiguration config, IFile exe, int pid) throws CDIException {
+ Session session = null;
+ boolean failed = false;
+ try {
+ session = (Session) super.createAttachSession(config, exe, pid);
+ session.getMISession().setCommandFactory(commandFactory);
+ initializeLibraries(config, session);
+ return session;
+ } catch (CDIException e) {
+ failed = true;
+ throw e;
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
+ }
}
- public ICDISession createCoreSession(
- ILaunchConfiguration config,
- IFile exe,
- IPath corefile)
- throws CDIException {
- Session session =
- (Session) super.createCoreSession(config, exe, corefile);
- session.getMISession().setCommandFactory(commandFactory);
- initializeLibraries(config, session);
- return session;
+ public ICDISession createCoreSession(ILaunchConfiguration config, IFile exe, IPath corefile) throws CDIException {
+ Session session = null;
+ boolean failed = false;
+ try {
+ session = (Session) super.createCoreSession(config, exe, corefile);
+ session.getMISession().setCommandFactory(commandFactory);
+ initializeLibraries(config, session);
+ return session;
+ } catch (CDIException e) {
+ failed = true;
+ throw e;
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
+ }
}
}
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 5cede42edc8..596142daab2 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
@@ -61,54 +61,98 @@ public class GDBDebugger implements ICDebugger {
}
public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException {
+ Session session = null;
+ boolean failed = false;
try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
- Session session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit);
+ session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit);
initializeLibraries(config, session);
return session;
} catch (IOException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
} catch (MIException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
} catch (CoreException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
}
}
public ICDISession createAttachSession(ILaunchConfiguration config, IFile exe, int pid) throws CDIException {
+ Session session = null;
+ boolean failed = false;
try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
- Session 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);
initializeLibraries(config, session);
return session;
} catch (IOException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
} catch (MIException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
} catch (CoreException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
}
-
}
public ICDISession createCoreSession(ILaunchConfiguration config, IFile exe, IPath corefile) throws CDIException {
+ Session session = null;
+ boolean failed = false;
try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
- Session 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);
initializeLibraries(config, session);
return session;
} catch (IOException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
} catch (MIException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
} catch (CoreException e) {
+ failed = true;
throw new CDIException("Error creating session: " + e.getMessage());
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
}
}
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 158175c09a8..96c74584e6e 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
@@ -56,11 +56,12 @@ public class GDBServerDebugger implements ICDebugger {
}
public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException {
+ Session session = null;
+ boolean failed = false;
try {
String gdb = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
- Session session = null;
if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) {
String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, "invalid");
remote += ":";
@@ -82,25 +83,36 @@ public class GDBServerDebugger implements ICDebugger {
miSession.postCommand(setRemoteBaud, launchTimeout);
MIInfo info = setRemoteBaud.getMIInfo();
if (info == null) {
- session.terminate();
throw new MIException ("Can not set Baud");
}
MITargetSelect select = factory.createMITargetSelect(new String[] {"remote", remote});
miSession.postCommand(select, launchTimeout);
select.getMIInfo();
if (info == null) {
- session.terminate();
throw new MIException ("No answer");
}
}
initializeLibraries(config, session);
return session;
} catch (IOException e) {
+ failed = true;
throw new CDIException("Error initializing: " + e.getMessage());
} catch (MIException e) {
+ failed = true;
throw new CDIException("Error initializing: " + e.getMessage());
} catch (CoreException e) {
+ failed = true;
throw new CDIException("Error initializing: " + e.getMessage());
+ } finally {
+ if (failed) {
+ if (session != null) {
+ try {
+ session.terminate();
+ } catch (Exception ex) {
+ // ignore the exception here.
+ }
+ }
+ }
}
}
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 4f8afdc184a..6a10f45e9f4 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
@@ -9,6 +9,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.Reader;
import java.text.MessageFormat;
@@ -99,11 +100,39 @@ public class MIPlugin extends Plugin {
*/
public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit) throws IOException, MIException {
PTY pty = null;
+ boolean failed = false;
+
try {
pty = new PTY();
} catch (IOException e) {
}
- return createCSession(gdb, program, cwd, gdbinit, pty);
+
+ try {
+ return createCSession(gdb, program, cwd, gdbinit, pty);
+ } catch (IOException exc) {
+ failed = true;
+ throw exc;
+ } catch (MIException exc) {
+ failed = true;
+ throw exc;
+ } finally {
+ if (failed) {
+ // Shutdown the pty console.
+ if (pty != null) {
+ try {
+ OutputStream out = pty.getOutputStream();
+ if (out != null) {
+ out.close();
+ }
+ InputStream in = pty.getInputStream();
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
}
/**
@@ -290,7 +319,7 @@ public class MIPlugin extends Plugin {
}
/**
- * Do some basic synchronisation, gdb make take some time to load
+ * Do some basic synchronisation, gdb may take some time to load
* for whatever reasons.
* @param args
* @return Process
diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java
index 9cc6f531a7d..fa9af09a30b 100644
--- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java
+++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MISession.java
@@ -136,17 +136,35 @@ public class MISession extends Observable {
// Disable a certain number of irritations from gdb.
// Like confirmation and screen size.
- MIGDBSet confirm = new MIGDBSet(new String[]{"confirm", "off"});
- postCommand(confirm, launchTimeout);
- confirm.getMIInfo();
+ try {
+ MIGDBSet confirm = new MIGDBSet(new String[]{"confirm", "off"});
+ postCommand(confirm, launchTimeout);
+ confirm.getMIInfo();
+
+ MIGDBSet width = new MIGDBSet(new String[]{"width", "0"});
+ postCommand(width, launchTimeout);
+ confirm.getMIInfo();
- MIGDBSet width = new MIGDBSet(new String[]{"width", "0"});
- postCommand(width, launchTimeout);
- confirm.getMIInfo();
+ MIGDBSet height = new MIGDBSet(new String[]{"height", "0"});
+ postCommand(height, launchTimeout);
+ confirm.getMIInfo();
- MIGDBSet height = new MIGDBSet(new String[]{"height", "0"});
- postCommand(height, launchTimeout);
- confirm.getMIInfo();
+ } catch (MIException exc) {
+ // Kill the Transmition thread.
+ if (txThread.isAlive()) {
+ txThread.interrupt();
+ }
+ // Kill the Receiving Thread.
+ if (rxThread.isAlive()) {
+ rxThread.interrupt();
+ }
+ // Kill the event Thread.
+ if (eventThread.isAlive()) {
+ eventThread.interrupt();
+ }
+ // rethrow up the exception.
+ throw exc;
+ }
}
/**

Back to the top