1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 530443: Limit output to 10 lines per MI output

Some commands, such as -file-list-exec-source-files, can generate
10s of thousands of lines of output.

Change-Id: I07fc3ef99bdd8e9247c75e2e9733e43b35657687
Signed-off-by: Baha El Kassaby <baha.elkassaby@gmail.com>
Also-by: Jonah Graham <jonah@kichwacoders.com>
This commit is contained in:
Baha El Kassaby 2018-08-10 02:20:58 +02:00 committed by Jonah Graham
parent 0da8033c2c
commit 9f87a3ae09
8 changed files with 127 additions and 34 deletions

View file

@ -690,6 +690,16 @@ public class GdbDebugPreferencePage extends FieldEditorPreferencePage implements
// Need to set layout again.
group2.setLayout(groupLayout);
// The field below sets the number of lines a message can be.
final StringWithBooleanFieldEditor gdbMaxLines = new StringWithBooleanFieldEditor(
IGdbDebugPreferenceConstants.PREF_MAX_MI_OUTPUT_LINES_ENABLE,
IGdbDebugPreferenceConstants.PREF_MAX_MI_OUTPUT_LINES,
MessagesForPreferences.GdbDebugPreferencePage_enableMaxMessageLines_label, group2);
gdbMaxLines.fillIntoGrid(group2, 3);
addField(gdbMaxLines);
// Need to set layout again.
group2.setLayout(groupLayout);
boolField = new BooleanFieldEditor(IGdbDebugPreferenceConstants.PREF_USE_RTTI,
MessagesForPreferences.GdbDebugPreferencePage_use_rtti_label1 + " \n" //$NON-NLS-1$
+ MessagesForPreferences.GdbDebugPreferencePage_use_rtti_label2,

View file

@ -34,6 +34,7 @@ class MessagesForPreferences extends NLS {
/** @since 2.3 */
public static String GdbDebugPreferencePage_general_behavior_label;
public static String GdbDebugPreferencePage_enableTraces_label;
public static String GdbDebugPreferencePage_enableMaxMessageLines_label;
public static String GdbDebugPreferencePage_autoTerminateGdb_label;
public static String GdbDebugPreferencePage_Browse_button;
public static String GdbDebugPreferencePage_Command_column_name;

View file

@ -22,6 +22,7 @@ GdbDebugPreferencePage_description=General settings for GDB Debugging
GdbDebugPreferencePage_general_behavior_label=General Behavior
GdbDebugPreferencePage_enableTraces_label=Show the GDB traces consoles with character limit:
GdbDebugPreferencePage_enableMaxMessageLines_label=Maximum number of lines to display per message in GDB traces:
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

View file

@ -42,6 +42,31 @@ public interface IGdbDebugPreferenceConstants {
*/
public static final String PREF_MAX_GDB_TRACES = "maxGdbTraces"; //$NON-NLS-1$
/**
* Boolean preference whether to enable the max number of lines for messages.
* Default is {@value #MAX_MI_OUTPUT_LINES_ENABLE_DEFAULT}.
* @since 5.6
*/
public static final String PREF_MAX_MI_OUTPUT_LINES_ENABLE = "maxMiOutputLinesEnable"; //$NON-NLS-1$
/**
* The default for whether {@link #PREF_MAX_MI_OUTPUT_LINES} is enabled.
* @since 5.6
*/
public static final boolean MAX_MI_OUTPUT_LINES_ENABLE_DEFAULT = true;
/**
* The maximum number of lines a single message can be. Default is {@value #MAX_MI_OUTPUT_LINES_DEFAULT}.
* @since 5.6
*/
public static final String PREF_MAX_MI_OUTPUT_LINES = "maxMiOutputLines"; //$NON-NLS-1$
/**
* The default maximum number of lines a single message can be.
* @since 5.6
*/
public static final int MAX_MI_OUTPUT_LINES_DEFAULT = 5;
/**
* Boolean preference whether to automatically terminate GDB when the inferior exists. Default is <code>true</code>.
*/

View file

@ -35,6 +35,10 @@ public class GdbPreferenceInitializer extends AbstractPreferenceInitializer {
IEclipsePreferences node = DefaultScope.INSTANCE.getNode(GdbPlugin.PLUGIN_ID);
node.putBoolean(IGdbDebugPreferenceConstants.PREF_TRACES_ENABLE, false);
node.putInt(IGdbDebugPreferenceConstants.PREF_MAX_GDB_TRACES, 500000);
node.putBoolean(IGdbDebugPreferenceConstants.PREF_MAX_MI_OUTPUT_LINES_ENABLE,
IGdbDebugPreferenceConstants.MAX_MI_OUTPUT_LINES_ENABLE_DEFAULT);
node.putInt(IGdbDebugPreferenceConstants.PREF_MAX_MI_OUTPUT_LINES,
IGdbDebugPreferenceConstants.MAX_MI_OUTPUT_LINES_DEFAULT);
node.putBoolean(IGdbDebugPreferenceConstants.PREF_AUTO_TERMINATE_GDB, true);
node.putBoolean(IGdbDebugPreferenceConstants.PREF_USE_INSPECTOR_HOVER, true);
node.putBoolean(IGdbDebugPreferenceConstants.PREF_ENABLE_PRETTY_PRINTING, true);

View file

@ -49,6 +49,7 @@ import org.eclipse.cdt.dsf.debug.service.command.ICommandListener;
import org.eclipse.cdt.dsf.debug.service.command.ICommandResult;
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
import org.eclipse.cdt.dsf.debug.service.command.IEventListener;
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
import org.eclipse.cdt.dsf.gdb.internal.GdbDebugOptions;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
@ -70,6 +71,9 @@ import org.eclipse.cdt.dsf.service.AbstractDsfService;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.osgi.util.NLS;
import com.ibm.icu.text.MessageFormat;
@ -567,6 +571,50 @@ public abstract class AbstractMIControl extends AbstractDsfService implements IM
return count;
}
/**
* Write the str containing an MI message to the tracing stream.
* The str will generally have a newline already if toGdb is true,
* and will need a newline if toGdb is false.
* @param toGdb true if MI is to GDB, false if from GDB
* @param str string containing MI message
* @since 5.6
*/
protected void writeToTracingStream(boolean toGdb, final String str) {
if (getMITracingStream() != null) {
try {
String message = GdbPlugin.getDebugTime() + " " + str + (toGdb ? "" : "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(GdbPlugin.PLUGIN_ID);
boolean limitEnabled = node.getBoolean(IGdbDebugPreferenceConstants.PREF_MAX_MI_OUTPUT_LINES_ENABLE,
IGdbDebugPreferenceConstants.MAX_MI_OUTPUT_LINES_ENABLE_DEFAULT);
int initialMaxLines = IGdbDebugPreferenceConstants.MAX_MI_OUTPUT_LINES_DEFAULT;
try {
initialMaxLines = node.getInt(IGdbDebugPreferenceConstants.PREF_MAX_MI_OUTPUT_LINES,
IGdbDebugPreferenceConstants.MAX_MI_OUTPUT_LINES_DEFAULT);
} catch (NumberFormatException e) {
}
int linecounter = initialMaxLines;
while (message.length() > 100 && (!limitEnabled || linecounter-- > 0)) {
String partial = message.substring(0, 100);
message = message.substring(100);
getMITracingStream().write(partial.getBytes());
getMITracingStream().write("\\\n".getBytes()); //$NON-NLS-1$
}
if (linecounter <= 0) {
String messageTruncatedInfo = NLS.bind(Messages.AbstractMIControl_message_truncated,
initialMaxLines);
getMITracingStream().write(messageTruncatedInfo.getBytes());
} else {
getMITracingStream().write(message.getBytes());
}
} catch (IOException e) {
// The tracing stream could be closed at any time
// since the user can set a preference to turn off
// this tracing.
setMITracingStream(null);
}
}
}
/*
* Support class which creates a convenient wrapper for holding all information about an
* individual request.
@ -705,22 +753,7 @@ public abstract class AbstractMIControl extends AbstractDsfService implements IM
GdbDebugOptions.trace(
String.format("%s %s %s", GdbPlugin.getDebugTime(), MI_TRACE_IDENTIFIER, str)); //$NON-NLS-1$
}
if (getMITracingStream() != null) {
try {
String message = GdbPlugin.getDebugTime() + " " + str; //$NON-NLS-1$
while (message.length() > 100) {
String partial = message.substring(0, 100) + "\\\n"; //$NON-NLS-1$
message = message.substring(100);
getMITracingStream().write(partial.getBytes());
}
getMITracingStream().write(message.getBytes());
} catch (IOException e) {
// The tracing stream could be closed at any time
// since the user can set a preference to turn off
// this tracing.
setMITracingStream(null);
}
}
writeToTracingStream(true, str);
fOutputStream.write(str.getBytes());
fOutputStream.flush();
@ -785,24 +818,7 @@ public abstract class AbstractMIControl extends AbstractDsfService implements IM
}
}
final String finalLine = line;
if (getMITracingStream() != null) {
try {
String message = GdbPlugin.getDebugTime() + " " + finalLine + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
while (message.length() > 100) {
String partial = message.substring(0, 100) + "\\\n"; //$NON-NLS-1$
message = message.substring(100);
getMITracingStream().write(partial.getBytes());
}
getMITracingStream().write(message.getBytes());
} catch (IOException e) {
// The tracing stream could be closed at any time
// since the user can set a preference to turn off
// this tracing.
setMITracingStream(null);
}
}
writeToTracingStream(false, line);
processMIOutput(line);
}
}

View file

@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2018 Kichwa Coders and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command;
import org.eclipse.osgi.util.NLS;
class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.dsf.mi.service.command.messages"; //$NON-NLS-1$
public static String AbstractMIControl_message_truncated;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
private Messages() {
}
}

View file

@ -0,0 +1,11 @@
###############################################################################
# Copyright (c) 2018 Kichwa Coders and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
###############################################################################
AbstractMIControl_message_truncated=[message truncated to {0} lines. More lines can be set in the 'Preference->Debug->GDB' eclipse preference page.]\n