Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaha El Kassaby2018-08-10 00:20:58 +0000
committerJonah Graham2018-11-26 21:27:57 +0000
commit9f87a3ae09b05d66c859e0e784490deb21d4a3be (patch)
treea8b4a0cad1fe7309282502ef4258c245ed0f0381
parent0da8033c2c0947959860edab8c141fdf3a6ec2e3 (diff)
downloadorg.eclipse.cdt-9f87a3ae09b05d66c859e0e784490deb21d4a3be.tar.gz
org.eclipse.cdt-9f87a3ae09b05d66c859e0e784490deb21d4a3be.tar.xz
org.eclipse.cdt-9f87a3ae09b05d66c859e0e784490deb21d4a3be.zip
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>
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbDebugPreferencePage.java10
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java1
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties1
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java25
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java4
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java84
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/Messages.java25
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/messages.properties11
8 files changed, 127 insertions, 34 deletions
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 9b2fb9821fc..0eb6abd767b 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
@@ -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,
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 1cfb06ae6e4..aae5e188437 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
@@ -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;
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 80d3b222294..803818bf147 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
@@ -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
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 373d27eb398..b000efa2f82 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
@@ -43,6 +43,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>.
*/
public static final String PREF_AUTO_TERMINATE_GDB = "autoTerminateGdb"; //$NON-NLS-1$
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 b0173d6dfe8..8056d779697 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
@@ -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);
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java
index e8077abde6b..d94e9dd2901 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java
@@ -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);
}
}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/Messages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/Messages.java
new file mode 100644
index 00000000000..4b32a993a25
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/Messages.java
@@ -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() {
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/messages.properties
new file mode 100644
index 00000000000..d2ccd80cb8c
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/messages.properties
@@ -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

Back to the top