1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 335895: GDB Traces Console has infinite capacity

This commit is contained in:
Marc Khouzam 2011-02-03 17:08:12 +00:00
parent 3bb812c2c1
commit 7eb8ffda2e
6 changed files with 79 additions and 12 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Ericsson and others.
* Copyright (c) 2009, 2011 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
@ -38,6 +38,17 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang
*/
private boolean fTracingEnabled = false;
/**
* The maximum number of characters that are allowed per console
*/
private int fMaxNumCharacters = 500000;
/**
* The number of characters that will be kept in the console once we
* go over fMaxNumCharacters and that we must remove some characters
*/
private int fMinNumCharacters = 400000;
/**
* Start the tracing console. We don't do this in a constructor, because
* we need to use <code>this</code>.
@ -47,6 +58,8 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang
store.addPropertyChangeListener(this);
fTracingEnabled = store.getBoolean(IGdbDebugPreferenceConstants.PREF_TRACES_ENABLE);
int maxChars = store.getInt(IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES);
setWaterMarks(maxChars);
if (fTracingEnabled) {
toggleTracing(true);
@ -110,7 +123,11 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang
if (event.getProperty().equals(IGdbDebugPreferenceConstants.PREF_TRACES_ENABLE)) {
fTracingEnabled = (Boolean)event.getNewValue();
toggleTracing(fTracingEnabled);
} else if (event.getProperty().equals(IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES)) {
int maxChars = (Integer)event.getNewValue();
updateAllConsoleWaterMarks(maxChars);
}
}
protected void addConsole(ILaunch launch) {
@ -121,6 +138,7 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang
if (launch.isTerminated() == false) {
// Create and new tracing console.
TracingConsole console = new TracingConsole(launch, ConsoleMessages.ConsoleMessages_trace_console_name);
console.setWaterMarks(fMinNumCharacters, fMaxNumCharacters);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{console});
} // else we don't display a new console for a terminated launch
}
@ -162,4 +180,33 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang
}
return null;
}
/** @since 2.2 */
protected void setWaterMarks(int maxChars) {
if (maxChars < 10000) maxChars = 10000;
fMaxNumCharacters = maxChars;
// If the max number of chars is anything below 105000, we only keep 5000 once we truncate.
// If the max number of chars is bigger than 105000, we truncate 100000 chars.
fMinNumCharacters = maxChars < 105000 ? 5000 : maxChars - 100000;
}
/** @since 2.2 */
protected void updateAllConsoleWaterMarks(int maxChars) {
setWaterMarks(maxChars);
ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
for (ILaunch launch : launches) {
updateConsoleWaterMarks(launch);
}
}
/** @since 2.2 */
protected void updateConsoleWaterMarks(ILaunch launch) {
if (launch instanceof ITracedLaunch) {
TracingConsole console = getConsole(launch);
if (console != null) {
console.setWaterMarks(fMinNumCharacters, fMaxNumCharacters);
}
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Ericsson and others.
* Copyright (c) 2009, 2011 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
@ -137,6 +137,17 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements
boolField.fillIntoGrid(group, 3);
addField(boolField);
IntegerFieldEditor maxCharactersField = new IntegerFieldEditor(
IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES,
MessagesForPreferences.GdbDebugPreferencePage_maxGdbTraces_label,
group);
// Instead of using Integer.MAX_VALUE which is some obscure number, using 2 billion is nice and readable
maxCharactersField.setValidRange(10000, 2000000000);
maxCharactersField.fillIntoGrid(group, 3);
addField(maxCharactersField);
// need to set layout again
group.setLayout(groupLayout);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Ericsson and others.
* Copyright (c) 2009, 2011 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
@ -25,6 +25,7 @@ public class GdbPreferenceInitializer extends AbstractPreferenceInitializer {
public void initializeDefaultPreferences() {
IPreferenceStore store = GdbUIPlugin.getDefault().getPreferenceStore();
store.setDefault(IGdbDebugPreferenceConstants.PREF_TRACES_ENABLE, true);
store.setDefault(IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES, 500000);
store.setDefault(IGdbDebugPreferenceConstants.PREF_AUTO_TERMINATE_GDB, true);
store.setDefault(IGdbDebugPreferenceConstants.PREF_USE_INSPECTOR_HOVER, true);
store.setDefault(IGdbDebugPreferenceConstants.PREF_ENABLE_PRETTY_PRINTING, true);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Ericsson and others.
* Copyright (c) 2009, 2011 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
@ -20,19 +20,21 @@ class MessagesForPreferences extends NLS {
public static String GdbDebugPreferencePage_description;
public static String GdbDebugPreferencePage_traces_label;
public static String GdbDebugPreferencePage_enableTraces_label;
/** @since 2.2 */
public static String GdbDebugPreferencePage_maxGdbTraces_label;
public static String GdbDebugPreferencePage_termination_label;
public static String GdbDebugPreferencePage_autoTerminateGdb_label;
public static String GdbDebugPreferencePage_hover_label;
public static String GdbDebugPreferencePage_useInspectorHover_label;
/** @since 3.0 */
/** @since 2.2 */
public static String GdbDebugPreferencePage_prettyPrinting_label;
/** @since 3.0 */
/** @since 2.2 */
public static String GdbDebugPreferencePage_enablePrettyPrinting_label1;
/** @since 3.0 */
/** @since 2.2 */
public static String GdbDebugPreferencePage_enablePrettyPrinting_label2;
/** @since 3.0 */
/** @since 2.2 */
public static String GdbDebugPreferencePage_initialChildCountLimitForCollections_label;
/** @since 3.0 */
/** @since 2.2 */
public static String GdbDebugPreferencePage_defaults_label;
static {
// initialize resource bundle

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2009, 2010 Ericsson and others.
# Copyright (c) 2009, 2011 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
@ -14,7 +14,7 @@ GdbDebugPreferencePage_description=General settings for GDB Debugging
GdbDebugPreferencePage_traces_label=Traces
GdbDebugPreferencePage_enableTraces_label=Enable GDB traces
GdbDebugPreferencePage_maxGdbTraces_label=Limit GDB traces output (# characters):
GdbDebugPreferencePage_termination_label=Termination
GdbDebugPreferencePage_autoTerminateGdb_label=Terminate GDB when last process exits

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Ericsson and others.
* Copyright (c) 2009, 2011 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
@ -26,6 +26,12 @@ public interface IGdbDebugPreferenceConstants {
*/
public static final String PREF_TRACES_ENABLE = "tracesEnable"; //$NON-NLS-1$
/**
* The maximum number of characters in the GDB trace console. Default is 500000 characters.
* @since 4.0
*/
public static final String PREF_MAX_GDB_TRACES = "maxGdbTraces"; //$NON-NLS-1$
/**
* Boolean preference whether to automatically terminate GDB when the inferior exists. Default is <code>true</code>.
*/