diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/TracingConsole.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/TracingConsole.java index a60cab216f5..5da677eee6e 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/TracingConsole.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/TracingConsole.java @@ -50,7 +50,7 @@ public class TracingConsole extends IOConsole { private String fLabel = ""; //$NON-NLS-1$ public TracingConsole(ILaunch launch, String label) { - super("", null, null, true); //$NON-NLS-1$ + super("", null, null, false); //$NON-NLS-1$ fLaunch = launch; fTracingStream = newOutputStream(); fSession = ((GdbLaunch)launch).getSession(); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/TracingConsoleManager.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/TracingConsoleManager.java index 6a6d4c5a72b..10a10d896f7 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/TracingConsoleManager.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/TracingConsoleManager.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.internal.ui.console; +import java.util.HashMap; + import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.dsf.gdb.launching.ITracedLaunch; @@ -21,11 +23,12 @@ import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.IConsole; -import org.eclipse.ui.console.IConsoleManager; /** * A tracing console manager which adds and removes tracing consoles * based on launch events and preference events. + * TracingConsoles are always running but are only shown in the console + * view if enabled by the user preference. * * @since 2.1 * This class was moved from package org.eclipse.cdt.dsf.gdb.internal.ui.tracing @@ -61,6 +64,13 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang */ private int fMinNumCharacters = fMaxNumCharacters - NUMBER_OF_CHARS_TO_DELETE; + /** + * A map of all TracingConsoles for their corresponding launch. + * We keep this list because TracingConsoles may not be registered + * with the ConsoleManager, so we need another way to find them. + */ + private HashMap fTracingConsoles = new HashMap<>(); + /** * Start the tracing console. We don't do this in a constructor, because * we need to use this. @@ -73,9 +83,7 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang int maxChars = store.getInt(IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES); setWaterMarks(maxChars); - if (fTracingEnabled) { - toggleTracing(true); - } + DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); } public void shutdown() { @@ -84,23 +92,16 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang removeAllConsoles(); } - protected void toggleTracing(boolean enabled) { - if (enabled) { - DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); - addAllConsoles(); + protected void toggleTracingVisibility(boolean visible) { + if (visible) { + ConsolePlugin.getDefault().getConsoleManager().addConsoles( + fTracingConsoles.values().toArray(new IConsole[fTracingConsoles.size()])); } else { - DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); - removeAllConsoles(); + ConsolePlugin.getDefault().getConsoleManager().removeConsoles( + fTracingConsoles.values().toArray(new IConsole[fTracingConsoles.size()])); } } - protected void addAllConsoles() { - ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); - for (ILaunch launch : launches) { - addConsole(launch); - } - } - protected void removeAllConsoles() { ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); for (ILaunch launch : launches) { @@ -139,12 +140,11 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(IGdbDebugPreferenceConstants.PREF_TRACES_ENABLE)) { fTracingEnabled = (Boolean)event.getNewValue(); - toggleTracing(fTracingEnabled); + toggleTracingVisibility(fTracingEnabled); } else if (event.getProperty().equals(IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES)) { int maxChars = (Integer)event.getNewValue(); updateAllConsoleWaterMarks(maxChars); } - } protected void addConsole(ILaunch launch) { @@ -152,50 +152,40 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang if (launch instanceof ITracedLaunch) { // Make sure we didn't already add this console if (getConsole(launch) == null) { - if (launch.isTerminated() == false) { - // Create and new tracing console. + if (!launch.isTerminated()) { + // Create a new tracing console. TracingConsole console = new TracingConsole(launch, ConsoleMessages.ConsoleMessages_trace_console_name); + console.initialize(); console.setWaterMarks(fMinNumCharacters, fMaxNumCharacters); - ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{console}); + + fTracingConsoles.put((ITracedLaunch)launch, console); + if (fTracingEnabled) { + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{console}); + } } // else we don't display a new console for a terminated launch } } } protected void removeConsole(ILaunch launch) { - if (launch instanceof ITracedLaunch) { - TracingConsole console = getConsole(launch); - if (console != null) { + TracingConsole console = fTracingConsoles.remove(launch); + if (console != null) { + console.destroy(); + if (fTracingEnabled) { ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[]{console}); } } } protected void renameConsole(ILaunch launch) { - if (launch instanceof ITracedLaunch) { - TracingConsole console = getConsole(launch); - if (console != null) { - console.resetName(); - } + TracingConsole console = getConsole(launch); + if (console != null) { + console.resetName(); } } private TracingConsole getConsole(ILaunch launch) { - ConsolePlugin plugin = ConsolePlugin.getDefault(); - if (plugin != null) { - // I've seen the plugin be null when running headless JUnit tests - IConsoleManager manager = plugin.getConsoleManager(); - IConsole[] consoles = manager.getConsoles(); - for (IConsole console : consoles) { - if (console instanceof TracingConsole) { - TracingConsole tracingConsole = (TracingConsole)console; - if (tracingConsole.getLaunch().equals(launch)) { - return tracingConsole; - } - } - } - } - return null; + return fTracingConsoles.get(launch); } /** @since 2.2 */ @@ -224,11 +214,9 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang /** @since 2.2 */ protected void updateConsoleWaterMarks(ILaunch launch) { - if (launch instanceof ITracedLaunch) { - TracingConsole console = getConsole(launch); - if (console != null) { - console.setWaterMarks(fMinNumCharacters, fMaxNumCharacters); - } - } + TracingConsole console = getConsole(launch); + if (console != null) { + console.setWaterMarks(fMinNumCharacters, fMaxNumCharacters); + } } } 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 de8542a0de1..723047b3e85 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 @@ -233,9 +233,6 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements } } - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite) - */ @Override protected Control createDialogArea( Composite parent ) { getShell().setText( MessagesForPreferences.GdbDebugPreferencePage_Advanced_Timeout_Settings ); @@ -661,16 +658,34 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements // Need to set layout again. group2.setLayout(groupLayout); - final IntegerWithBooleanFieldEditor enableGdbTracesField = new IntegerWithBooleanFieldEditor( + boolField= new BooleanFieldEditor( IGdbDebugPreferenceConstants.PREF_TRACES_ENABLE, - IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES, MessagesForPreferences.GdbDebugPreferencePage_enableTraces_label, group2); + + boolField.fillIntoGrid(group2, 1); + addField(boolField); + group2.setLayout(groupLayout); + + // The field below sets the size of the buffer for the gdb traces. + // It is located to the right of the previous field (which shows or not the + // gdb traces) and uses its label. However, we don't want to tightly + // couple the two fields using IntegerWithBooleanFieldEditor because + // we want the gdb traces limit to stay enabled even when the gdb traces + // are not actually shown (when the above preference is not selected). + // The reason is that since the gdb traces record even when they are not + // shown, we want the user to be able to set the limit on those consoles, + // even if they are not currently shown. + final IntegerFieldEditor gdbTracesLimit = new IntegerFieldEditor( + IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES, + "", // Empty title as we reuse the string of the previous field //$NON-NLS-1$ + group2); + // Instead of using Integer.MAX_VALUE which is some obscure number, // using 2 billion is nice and readable. - enableGdbTracesField.setValidRange(10000, 2000000000); - enableGdbTracesField.fillIntoGrid(group2, 2); - addField(enableGdbTracesField); + gdbTracesLimit.setValidRange(10000, 2000000000); + gdbTracesLimit.fillIntoGrid(group2, 2); + addField(gdbTracesLimit); // Need to set layout again. group2.setLayout(groupLayout); @@ -781,9 +796,6 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements updateTimeoutButtons(); } - /* (non-Javadoc) - * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk() - */ @Override public boolean performOk() { getPreferenceStore().setValue( IGdbDebugPreferenceConstants.PREF_COMMAND_CUSTOM_TIMEOUTS, fCustomTimeouts.getMemento() ); 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 ae219d7e35f..6e0e60d243b 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 @@ -18,7 +18,7 @@ GdbDebugPreferencePage_Add_button=Add GdbDebugPreferencePage_description=General settings for GDB Debugging GdbDebugPreferencePage_general_behavior_label=General Behavior -GdbDebugPreferencePage_enableTraces_label=Enable GDB traces with character limit: +GdbDebugPreferencePage_enableTraces_label=Show the GDB traces consoles with character limit: GdbDebugPreferencePage_autoTerminateGdb_label=Terminate GDB when last process exits GdbDebugPreferencePage_Command_column_name=GDB/MI Command GdbDebugPreferencePage_Command_field_can_not_be_empty='Command' field can not be empty 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 5565c709476..4ca61a23b23 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 @@ -30,7 +30,7 @@ public class GdbPreferenceInitializer extends AbstractPreferenceInitializer { @Override public void initializeDefaultPreferences() { IEclipsePreferences node = DefaultScope.INSTANCE.getNode(GdbPlugin.PLUGIN_ID); - node.putBoolean(IGdbDebugPreferenceConstants.PREF_TRACES_ENABLE, true); + node.putBoolean(IGdbDebugPreferenceConstants.PREF_TRACES_ENABLE, false); node.putInt(IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES, 500000); node.putBoolean(IGdbDebugPreferenceConstants.PREF_AUTO_TERMINATE_GDB, true); node.putBoolean(IGdbDebugPreferenceConstants.PREF_USE_INSPECTOR_HOVER, true);