diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbDebuggerPage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbDebuggerPage.java index 751aeca2747..7d0d89095a2 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbDebuggerPage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbDebuggerPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 QNX Software Systems and others. + * Copyright (c) 2008, 2017 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 @@ -24,6 +24,7 @@ import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.jface.preference.IPreferenceStore; @@ -60,6 +61,10 @@ public class GdbDebuggerPage extends AbstractCDebuggerPage implements Observer { protected Button fUpdateThreadlistOnSuspend; protected Button fDebugOnFork; + /** + * Checkbox for using GDB's new-console -- only displayed on Windows. Will be null if unsupported. + */ + private Button fExternalConsole; /** * A combo box to let the user choose if fast tracepoints should be used or not. @@ -101,6 +106,8 @@ public class GdbDebuggerPage extends AbstractCDebuggerPage implements Observer { IGDBLaunchConfigurationConstants.DEBUGGER_UPDATE_THREADLIST_ON_SUSPEND_DEFAULT); configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_DEBUG_ON_FORK, IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_ON_FORK_DEFAULT); + configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_EXTERNAL_CONSOLE, + preferenceStore.getBoolean(IGdbDebugPreferenceConstants.PREF_EXTERNAL_CONSOLE)); configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_TRACEPOINT_MODE, IGDBLaunchConfigurationConstants.DEBUGGER_TRACEPOINT_MODE_DEFAULT); @@ -157,6 +164,8 @@ public class GdbDebuggerPage extends AbstractCDebuggerPage implements Observer { IGDBLaunchConfigurationConstants.DEBUGGER_UPDATE_THREADLIST_ON_SUSPEND_DEFAULT); boolean debugOnFork = getBooleanAttr(configuration, IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_DEBUG_ON_FORK, IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_ON_FORK_DEFAULT); + boolean externalConsole = getBooleanAttr(configuration, IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_EXTERNAL_CONSOLE, + preferenceStore.getBoolean(IGdbDebugPreferenceConstants.PREF_EXTERNAL_CONSOLE)); if (fSolibBlock != null) fSolibBlock.initializeFrom(configuration); @@ -166,6 +175,9 @@ public class GdbDebuggerPage extends AbstractCDebuggerPage implements Observer { fReverseCheckBox.setSelection(reverseEnabled); fUpdateThreadlistOnSuspend.setSelection(updateThreadsOnSuspend); fDebugOnFork.setSelection(debugOnFork); + if (fExternalConsole != null) { + fExternalConsole.setSelection(externalConsole); + } updateTracepointModeFromConfig(configuration); @@ -252,6 +264,10 @@ public class GdbDebuggerPage extends AbstractCDebuggerPage implements Observer { fUpdateThreadlistOnSuspend.getSelection()); configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_DEBUG_ON_FORK, fDebugOnFork.getSelection()); + if (fExternalConsole != null) { + configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_EXTERNAL_CONSOLE, + fExternalConsole.getSelection()); + } if (fTracepointModeCombo != null) { configuration.setAttribute(IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_TRACEPOINT_MODE, @@ -333,6 +349,9 @@ public class GdbDebuggerPage extends AbstractCDebuggerPage implements Observer { PlatformUI.getWorkbench().getHelpSystem().setHelp(fUpdateThreadlistOnSuspend, GdbUIPlugin.PLUGIN_ID + ".update_threadlist_button_context"); //$NON-NLS-1$ fDebugOnFork = addCheckbox(comp, LaunchUIMessages.getString("GDBDebuggerPage.Automatically_debug_forked_processes")); //$NON-NLS-1$ + if (Platform.getOS().startsWith("win")) { //$NON-NLS-1$ + fExternalConsole = addCheckbox(comp, LaunchUIMessages.getString("GDBDebuggerPage.use_new_console_for_process")); //$NON-NLS-1$ + } createTracepointModeCombo(comp); } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/LaunchUIMessages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/LaunchUIMessages.properties index 44ee360e020..689a6113e08 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/LaunchUIMessages.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/LaunchUIMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2016 QNX Software Systems and others. +# Copyright (c) 2003, 2017 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 @@ -29,6 +29,7 @@ GDBDebuggerPage.reverse_Debuggingmodesoft=Software Reverse Debugging (detailed b GDBDebuggerPage.reverse_Debuggingmodehard=Hardware Reverse Debugging (no details but faster) GDBDebuggerPage.update_thread_list_on_suspend=Force thread list update on suspend GDBDebuggerPage.Automatically_debug_forked_processes=Automatically debug forked processes (Note: Requires Multi Process GDB) +GDBDebuggerPage.use_new_console_for_process=Use external console for inferior (open a new console window for input/output) GDBDebuggerPage.tracepoint_mode_label=Tracepoint mode: GDBDebuggerPage.tracepoint_mode_fast=Fast GDBDebuggerPage.tracepoint_mode_normal=Normal diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java index 1e66fddb1a0..0811c151cb3 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson and others. + * Copyright (c) 2009, 2017 Ericsson 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 @@ -27,6 +27,7 @@ import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.dsf.gdb.internal.ui.IGdbUIConstants; import org.eclipse.cdt.dsf.gdb.service.command.CustomTimeoutsMap; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.fieldassist.ControlDecoration; @@ -582,8 +583,8 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements group1); enableStopAtMain.fillIntoGrid(group1, 3); addField(enableStopAtMain); - - fCommandTimeoutField = new IntegerWithBooleanFieldEditor( + + fCommandTimeoutField = new IntegerWithBooleanFieldEditor( IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT, IGdbDebugPreferenceConstants.PREF_COMMAND_TIMEOUT_VALUE, MessagesForPreferences.GdbDebugPreferencePage_Command_timeout, @@ -610,6 +611,16 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements enableNonStop.fillIntoGrid(group1, 3); addField(enableNonStop); + if (Platform.getOS().startsWith("win")) { //$NON-NLS-1$ + BooleanFieldEditor externalConsoleField = new BooleanFieldEditor( + IGdbDebugPreferenceConstants.PREF_EXTERNAL_CONSOLE, + MessagesForPreferences.GdbDebugPreferencePage_external_console, + group1); + + externalConsoleField.fillIntoGrid(group1, 3); + addField(externalConsoleField); + } + group1.setLayout(groupLayout); final Group group2= new Group(parent, SWT.NONE); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java index 3e04fa4994f..6ddaee8ac7a 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2016 Ericsson and others. + * Copyright (c) 2009, 2017 Ericsson 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 @@ -66,7 +66,8 @@ class MessagesForPreferences extends NLS { public static String GdbDebugPreferencePage_use_rtti_label1; /** @since 2.3 */ public static String GdbDebugPreferencePage_use_rtti_label2; - + public static String GdbDebugPreferencePage_external_console; + public static String ReverseDebugPreferencePage_ReverseSettings; public static String ReverseDebugPreferencePage_SelectHardwareTracingMethod; public static String ReverseDebugPreferencePage_GDBPreference; diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties index 6e0e60d243b..df4925944a6 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2009, 2016 Ericsson and others. +# Copyright (c) 2009, 2017 Ericsson 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 @@ -36,6 +36,8 @@ GdbDebugPreferencePage_initialChildCountLimitForCollections_label=For collection GdbDebugPreferencePage_use_rtti_label1=Display run-time type of variables GdbDebugPreferencePage_use_rtti_label2=(Note: requires GDB 7.5 or higher) +GdbDebugPreferencePage_external_console=Use external console for inferior (open a new console window for input/output) + GdbDebugPreferencePage_defaults_label=Debug Configurations Defaults GdbDebugPreferencePage_Delete_button=Delete GdbDebugPreferencePage_Invalid_timeout_value=Invalid timeout value diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java index 0980e0bc2b7..ce8ccb5cf1a 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGDBLaunchConfigurationConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 Ericsson and others. + * Copyright (c) 2008, 2017 Ericsson 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 @@ -113,7 +113,13 @@ public class IGDBLaunchConfigurationConstants { * @since 4.0 */ public static final String ATTR_DEBUGGER_DEBUG_ON_FORK = GdbPlugin.PLUGIN_ID + ".DEBUG_ON_FORK"; //$NON-NLS-1$ - + + /** + * Launch configuration attribute key. Boolean value to set the 'new-console' GDB option. + * @since 5.4 + */ + public static final String ATTR_DEBUGGER_EXTERNAL_CONSOLE = GdbPlugin.PLUGIN_ID + ".EXTERNAL_CONSOLE"; //$NON-NLS-1$ + /** * Launch configuration attribute key. The value is a String specifying the type of Tracepoint mode * that should be used for this launch. @@ -214,7 +220,13 @@ public class IGDBLaunchConfigurationConstants { * @since 4.0 */ public static final boolean DEBUGGER_DEBUG_ON_FORK_DEFAULT = false; - + + /** + * Launch configuration attribute value. The key is ATTR_DEBUGGER_EXTERNAL_CONSOLE. + * @since 5.4 + */ + public static final boolean DEBUGGER_EXTERNAL_CONSOLE_DEFAULT = false; + /** * Possible attribute value for the key is ATTR_DEBUGGER_TRACEPOINT_MODE. * Indicates that only normal tracepoints should be used. diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java index 6ed79a0dd63..6ba511cd6eb 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java @@ -126,6 +126,14 @@ public interface IGdbDebugPreferenceConstants { */ public static final String PREF_USE_RTTI = PREFIX + "useRtti"; //$NON-NLS-1$ + /** + * Boolean preference whether to use new-console. Default is + * {@link IGDBLaunchConfigurationConstants#DEBUGGER_EXTERNAL_CONSOLE_DEFAULT} + * + * @since 5.4 + */ + public static final String PREF_EXTERNAL_CONSOLE = PREFIX + "externalConsole"; //$NON-NLS-1$ + /** * Boolean preference whether to hide or not, the running threads in the debug view. * Default is false. diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java index 4ca61a23b23..2b1ecc9d64a 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java @@ -36,6 +36,7 @@ public class GdbPreferenceInitializer extends AbstractPreferenceInitializer { node.putBoolean(IGdbDebugPreferenceConstants.PREF_USE_INSPECTOR_HOVER, true); node.putBoolean(IGdbDebugPreferenceConstants.PREF_ENABLE_PRETTY_PRINTING, true); node.putBoolean(IGdbDebugPreferenceConstants.PREF_USE_RTTI, true); + node.putBoolean(IGdbDebugPreferenceConstants.PREF_EXTERNAL_CONSOLE, IGDBLaunchConfigurationConstants.DEBUGGER_EXTERNAL_CONSOLE_DEFAULT); node.putInt(IGdbDebugPreferenceConstants.PREF_INITIAL_CHILD_COUNT_LIMIT_FOR_COLLECTIONS, 100); node.put(IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_COMMAND, IGDBLaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT); node.put(IGdbDebugPreferenceConstants.PREF_DEFAULT_GDB_INIT, IGDBLaunchConfigurationConstants.DEBUGGER_GDB_INIT_DEFAULT); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java index f0e23cfc398..e0eb5343b7b 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/StartOrRestartProcessSequence_7_0.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2015 Ericsson and others. + * Copyright (c) 2011, 2017 Ericsson 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 @@ -32,6 +32,7 @@ import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContex import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext; import org.eclipse.cdt.dsf.debug.service.command.ICommand; import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; +import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.launching.LaunchUtils; import org.eclipse.cdt.dsf.gdb.service.command.IGDBControl; @@ -41,12 +42,14 @@ import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; import org.eclipse.cdt.dsf.mi.service.command.MIInferiorProcess; import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakInsertInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakpoint; +import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowNewConsoleInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; import org.eclipse.cdt.dsf.service.DsfServicesTracker; import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.cdt.utils.pty.PersistentPTY; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; /** @@ -286,36 +289,73 @@ public class StartOrRestartProcessSequence_7_0 extends ReflectionSequence { rm.done(); return; } - - // Every other type of session that can get to this code, is starting a new process - // and requires a pty for it. - try { - // Use a PersistentPTY so it can be re-used for restarts. - // It is possible that the inferior will be restarted by the user from - // the GDB console, in which case, we are not able to create a new PTY - // for it; using a persistentPTY allows this to work since the persistentPTY - // does not need to be replaced but can continue to be used. - fPty = new PersistentPTY(); - fPty.validateSlaveName(); + + boolean externalConsoleDefault = Platform.getPreferencesService().getBoolean(GdbPlugin.PLUGIN_ID, + IGdbDebugPreferenceConstants.PREF_EXTERNAL_CONSOLE, + IGDBLaunchConfigurationConstants.DEBUGGER_EXTERNAL_CONSOLE_DEFAULT, null); - // Tell GDB to use this PTY - fCommandControl.queueCommand( - fCommandFactory.createMIInferiorTTYSet((IMIContainerDMContext)getContainerContext(), fPty.getSlaveName()), - new ImmediateDataRequestMonitor(rm) { - @Override - protected void handleFailure() { - // We were not able to tell GDB to use the PTY - // so we won't use it at all. - fPty = null; - rm.done(); - } - }); - } catch (IOException e) { - fPty = null; - rm.done(); + boolean externalConsole = CDebugUtils.getAttribute(fAttributes, + IGDBLaunchConfigurationConstants.ATTR_DEBUGGER_EXTERNAL_CONSOLE, + externalConsoleDefault); + if (externalConsole) { + initializeExternalConsole(new ImmediateRequestMonitor(rm) { + @Override + protected void handleCompleted() { + if (isSuccess()) { + fPty = null; + rm.done(); + } else { + initializePty(rm); + } + } + }); + } else { + initializePty(rm); } } } + + private void initializeExternalConsole(final RequestMonitor rm) { + fCommandControl.queueCommand(fCommandFactory.createMIGDBShowNewConsole(getContainerContext()), + new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + fCommandControl.queueCommand( + fCommandFactory.createMIGDBSetNewConsole(getContainerContext(), true), + new ImmediateDataRequestMonitor(rm)); + } + }); + } + + private void initializePty(final RequestMonitor rm) { + // Every other type of session that can get to this code, is starting a new process + // and requires a pty for it. + try { + // Use a PersistentPTY so it can be re-used for restarts. + // It is possible that the inferior will be restarted by the user from + // the GDB console, in which case, we are not able to create a new PTY + // for it; using a persistentPTY allows this to work since the persistentPTY + // does not need to be replaced but can continue to be used. + fPty = new PersistentPTY(); + fPty.validateSlaveName(); + + // Tell GDB to use this PTY + fCommandControl.queueCommand( + fCommandFactory.createMIInferiorTTYSet((IMIContainerDMContext)getContainerContext(), fPty.getSlaveName()), + new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleFailure() { + // We were not able to tell GDB to use the PTY + // so we won't use it at all. + fPty = null; + rm.done(); + } + }); + } catch (IOException e) { + fPty = null; + rm.done(); + } + } /** * @since 4.7 diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java index 5c6a15af5a5..de5e280be27 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java @@ -130,6 +130,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetDisconnectedTraci import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetEnv; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetHostCharset; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetLanguage; +import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetNewConsole; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetNonStop; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetPagination; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetPrintObject; @@ -146,6 +147,7 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTraceNotes; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTraceUser; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBShowExitCode; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBShowLanguage; +import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBShowNewConsole; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBVersion; import org.eclipse.cdt.dsf.mi.service.command.commands.MIInferiorTTYSet; import org.eclipse.cdt.dsf.mi.service.command.commands.MIInfoOs; @@ -217,6 +219,7 @@ import org.eclipse.cdt.dsf.mi.service.command.output.MIDataReadMemoryInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIDataWriteMemoryInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowExitCodeInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowLanguageInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowNewConsoleInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBVersionInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo; import org.eclipse.cdt.dsf.mi.service.command.output.MIInfoOsInfo; @@ -799,6 +802,11 @@ public class CommandFactory { return new MIGDBSetLanguage(ctx, language); } + /** @since 5.4*/ + public ICommand createMIGDBSetNewConsole(IDMContext ctx, boolean isSet) { + return new MIGDBSetNewConsole(ctx, isSet); + } + public ICommand createMIGDBSetNonStop(ICommandControlDMContext ctx, boolean isSet) { return new MIGDBSetNonStop(ctx, isSet); } @@ -868,6 +876,11 @@ public class CommandFactory { return new MIGDBShowExitCode(ctx); } + /** @since 5.4 */ + public ICommand createMIGDBShowNewConsole(IDMContext ctx) { + return new MIGDBShowNewConsole(ctx); + } + /** @since 4.3 */ public ICommand createMIGDBShowLanguage(IDMContext ctx) { return new MIGDBShowLanguage(ctx); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetNewConsole.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetNewConsole.java new file mode 100644 index 00000000000..814b822dfae --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetNewConsole.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2017 Kichwa Coders 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: + * Kichwa Coders - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.mi.service.command.commands; + +import org.eclipse.cdt.dsf.datamodel.IDMContext; + +/** + * -gdb-set new-console on|off + * + * Set whether to start in a new console or not + * + * @since 5.4 + */ +public class MIGDBSetNewConsole extends MIGDBSet { + + public MIGDBSetNewConsole(IDMContext ctx, boolean isSet) { + super(ctx, new String[] { "new-console", isSet ? "on" : "off" }); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShowNewConsole.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShowNewConsole.java new file mode 100644 index 00000000000..49fa6dddc85 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShowNewConsole.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2017 Kichwa Coders 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: + * Kichwa Coders - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.mi.service.command.commands; + +import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.mi.service.command.output.MIGDBShowNewConsoleInfo; +import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput; + +/** + * + * -gdb-show new-console + * + * @since 5.4 + * + */ +public class MIGDBShowNewConsole extends MIGDBShow { + + public MIGDBShowNewConsole(IDMContext ctx) { + super(ctx, new String[] { "new-console" }); //$NON-NLS-1$ + } + + @Override + public MIGDBShowNewConsoleInfo getResult(MIOutput miResult) { + return new MIGDBShowNewConsoleInfo(miResult); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBShowNewConsoleInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBShowNewConsoleInfo.java new file mode 100644 index 00000000000..3ba608be8d5 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBShowNewConsoleInfo.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2017 Kichwa Coders 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: + * Kichwa Coders - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.dsf.mi.service.command.output; + +/** + * @since 5.4 + */ +public class MIGDBShowNewConsoleInfo extends MIInfo { + + private Boolean fIsSet = null; + + public MIGDBShowNewConsoleInfo(MIOutput record) { + super(record); + parse(); + } + + protected void parse() { + if (isDone()) { + MIOutput out = getMIOutput(); + MIResultRecord outr = out.getMIResultRecord(); + if (outr != null) { + MIResult[] results = outr.getMIResults(); + for (int i = 0; i < results.length; i++) { + String var = results[i].getVariable(); + if (var.equals("value")) { //$NON-NLS-1$ + MIValue value = results[i].getMIValue(); + if (value instanceof MIConst) { + fIsSet = "on".equals(((MIConst) value).getString()); //$NON-NLS-1$ + } + } + } + } + } + } + + /** + * Return if child will launch in a new console, or null if + * new-console unsupported. + */ + public Boolean isSet() { + return fIsSet; + } +}