Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2015-11-04 14:03:54 +0000
committerAnton Leherbauer2015-11-04 14:04:19 +0000
commitd18eb6e07e63aa067233c219cdc7baf890ac642b (patch)
tree16cae8d476bd88c5ad9ed5be5e372dbba84b710d /target_explorer
parent7134719a5d5b3b1ab4fc29fabb8cf5347e64a6d2 (diff)
downloadorg.eclipse.tcf-d18eb6e07e63aa067233c219cdc7baf890ac642b.tar.gz
org.eclipse.tcf-d18eb6e07e63aa067233c219cdc7baf890ac642b.tar.xz
org.eclipse.tcf-d18eb6e07e63aa067233c219cdc7baf890ac642b.zip
Target Explorer: Fix termination of gdb if started as Windows batch script
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java
index 0cdc4f562..52020bffd 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.cdt/src/org/eclipse/tcf/te/tcf/launch/cdt/launching/TEGdbAbstractLaunchDelegate.java
@@ -28,12 +28,17 @@ import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
import org.eclipse.cdt.dsf.concurrent.ImmediateRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.Query;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
+import org.eclipse.cdt.dsf.debug.service.command.IEventListener;
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunchDelegate;
+import org.eclipse.cdt.dsf.gdb.service.IGDBBackend;
import org.eclipse.cdt.dsf.gdb.service.IGDBProcesses;
import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl;
+import org.eclipse.cdt.dsf.mi.service.command.output.MIOOBRecord;
+import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput;
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
+import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -53,6 +58,7 @@ import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.te.core.utils.text.StringUtil;
import org.eclipse.tcf.te.runtime.callback.Callback;
import org.eclipse.tcf.te.runtime.services.ServiceUtils;
+import org.eclipse.tcf.te.runtime.utils.Host;
import org.eclipse.tcf.te.tcf.core.streams.StreamsDataReceiver;
import org.eclipse.tcf.te.tcf.launch.cdt.activator.Activator;
import org.eclipse.tcf.te.tcf.launch.cdt.interfaces.IGdbserverLaunchHandlerDelegate;
@@ -352,6 +358,7 @@ public abstract class TEGdbAbstractLaunchDelegate extends GdbLaunchDelegate {
@Override
protected void launchDebugSession(ILaunchConfiguration config, ILaunch l, IProgressMonitor monitor) throws CoreException {
super.launchDebugSession(config, l, monitor);
+ addWindowsBatchJobTerminator(l);
// Determine if the launch is an attach launch
final boolean isAttachLaunch = ICDTLaunchConfigurationConstants.ID_LAUNCH_C_ATTACH.equals(config.getType().getIdentifier());
@@ -401,6 +408,45 @@ public abstract class TEGdbAbstractLaunchDelegate extends GdbLaunchDelegate {
}
/**
+ * On Windows, if gdb was started as part of a batch script, the script does not exit silently
+ * if it has been interrupted before. Therefore we listen for the "Terminate batch job (Y/N)?"
+ * prompt to terminate the script by force instead.
+ *
+ * @param launch
+ */
+ private void addWindowsBatchJobTerminator(ILaunch launch) {
+ if (Host.isWindowsHost() && launch instanceof GdbLaunch) {
+ final DsfSession s = ((GdbLaunch) launch).getSession();
+ s.getExecutor().execute(new Runnable() {
+ @Override
+ public void run() {
+ DsfServicesTracker tracker = new DsfServicesTracker(Activator.getDefault().getBundle().getBundleContext(), s.getId());
+ try {
+ final IGDBBackend backend = tracker.getService(IGDBBackend.class);
+ final IGDBControl commandControl = tracker.getService(IGDBControl.class);
+ commandControl.addEventListener(new IEventListener() {
+ @Override
+ public void eventReceived(Object output) {
+ if (output instanceof MIOutput) {
+ MIOOBRecord[] oobs = ((MIOutput) output).getMIOOBRecords();
+ if (oobs != null && oobs.length > 0) {
+ String out = oobs[0].toString();
+ if (out.contains("Terminate batch job (Y/N)?")) { //$NON-NLS-1$
+ backend.destroy();
+ }
+ }
+ }
+ }
+ });
+ } finally {
+ tracker.dispose();
+ }
+ }
+ });
+ }
+ }
+
+ /**
* Shutdown the GDB debug session.
* This method always throws a CoreException and does not return.
*

Back to the top