diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index b701919c7f3..a428e81bd43 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,17 @@ +2005-07-18 Alain Magloire + GDB has now four different version of MI, so it has become + important to give the user the choice of the version. + * mi/org/eclipse/cdt/debug/mi/core/MISession.java + * mi/org/eclipse/cdt/debug/mi/core/RxThread.java + * mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java + * mi/org/eclipse/cdt/debug/mi/core/command/MICommand.java + + mi/org/eclipse/cdt/debug/mi/core/command/MIVersion.java + * src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java + * src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java + * src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger.java + * src/org/eclipse/cdt/debug/mi/core/MIPlugin.java + * src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java + 2005-07-10 Alain Magloire Fix for PR 100992: Setting breakpoints for methods * cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java index 5bbe410d81d..40bc98bf73f 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/MISession.java @@ -27,11 +27,14 @@ import org.eclipse.cdt.debug.mi.core.command.MIGDBSet; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowExitCode; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowPrompt; import org.eclipse.cdt.debug.mi.core.command.MIInterpreterExecConsole; +import org.eclipse.cdt.debug.mi.core.command.MIVersion; import org.eclipse.cdt.debug.mi.core.event.MIEvent; import org.eclipse.cdt.debug.mi.core.event.MIGDBExitEvent; import org.eclipse.cdt.debug.mi.core.output.MIGDBShowInfo; import org.eclipse.cdt.debug.mi.core.output.MIOutput; import org.eclipse.cdt.debug.mi.core.output.MIParser; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; /** * Represents a GDB/MI session. @@ -88,27 +91,56 @@ public class MISession extends Observable { MIInferior inferior; /** - * Create the gdb session. + * @param process + * @param tty + * @param type + * @param commandTimeout + * @param launchTimeout + * @param miVersion + * @param monitor + * @throws MIException + */ + public MISession(MIProcess process, IMITTY tty, int type, int commandTimeout, int launchTimeout, String miVersion, IProgressMonitor monitor) throws MIException { + this(process, tty, type, new CommandFactory(miVersion), commandTimeout, launchTimeout, monitor); + } + + + /** + * Create the gdb session. Assume MIVersion 1 * + * @deprecated use the other constructors with the MIVersion * @param Process gdb Process. * @param pty Terminal to use for the inferior. * @param timeout time in milliseconds to wait for command response. * @param type the type of debugin session. */ - public MISession(MIProcess process, IMITTY tty, int timeout, int type, int launchTimeout) throws MIException { - - // Assume mi1 for now - String miVersion = "mi1"; //$NON-NLS-1$ - + public MISession(MIProcess process, IMITTY tty, int commandTimeout, int type, int launchTimeout) throws MIException { + this(process, tty, type, commandTimeout, launchTimeout, MIVersion.MI1, new NullProgressMonitor()); + if (useExecConsole()) { + // if exec console is present, assume MI2 supported + setCommandFactory(new CommandFactory(MIVersion.MI2)); + } + } + + /** + * Create the gdb session. + * + * @param type the type of debugging session. + * @param commandFactory the MI command factory + * @param Process gdb Process. + * @param pty Terminal to use for the inferior. + * @param timeout time in milliseconds to wait for command response. + */ + public MISession(MIProcess process, IMITTY tty, int type, CommandFactory commandFactory, int commandTimeout, int launchTimeout, IProgressMonitor monitor) throws MIException { gdbProcess = process; inChannel = process.getInputStream(); outChannel = process.getOutputStream(); - cmdTimeout = timeout; + factory = commandFactory; + cmdTimeout = commandTimeout; sessionType = type; - parser = new MIParser(); inferior = new MIInferior(this, tty); @@ -116,12 +148,21 @@ public class MISession extends Observable { txQueue = new CommandQueue(); rxQueue = new CommandQueue(); eventQueue = new Queue(); + + txThread = new TxThread(this); + rxThread = new RxThread(this); + eventThread = new EventThread(this); + // initialize/setup + setup(launchTimeout, new NullProgressMonitor()); + } + + protected void setup(int launchTimeout, IProgressMonitor monitor) throws MIException { // The Process may have terminated earlier because // of bad arguments etc .. check this here and bail out. try { - process.exitValue(); - InputStream err = process.getErrorStream(); + gdbProcess.exitValue(); + InputStream err = gdbProcess.getErrorStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(err)); String line = null; try { @@ -137,54 +178,21 @@ public class MISession extends Observable { } catch (IllegalThreadStateException e) { // Ok, it means the process is alive. } - - txThread = new TxThread(this); - rxThread = new RxThread(this); - eventThread = new EventThread(this); + + if (monitor.isCanceled()) { + throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$ + } txThread.start(); rxThread.start(); eventThread.start(); - - // Disable a certain number of irritations from gdb. - // Like confirmation and screen size. - - try { - MIGDBSet confirm = new MIGDBSet(miVersion, new String[]{"confirm", "off"}); //$NON-NLS-1$ //$NON-NLS-2$ - postCommand(confirm, launchTimeout); - confirm.getMIInfo(); - - MIGDBSet width = new MIGDBSet(miVersion, new String[]{"width", "0"}); //$NON-NLS-1$ //$NON-NLS-2$ - postCommand(width, launchTimeout); - width.getMIInfo(); - - MIGDBSet height = new MIGDBSet(miVersion, new String[]{"height", "0"}); //$NON-NLS-1$ //$NON-NLS-2$ - postCommand(height, launchTimeout); - height.getMIInfo(); - - // Try to discover is "-interpreter-exec" is supported. - try { - MIInterpreterExecConsole echo = new MIInterpreterExecConsole(miVersion, "echo"); //$NON-NLS-1$ - postCommand(echo, launchTimeout); - echo.getMIInfo(); - useInterpreterExecConsole = true; - } catch (MIException e) { - // - } - - // Get GDB's prompt - MIGDBShowPrompt prompt = new MIGDBShowPrompt(miVersion); - postCommand(prompt); - MIGDBShowInfo infoPrompt = prompt.getMIGDBShowInfo(); - String value = infoPrompt.getValue(); - if (value != null && value.length() > 0) { - parser.cliPrompt = value.trim(); - } - if (useInterpreterExecConsole) { - miVersion = "mi2"; //$NON-NLS-1$ - } - factory = new CommandFactory(miVersion); //$NON-NI + try { + if (monitor.isCanceled()) { + throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$ + } + + initialize(launchTimeout, monitor); } catch (MIException exc) { // Kill the Transmition thread. if (txThread.isAlive()) { @@ -202,6 +210,69 @@ public class MISession extends Observable { throw exc; } } + + protected void initialize(int launchTimeout, IProgressMonitor monitor) throws MIException { + // Disable a certain number of irritations from gdb. + // Like confirmation and screen size. + MIGDBSet confirm = getCommandFactory().createMIGDBSet(new String[]{"confirm", "off"}); //$NON-NLS-1$ //$NON-NLS-2$ + postCommand(confirm, launchTimeout); + confirm.getMIInfo(); + if (monitor.isCanceled()) { + throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$ + } + + MIGDBSet width = getCommandFactory().createMIGDBSet(new String[]{"width", "0"}); //$NON-NLS-1$ //$NON-NLS-2$ + postCommand(width, launchTimeout); + width.getMIInfo(); + if (monitor.isCanceled()) { + throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$ + } + + MIGDBSet height = getCommandFactory().createMIGDBSet(new String[]{"height", "0"}); //$NON-NLS-1$ //$NON-NLS-2$ + postCommand(height, launchTimeout); + height.getMIInfo(); + if (monitor.isCanceled()) { + throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$ + } + + useInterpreterExecConsole = canUseInterpreterExecConsole(); + if (monitor.isCanceled()) { + throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$ + } + + String prompt = getCLIPrompt(); + if (monitor.isCanceled()) { + throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$ + } + if (prompt != null) { + getMIParser().cliPrompt = prompt; + } + } + + protected boolean canUseInterpreterExecConsole() { + // Try to discover if "-interpreter-exec" is supported. + try { + MIInterpreterExecConsole echo = getCommandFactory().createMIInterpreterExecConsole("echo"); //$NON-NLS-1$ + postCommand(echo); + echo.getMIInfo(); + return true; + } catch (MIException e) { + // + } + return false; + } + + protected String getCLIPrompt() throws MIException { + // Get GDB's prompt + MIGDBShowPrompt prompt = getCommandFactory().createMIGDBShowPrompt(); + postCommand(prompt); + MIGDBShowInfo infoPrompt = prompt.getMIGDBShowInfo(); + String value = infoPrompt.getValue(); + if (value != null && value.length() > 0) { + return value.trim(); + } + return null; + } /** * get MI Console Stream. @@ -364,7 +435,7 @@ public class MISession extends Observable { } postCommand0(cmd, timeout); } - + /** * if timeout < 0 the operation will not try to way for * answer from gdb. @@ -375,7 +446,9 @@ public class MISession extends Observable { */ public synchronized void postCommand0(Command cmd, long timeout) throws MIException { // TRACING: print the command; - MIPlugin.getDefault().debugLog(cmd.toString()); + if (MIPlugin.getDefault().isDebugging()) { + MIPlugin.getDefault().debugLog(cmd.toString()); + } txQueue.addCommand(cmd); @@ -457,7 +530,7 @@ public class MISession extends Observable { // Although we will close the pipe(). It is cleaner // to give a chance to gdb to cleanup. // send the exit(-gdb-exit). But we only wait a maximum of 2 sec. - MIGDBExit exit = factory.createMIGDBExit(); + MIGDBExit exit = getCommandFactory().createMIGDBExit(); try { postCommand0(exit, 2000); } catch (MIException e) { @@ -548,12 +621,17 @@ public class MISession extends Observable { super.notifyObservers(arg); } - OutputStream getConsolePipe() { + if (miOutConsolePipe == null) { + getMIConsoleStream(); + } return miOutConsolePipe; } OutputStream getLogPipe() { + if (miOutLogPipe == null) { + getMILogStream(); + } return miOutLogPipe; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/RxThread.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/RxThread.java index 15639f70a37..173ad28f597 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/RxThread.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/RxThread.java @@ -86,7 +86,9 @@ public class RxThread extends Thread { String line; while ((line = reader.readLine()) != null) { // TRACING: print the output. - MIPlugin.getDefault().debugLog(line); + if (MIPlugin.getDefault().isDebugging()) { + MIPlugin.getDefault().debugLog(line); + } setPrompt(line); processMIOutput(line + "\n"); //$NON-NLS-1$ } 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 e2acee8c6ba..2e4568712d3 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 @@ -228,6 +228,10 @@ public class CommandFactory { return new MIGDBShow(getMIVersion(), params); } + public MIGDBShowPrompt createMIGDBShowPrompt() { + return new MIGDBShowPrompt(getMIVersion()); + } + public MIGDBShowExitCode createMIGDBShowExitCode() { return new MIGDBShowExitCode(getMIVersion()); } @@ -349,7 +353,7 @@ public class CommandFactory { } public MIVarCreate createMIVarCreate(String name, String frameAddr, String expression) { - return new MIVarCreate(name, frameAddr, expression); + return new MIVarCreate(getMIVersion(), name, frameAddr, expression); } public MIVarDelete createMIVarDelete(String name) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MICommand.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MICommand.java index eb7efa3e195..c7e0dfb2795 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MICommand.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MICommand.java @@ -58,7 +58,7 @@ public class MICommand extends Command { * @return */ public boolean isMI1() { - return "mi1".equalsIgnoreCase(fMIVersion); //$NON-NLS-1$ + return MIVersion.MI1.equalsIgnoreCase(fMIVersion); //$NON-NLS-1$ } /** @@ -66,7 +66,7 @@ public class MICommand extends Command { * @return */ public boolean isMI2() { - return "mi2".equalsIgnoreCase(fMIVersion); //$NON-NLS-1$ + return MIVersion.MI2.equalsIgnoreCase(fMIVersion); //$NON-NLS-1$ } /** diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIVersion.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIVersion.java new file mode 100644 index 00000000000..8bf49e43f1d --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIVersion.java @@ -0,0 +1,20 @@ +package org.eclipse.cdt.debug.mi.core.command; + +/** + * TODO: Make this an enum type. + * MI Version constants. + */ +public class MIVersion { + + public static final String MI1 = "mi1"; //$NON-NLS-1$ + public static final String MI2 = "mi2"; //$NON-NLS-1$ + public static final String MI3 = "mi3"; //$NON-NLS-1$ + + public static int compare(String v1, String v2) { + return v1.compareToIgnoreCase(v2); + } + + public static boolean equals(String v1, String v2) { + return v1.equalsIgnoreCase(v2); + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java index ccd95248fa8..94fb5efe636 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java @@ -94,13 +94,14 @@ public class GDBCDIDebugger implements ICDIDebugger { boolean failed = false; try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ + String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$ boolean usePty = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true); File cwd = getProjectPath(config).toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ if (usePty) { - session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), cwd, gdbinit, monitor); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), cwd, gdbinit, monitor); } else { - session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), cwd, gdbinit, null, monitor); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), cwd, gdbinit, null, monitor); } initializeLibraries(config, session); return session; @@ -129,11 +130,12 @@ public class GDBCDIDebugger implements ICDIDebugger { boolean failed = false; try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ + String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$ int pid = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, -1); File cwd = getProjectPath(config).toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ File exeFile = exe != null ? exe.getPath().toFile() : null; - session = MIPlugin.getDefault().createCSession(gdb, exeFile, pid, null, cwd, gdbinit, monitor); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exeFile, pid, null, cwd, gdbinit, monitor); initializeLibraries(config, session); return session; } catch (Exception e) { @@ -161,10 +163,11 @@ public class GDBCDIDebugger implements ICDIDebugger { boolean failed = false; try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ + String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$ File cwd = getProjectPath(config).toFile(); IPath coreFile = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, (String)null)); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ - session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), coreFile.toFile(), cwd, gdbinit, monitor); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), coreFile.toFile(), cwd, gdbinit, monitor); initializeLibraries(config, session); return session; } catch (Exception e) { 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 67545f2e7e3..513ed420791 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 @@ -15,6 +15,7 @@ import java.io.IOException; import java.util.Collections; import java.util.List; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugger; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDISession; @@ -73,9 +74,10 @@ public class GDBDebugger implements ICDebugger { boolean failed = false; try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ + String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$ File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ - session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit, null); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), cwd, gdbinit, null); initializeLibraries(config, session); return session; } catch (IOException e) { @@ -105,9 +107,10 @@ public class GDBDebugger implements ICDebugger { boolean failed = false; try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ + String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$ File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ - session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit, null); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), pid, null, cwd, gdbinit, null); initializeLibraries(config, session); return session; } catch (IOException e) { @@ -137,9 +140,10 @@ public class GDBDebugger implements ICDebugger { boolean failed = false; try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ + String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$ File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ - session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit, null); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit, null); initializeLibraries(config, session); return session; } catch (IOException e) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger.java index 165ef39de0e..a5c70c5bc79 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.debug.mi.core; import java.io.File; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.mi.core.cdi.Session; import org.eclipse.cdt.debug.mi.core.cdi.model.Target; @@ -43,6 +44,7 @@ public class GDBServerCDIDebugger extends GDBCDIDebugger { boolean failed = false; try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ + String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$ File cwd = getProjectPath(config).toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) { @@ -50,7 +52,7 @@ public class GDBServerCDIDebugger extends GDBCDIDebugger { remote += ":"; //$NON-NLS-1$ remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); //$NON-NLS-1$ String[] args = new String[] {"remote", remote}; //$NON-NLS-1$ - session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), 0, args, cwd, gdbinit, monitor); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), 0, args, cwd, gdbinit, monitor); } else { MIPlugin plugin = MIPlugin.getDefault(); Preferences prefs = plugin.getPluginPreferences(); @@ -58,7 +60,7 @@ public class GDBServerCDIDebugger extends GDBCDIDebugger { String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); //$NON-NLS-1$ String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid"); //$NON-NLS-1$ - session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), -1, null, cwd, gdbinit, monitor); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), -1, null, cwd, gdbinit, monitor); ICDITarget[] targets = session.getTargets(); for (int i = 0; i < targets.length; ++i) { Target target = (Target)targets[i]; 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 8565a374163..77210872a4a 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 @@ -16,6 +16,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugger; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDISession; @@ -63,6 +64,7 @@ public class GDBServerDebugger implements ICDebugger { boolean failed = false; try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ + String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$ File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) { @@ -70,7 +72,7 @@ public class GDBServerDebugger implements ICDebugger { remote += ":"; //$NON-NLS-1$ remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); //$NON-NLS-1$ String[] args = new String[] {"remote", remote}; //$NON-NLS-1$ - session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), 0, args, cwd, gdbinit, null); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), 0, args, cwd, gdbinit, null); } else { MIPlugin plugin = MIPlugin.getDefault(); Preferences prefs = plugin.getPluginPreferences(); @@ -78,7 +80,7 @@ public class GDBServerDebugger implements ICDebugger { String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); //$NON-NLS-1$ String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid"); //$NON-NLS-1$ - session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), -1, null, cwd, gdbinit, null); + session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), -1, null, cwd, gdbinit, null); ICDITarget[] targets = session.getTargets(); for (int i = 0; i < targets.length; ++i) { Target target = (Target)targets[i]; 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 6ea867a8d07..6edd1214544 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 @@ -17,11 +17,13 @@ import java.io.OutputStream; import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.ResourceBundle; + import org.eclipse.cdt.debug.mi.core.cdi.Session; +import org.eclipse.cdt.debug.mi.core.command.CLITargetAttach; import org.eclipse.cdt.debug.mi.core.command.CommandFactory; import org.eclipse.cdt.debug.mi.core.command.MIStackListFrames; -import org.eclipse.cdt.debug.mi.core.command.CLITargetAttach; import org.eclipse.cdt.debug.mi.core.command.MITargetSelect; +import org.eclipse.cdt.debug.mi.core.command.MIVersion; import org.eclipse.cdt.debug.mi.core.output.MIInfo; import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.core.runtime.IProgressMonitor; @@ -60,7 +62,7 @@ public class MIPlugin extends Plugin { } /** * The constructor - * @see org.eclipse.core.runtime.Plugin#Plugin(IPluginDescriptor) + * @see org.eclipse.core.runtime.Plugin#Plugin() */ public MIPlugin() { super(); @@ -83,8 +85,8 @@ public class MIPlugin extends Plugin { * @throws MIException * @return MISession */ - public MISession createMISession(MIProcess process, IMITTY pty, int timeout, int type, int launchTimeout) throws MIException { - return new MISession(process, pty, timeout, type, launchTimeout); + public MISession createMISession(MIProcess process, IMITTY pty, int timeout, int type, int launchTimeout, String miVersion, IProgressMonitor monitor) throws MIException { + return new MISession(process, pty, type, timeout, launchTimeout, miVersion, monitor); } /** @@ -95,21 +97,22 @@ public class MIPlugin extends Plugin { * @throws MIException * @return MISession */ - public MISession createMISession(MIProcess process, IMITTY pty, int type) throws MIException { + public MISession createMISession(MIProcess process, IMITTY pty, int type, String miVersion, IProgressMonitor monitor) throws MIException { MIPlugin miPlugin = getDefault(); Preferences prefs = miPlugin.getPluginPreferences(); int timeout = prefs.getInt(IMIConstants.PREF_REQUEST_TIMEOUT); int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); - return createMISession(process, pty, timeout, type, launchTimeout); + return createMISession(process, pty, timeout, type, launchTimeout, miVersion, monitor); } /** - * Method createCSession. + * Method createCSession; Create an new PTY instance and launch gdb in mi for local debug. + * * @param program * @return ICDISession * @throws MIException */ - public Session createCSession(String gdb, File program, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { + public Session createCSession(String gdb, String miVersion, File program, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { IMITTY pty = null; boolean failed = false; @@ -121,7 +124,7 @@ public class MIPlugin extends Plugin { } try { - return createCSession(gdb, program, cwd, gdbinit, pty, monitor); + return createCSession(gdb, miVersion, program, cwd, gdbinit, pty, monitor); } catch (IOException exc) { failed = true; throw exc; @@ -149,12 +152,12 @@ public class MIPlugin extends Plugin { } /** - * Method createCSession. + * Method createCSession; lauch gdb in mi mode for local debugging * @param program * @return ICDISession * @throws IOException */ - public Session createCSession(String gdb, File program, File cwd, String gdbinit, IMITTY pty, IProgressMonitor monitor) throws IOException, MIException { + public Session createCSession(String gdb, String miVersion, File program, File cwd, String gdbinit, IMITTY pty, IProgressMonitor monitor) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = GDB; } @@ -170,23 +173,33 @@ public class MIPlugin extends Plugin { String[] args; if (pty != null) { if (program == null) { - args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", "mi"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", miVersion}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ } else { - args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", "mi", program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", miVersion, program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ } } else { if (program == null) { - args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", "mi"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", miVersion}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } else { - args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", "mi", program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", miVersion, program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } } - MIProcess pgdb = new MIProcessAdapter(args, monitor); + int launchTimeout = MIPlugin.getDefault().getPluginPreferences().getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); + MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor); + if (MIPlugin.getDefault().isDebugging()) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < args.length; ++i) { + sb.append(args[i]); + sb.append(' '); + } + MIPlugin.getDefault().debugLog(sb.toString()); + } + MISession session; try { - session = createMISession(pgdb, pty, MISession.PROGRAM); + session = createMISession(pgdb, pty, MISession.PROGRAM, miVersion, monitor); } catch (MIException e) { pgdb.destroy(); throw e; @@ -213,13 +226,13 @@ public class MIPlugin extends Plugin { } /** - * Method createCSession. + * Method createCSession; Post mortem debug with a core file. * @param program * @param core * @return ICDISession * @throws IOException */ - public Session createCSession(String gdb, File program, File core, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { + public Session createCSession(String gdb, String miVersion, File program, File core, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = GDB; } @@ -234,14 +247,26 @@ public class MIPlugin extends Plugin { String[] args; if (program == null) { - args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi", "-c", core.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", miVersion, "-c", core.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ } else { - args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi", "-c", core.getAbsolutePath(), program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", miVersion, "-c", core.getAbsolutePath(), program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ } - MIProcess pgdb = new MIProcessAdapter(args, monitor); + + int launchTimeout = MIPlugin.getDefault().getPluginPreferences().getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); + MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor); + + if (MIPlugin.getDefault().isDebugging()) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < args.length; ++i) { + sb.append(args[i]); + sb.append(' '); + } + MIPlugin.getDefault().debugLog(sb.toString()); + } + MISession session; try { - session = createMISession(pgdb, null, MISession.CORE); + session = createMISession(pgdb, null, MISession.CORE, miVersion, monitor); //@@@ We have to manually set the suspended state when doing post-mortem session.getMIInferior().setSuspended(); } catch (MIException e) { @@ -252,13 +277,13 @@ public class MIPlugin extends Plugin { } /** - * Method createCSession. + * Method createCSession; remote debuging by selectin a target. * @param program * @param pid * @return ICDISession * @throws IOException */ - public Session createCSession(String gdb, File program, int pid, String[] targetParams, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { + public Session createCSession(String gdb, String miVersion, File program, int pid, String[] targetParams, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = GDB; } @@ -273,14 +298,26 @@ public class MIPlugin extends Plugin { String[] args; if (program == null) { - args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", miVersion}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } else { - args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi", program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", miVersion, program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } - MIProcess pgdb = new MIProcessAdapter(args, monitor); + + int launchTimeout = MIPlugin.getDefault().getPluginPreferences().getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); + MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor); + + if (MIPlugin.getDefault().isDebugging()) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < args.length; ++i) { + sb.append(args[i]); + sb.append(' '); + } + MIPlugin.getDefault().debugLog(sb.toString()); + } + MISession session; try { - session = createMISession(pgdb, null, MISession.ATTACH); + session = createMISession(pgdb, null, MISession.ATTACH, miVersion, monitor); } catch (MIException e) { pgdb.destroy(); throw e; @@ -337,9 +374,9 @@ public class MIPlugin extends Plugin { // This is to verbose for a log file, better use the console. // getDefault().getLog().log(StatusUtil.newStatus(Status.ERROR, message, null)); // ALERT:FIXME: For example for big buffers say 4k length, - // the console will simply blow taking down eclipse. + // the console will simply blows taking down eclipse. // This seems only to happen in Eclipse-gtk and Eclipse-motif - // on GNU/Linux, so it will be break in smaller chunks. + // on GNU/Linux, so we break the lines in smaller chunks. while (message.length() > 100) { String partial = message.substring(0, 100); message = message.substring(100); 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 1fa1e6b8cd2..9484c4cd9e6 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 @@ -21,16 +21,20 @@ import java.io.Reader; import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.cdt.utils.spawner.Spawner; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Preferences; /** */ public class MIProcessAdapter implements MIProcess { Process fGDBProcess; + private static final int ONE_SECOND = 1000; public MIProcessAdapter(String[] args, IProgressMonitor monitor) throws IOException { - fGDBProcess = getGDBProcess(args, monitor); + this(args, 0, monitor); + } + + public MIProcessAdapter(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException { + fGDBProcess = getGDBProcess(args, launchTimeout, monitor); } /** @@ -41,17 +45,7 @@ public class MIProcessAdapter implements MIProcess { * @return Process * @throws IOException */ - protected Process getGDBProcess(String[] args, IProgressMonitor monitor) throws IOException { - int ONE_SECOND = 1000; - - if (MIPlugin.getDefault().isDebugging()) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < args.length; ++i) { - sb.append(args[i]); - sb.append(' '); - } - MIPlugin.getDefault().debugLog(sb.toString()); - } + protected Process getGDBProcess(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException { final Process pgdb = ProcessFactory.getFactory().exec(args); Thread syncStartup = new Thread("GDB Start") { //$NON-NLS-1$ public void run() { @@ -74,10 +68,7 @@ public class MIProcessAdapter implements MIProcess { }; syncStartup.start(); - MIPlugin miPlugin = MIPlugin.getDefault(); - Preferences prefs = miPlugin.getPluginPreferences(); int timepass = 0; - int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); if (launchTimeout <= 0) { // Simulate we are waiting forever. launchTimeout = Integer.MAX_VALUE;