mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 03:15:33 +02:00
Make sure the session is terminated if
an exception is thrown.
This commit is contained in:
parent
8dd35316c0
commit
6bfd40852c
5 changed files with 204 additions and 63 deletions
|
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue