From dc88016beba4aa235c8a5cbbfddb006c2d359cf2 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Thu, 17 May 2007 18:51:41 +0000 Subject: [PATCH] Fix up interrupt signalling for cygwin and mingw gdb. As a side affect, mingw no longer pops up it's own console but prints to the console like other platforms do. --- .../debug/mi/core/command/CommandFactory.java | 8 +++ .../mi/core/command/MIGDBSetNewConsole.java | 6 +- .../factories/win32/CygwinCommandFactory.java | 19 ++++++ .../win32/StandardWinCommandFactory.java | 50 +++----------- .../debug/mi/core/CygwinMIProcessAdapter.java | 40 +++++++++++ .../eclipse/cdt/debug/mi/core/MIPlugin.java | 2 +- .../cdt/debug/mi/core/MIProcessAdapter.java | 66 ++++++------------- 7 files changed, 100 insertions(+), 91 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinMIProcessAdapter.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java index e4c1fc3ba7c..dfb129dd8a6 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java @@ -12,8 +12,12 @@ package org.eclipse.cdt.debug.mi.core.command; import java.io.File; +import java.io.IOException; import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.debug.mi.core.MIProcess; +import org.eclipse.cdt.debug.mi.core.MIProcessAdapter; +import org.eclipse.core.runtime.IProgressMonitor; /** @@ -438,4 +442,8 @@ public class CommandFactory { public String getWorkingDirectory(File cwd) { return "--cd=" + cwd.getAbsolutePath(); //$NON-NLS-1$ } + + public MIProcess createMIProcess(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException { + return new MIProcessAdapter(args, launchTimeout, monitor); + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIGDBSetNewConsole.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIGDBSetNewConsole.java index cfb74d4fc55..03a1a6c0f7e 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIGDBSetNewConsole.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIGDBSetNewConsole.java @@ -3,7 +3,11 @@ package org.eclipse.cdt.debug.mi.core.command; public class MIGDBSetNewConsole extends MIGDBSet { public MIGDBSetNewConsole(String miVersion) { - super(miVersion, new String[] {"new-console"}); //$NON-NLS-1$ + this(miVersion, "on"); + } + + public MIGDBSetNewConsole(String miVersion, String param) { + super(miVersion, new String[] {"new-console", param}); //$NON-NLS-1$ } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinCommandFactory.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinCommandFactory.java index 2244472aad4..e3d7c692329 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinCommandFactory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/CygwinCommandFactory.java @@ -10,7 +10,13 @@ *******************************************************************************/ package org.eclipse.cdt.debug.mi.core.command.factories.win32; +import java.io.IOException; + +import org.eclipse.cdt.debug.mi.core.CygwinMIProcessAdapter; +import org.eclipse.cdt.debug.mi.core.MIProcess; import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory; +import org.eclipse.cdt.debug.mi.core.command.MIGDBSetNewConsole; +import org.eclipse.core.runtime.IProgressMonitor; /** * Command factory for the gdb/mi protocol for CygWin environment. @@ -34,4 +40,17 @@ public class CygwinCommandFactory extends StandardWinCommandFactory { public MIEnvironmentDirectory createMIEnvironmentDirectory(boolean reset, String[] pathdirs) { return new CygwinMIEnvironmentDirectory( getMIVersion(), reset, pathdirs ); } + + public MIGDBSetNewConsole createMIGDBSetNewConsole() { + // With cygwin, the Ctrl-C isn't getting propagated to the + // inferior. Thus we need to have the inferior in it's own + // console so that the fall back of sending it the interrupt + // signal works. + return new MIGDBSetNewConsole(getMIVersion(), "on"); + } + + public MIProcess createMIProcess(String[] args, int launchTimeout, + IProgressMonitor monitor) throws IOException { + return new CygwinMIProcessAdapter(args, launchTimeout, monitor); + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/StandardWinCommandFactory.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/StandardWinCommandFactory.java index 2b8134075e9..20ed3097aa8 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/StandardWinCommandFactory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/win32/StandardWinCommandFactory.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.mi.core.command.factories.win32; import org.eclipse.cdt.debug.mi.core.command.CLIInfoSharedLibrary; import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentCD; import org.eclipse.cdt.debug.mi.core.command.MIGDBSetAutoSolib; +import org.eclipse.cdt.debug.mi.core.command.MIGDBSetNewConsole; import org.eclipse.cdt.debug.mi.core.command.MIGDBSetSolibSearchPath; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowSolibSearchPath; import org.eclipse.cdt.debug.mi.core.command.factories.StandardCommandFactory; @@ -36,107 +37,72 @@ public class StandardWinCommandFactory extends StandardCommandFactory { super( miVersion ); } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.CommandFactory#createMIEnvironmentCD(java.lang.String) - */ public MIEnvironmentCD createMIEnvironmentCD( String pathdir ) { return new WinMIEnvironmentCD( getMIVersion(), pathdir ); } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.CommandFactory#createCLIInfoSharedLibrary() - */ public CLIInfoSharedLibrary createCLIInfoSharedLibrary() { return new WinCLIInfoSharedLibrary(); } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.CommandFactory#createMIGDBSetAutoSolib(boolean) - */ public MIGDBSetAutoSolib createMIGDBSetAutoSolib( boolean set ) { // Suppress "set auto-solib" - returns error on Windows return new MIGDBSetAutoSolib( getMIVersion(), true ) { - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getOperation() - */ public String getOperation() { return ""; //$NON-NLS-1$ } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getOptions() - */ public String[] getOptions() { return new String[0]; } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getParameters() - */ public String[] getParameters() { return new String[0]; } }; } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.CommandFactory#createMIGDBShowSolibSearchPath() - */ public MIGDBShowSolibSearchPath createMIGDBShowSolibSearchPath() { // Suppress "show solib-search-path" - returns error on Windows return new MIGDBShowSolibSearchPath( getMIVersion() ) { - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getOperation() - */ public String getOperation() { return ""; //$NON-NLS-1$ } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getOptions() - */ public String[] getOptions() { return new String[0]; } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getParameters() - */ public String[] getParameters() { return new String[0]; } }; } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.CommandFactory#createMIGDBSetSolibSearchPath(java.lang.String[]) - */ public MIGDBSetSolibSearchPath createMIGDBSetSolibSearchPath( String[] params ) { // Suppress "set solib-search-path" - returns error on Windows return new MIGDBSetSolibSearchPath( getMIVersion(), params ) { - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getOperation() - */ public String getOperation() { return ""; //$NON-NLS-1$ } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getOptions() - */ public String[] getOptions() { return new String[0]; } - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.mi.core.command.MICommand#getParameters() - */ public String[] getParameters() { return new String[0]; } }; } + + public MIGDBSetNewConsole createMIGDBSetNewConsole() { + // By default in Windows, turn off new console so that the + // Ctrl-C's get propogated automatically to the inferior. + // Overriden by Cygwin. + return new MIGDBSetNewConsole(getMIVersion(), "off"); + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinMIProcessAdapter.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinMIProcessAdapter.java new file mode 100644 index 00000000000..c938a255a32 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/CygwinMIProcessAdapter.java @@ -0,0 +1,40 @@ +/********************************************************************** + * Copyright (c) 2007 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + **********************************************************************/ + +package org.eclipse.cdt.debug.mi.core; + +import java.io.IOException; + +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * @author Doug Schaefer + */ +public class CygwinMIProcessAdapter extends MIProcessAdapter { + + /** + * @param args + * @param launchTimeout + * @param monitor + * @throws IOException + */ + public CygwinMIProcessAdapter(String[] args, int launchTimeout, + IProgressMonitor monitor) throws IOException { + super(args, launchTimeout, monitor); + } + + public void interrupt(MIInferior inferior) { + // With cygwin gdb, interrupting gdb itself never works. + // You need to interrupt the inferior directly. + interruptInferior(inferior); + } + +} 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 9f5cc997dae..6359e6ac3e0 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 @@ -445,7 +445,7 @@ public class MIPlugin extends Plugin { MIProcess pgdb = null; boolean failed = false; try { - pgdb = new MIProcessAdapter(args, launchTimeout, monitor); + pgdb = factory.createMIProcess(args, launchTimeout, monitor); if (MIPlugin.getDefault().isDebugging()) { StringBuffer sb = new StringBuffer(); 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 c6afb261245..0e0d0ae6a79 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 @@ -106,20 +106,10 @@ public class MIProcessAdapter implements MIProcess { return pgdb; } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.mi.core.MIProcess#canInterrupt() - */ public boolean canInterrupt(MIInferior inferior) { return fGDBProcess instanceof Spawner; } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.mi.core.MIProcess#interrupt() - */ public void interrupt(MIInferior inferior) { if (fGDBProcess instanceof Spawner) { Spawner gdbSpawner = (Spawner) fGDBProcess; @@ -136,70 +126,52 @@ public class MIProcessAdapter implements MIProcess { // If we are still running try to drop the sig to the PID if (inferior.isRunning() && inferior.getInferiorPID() > 0) { // lets try something else. - gdbSpawner.raise(inferior.getInferiorPID(), gdbSpawner.INT); - synchronized (inferior) { - for (int i = 0; inferior.isRunning() && i < 5; i++) { - try { - inferior.wait(1000); - } catch (InterruptedException e) { - } - } - } + interruptInferior(inferior); } } } - /* - * (non-Javadoc) + /** + * Send an interrupt to the inferior process. * - * @see java.lang.Process#exitValue() + * @param inferior */ + protected void interruptInferior(MIInferior inferior) { + if (fGDBProcess instanceof Spawner) { + Spawner gdbSpawner = (Spawner) fGDBProcess; + gdbSpawner.raise(inferior.getInferiorPID(), gdbSpawner.INT); + synchronized (inferior) { + for (int i = 0; inferior.isRunning() && i < 5; i++) { + try { + inferior.wait(1000); + } catch (InterruptedException e) { + } + } + } + } + } + public int exitValue() { return fGDBProcess.exitValue(); } - /* - * (non-Javadoc) - * - * @see java.lang.Process#waitFor() - */ public int waitFor() throws InterruptedException { return fGDBProcess.waitFor(); } - /* - * (non-Javadoc) - * - * @see java.lang.Process#destroy() - */ public void destroy() { fGDBProcess.destroy(); } - /* - * (non-Javadoc) - * - * @see java.lang.Process#getErrorStream() - */ public InputStream getErrorStream() { return fGDBProcess.getErrorStream(); } - /* - * (non-Javadoc) - * - * @see java.lang.Process#getInputStream() - */ public InputStream getInputStream() { return fGDBProcess.getInputStream(); } - /* - * (non-Javadoc) - * - * @see java.lang.Process#getOutputStream() - */ public OutputStream getOutputStream() { return fGDBProcess.getOutputStream(); }