From 9e8cd5b29b7ef3d1694e82034c1590109f7bcd57 Mon Sep 17 00:00:00 2001 From: John Cortell Date: Mon, 26 Apr 2010 22:58:22 +0000 Subject: [PATCH] Bug 304096: restore interrupt behavior for remote debugging case. --- .../eclipse/cdt/debug/mi/core/MIInferior.java | 23 ++++++++++++++++ .../debug/mi/core/GDBServerCDIDebugger2.java | 1 + .../cdt/debug/mi/core/MIProcessAdapter.java | 14 +++++++++- .../cdt/dsf/gdb/service/GDBBackend.java | 26 +++++++++++++++++-- 4 files changed, 61 insertions(+), 3 deletions(-) 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 952967874d9..4bb845afa7a 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 @@ -55,6 +55,10 @@ public class MIInferior extends Process { IMITTY tty; int inferiorPID; + + + /** See {@link #getIsRemoteInferior()} */ + private boolean fIsRemoteInferior; public MIInferior(MISession mi, IMITTY p) { session = mi; @@ -378,4 +382,23 @@ public class MIInferior extends Process { public int getInferiorPID() { return inferiorPID; } + + /** + * Called early on in the debug session to mark the inferior process as being + * under the control of a gdbserver. + * + * @since 7.0 + */ + public void setIsRemoteInferior(boolean value) { + fIsRemoteInferior = value; + } + + /** + * Is the inferior process being debugged remotely through gdbserver? + * + * @since 7.0 + */ + public boolean getIsRemoteInferior() { + return fIsRemoteInferior; + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger2.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger2.java index 766c8dec293..da14c80e0e8 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger2.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger2.java @@ -109,6 +109,7 @@ public class GDBServerCDIDebugger2 extends GDBCDIDebugger2 { // @@@ We have to set the suspended state manually miSession.getMIInferior().setSuspended(); miSession.getMIInferior().update(); + miSession.getMIInferior().setIsRemoteInferior(true); } } 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 9eca771b652..7c146c4f832 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 @@ -123,7 +123,19 @@ public class MIProcessAdapter implements MIProcess { if (fGDBProcess instanceof Spawner) { if (inferior.isRunning()) { Spawner gdbSpawner = (Spawner) fGDBProcess; - gdbSpawner.interruptCTRLC(); + + // Cygwin gdb 6.8 is capricious when it comes to interrupting the + // target. The same logic here will work with MinGW, though. And on + // linux it's irrelevant since interruptCTRLC()==interrupt(). So, + // one odd size fits all. + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=304096#c54 + if (inferior.getIsRemoteInferior()) { + gdbSpawner.interrupt(); + } + else { + gdbSpawner.interruptCTRLC(); + } + waitForInterrupt(inferior); } // If we are still running try to drop the sig to the PID diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java index 5a3ace0fae2..1fcf736b912 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java @@ -378,7 +378,18 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend { public void interrupt() { if (fProcess instanceof Spawner) { Spawner gdbSpawner = (Spawner) fProcess; - gdbSpawner.interruptCTRLC(); + + // Cygwin gdb 6.8 is capricious when it comes to interrupting the + // target. The same logic here will work with MinGW, though. And on + // linux it's irrelevant since interruptCTRLC()==interrupt(). So, + // one odd size fits all. + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=304096#c54 + if (getSessionType() == SessionType.REMOTE) { + gdbSpawner.interrupt(); + } + else { + gdbSpawner.interruptCTRLC(); + } } } @@ -388,7 +399,18 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend { public void interruptAndWait(int timeout, RequestMonitor rm) { if (fProcess instanceof Spawner) { Spawner gdbSpawner = (Spawner) fProcess; - gdbSpawner.interruptCTRLC(); + + // Cygwin gdb 6.8 is capricious when it comes to interrupting the + // target. The same logic here will work with MinGW, though. And on + // linux it's irrelevant since interruptCTRLC()==interrupt(). So, + // one odd size fits all. + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=304096#c54 + if (getSessionType() == SessionType.REMOTE) { + gdbSpawner.interrupt(); + } + else { + gdbSpawner.interruptCTRLC(); + } fInterruptFailedJob = new MonitorInterruptJob(timeout, rm); } else { rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.NOT_SUPPORTED, "Cannot interrupt.", null)); //$NON-NLS-1$