Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonah Graham2018-11-20 16:20:39 -0500
committerJonah Graham2018-11-20 16:20:39 -0500
commit48d2271a58a68743e428d3096d2bca054d04e310 (patch)
tree235ba23e71c393ad22d1d57fc8fdfec14754c4ee /dsf-gdb
parent3cf0297769e5cfb91823e93ce570120a75fe01ce (diff)
downloadorg.eclipse.cdt-48d2271a58a68743e428d3096d2bca054d04e310.tar.gz
org.eclipse.cdt-48d2271a58a68743e428d3096d2bca054d04e310.tar.xz
org.eclipse.cdt-48d2271a58a68743e428d3096d2bca054d04e310.zip
Bug 540373: Normalize newlines with .gitattributes
There is also a new script to verify completeness of .gitattributes: releng/scripts/verify_gitattributes.sh Change-Id: I2ce270852ab54b66b6c474a6ec94203fe5bba78b
Diffstat (limited to 'dsf-gdb')
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.java50
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.properties24
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/service/CommonDsfTest.java216
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/mi/service/command/commands/TestMIGDBSetSysroot.java146
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbDebugOptions.java244
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/CommandFactory_6_8.java80
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIJump.java56
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIExecArguments.java62
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetCharset.java60
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetHostCharset.java56
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetNewConsole.java54
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintObject.java60
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintSevenbitStrings.java58
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetCharset.java58
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetWideCharset.java62
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBShowNewConsole.java68
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIGDBShowNewConsoleInfo.java102
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStringHandler.java918
18 files changed, 1187 insertions, 1187 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.java
index af36ef7c1b..699c4b1da1 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.java
@@ -1,25 +1,25 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2014 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
-
-import org.eclipse.osgi.util.NLS;
-
-public class Messages extends NLS {
- public static String MulticoreVisualizer_name;
- public static String MulticoreVisualizer_tooltip;
- static {
- // initialize resource bundle
- NLS.initializeMessages(Messages.class.getName(), Messages.class);
- }
-
- private Messages() {
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.view;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ public static String MulticoreVisualizer_name;
+ public static String MulticoreVisualizer_tooltip;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(Messages.class.getName(), Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.properties
index 96c244d3df..5cfd1086b1 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.properties
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/ui/view/Messages.properties
@@ -1,12 +1,12 @@
-###############################################################################
-# Copyright (c) 2012 IBM Corporation 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:
-# IBM Corporation - initial API and implementation
-###############################################################################
-MulticoreVisualizer_name=Multicore Visualizer
-MulticoreVisualizer_tooltip=Displays current state of selected debug target
+###############################################################################
+# Copyright (c) 2012 IBM Corporation 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:
+# IBM Corporation - initial API and implementation
+###############################################################################
+MulticoreVisualizer_name=Multicore Visualizer
+MulticoreVisualizer_tooltip=Displays current state of selected debug target
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/service/CommonDsfTest.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/service/CommonDsfTest.java
index 094bcb18f7..5182a0ad47 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/service/CommonDsfTest.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/gdb/service/CommonDsfTest.java
@@ -1,109 +1,109 @@
-/*******************************************************************************
- * Copyright (c) 2017 Renesas Electronics 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:
- * Bruno Medeiros (Renesas) - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.dsf.gdb.service;
-
-import static org.junit.Assert.fail;
-
-import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
-import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
-import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor;
-import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
-import org.eclipse.cdt.dsf.debug.model.DsfLaunch;
-import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
-import org.eclipse.cdt.dsf.service.DsfSession;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.core.model.ISourceLocator;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-
-/**
- * Helper base class for running DSF related tests
- */
-public class CommonDsfTest extends CommonTest {
-
- protected static DsfSession fSession = null;
-
- /**
- * Setup the test.
- * The session is typically configured once per class load, but we allow subclasses to override this,
- * and sometimes re-setup during a test (or interactive debugging).
- * Therefore {@link Before} is used, not {@link BeforeClass}.
- */
- @Before
- public void setup() {
- if(fSession != null) {
- return; // Already set-up
- }
-
- doSetupSession();
- }
-
- protected void doSetupSession() {
- fSession = DsfSession.startSession(new DefaultDsfExecutor(GdbPlugin.PLUGIN_ID), GdbPlugin.PLUGIN_ID);
-
- registerLaunch();
- }
-
- @AfterClass
- public static void tearDown() {
- if(fSession != null) {
- DsfSession.endSession(fSession);
- fSession = null;
- }
- }
-
- protected ILaunchConfigurationType getCLaunchConfigType() {
- return getLaunchManager().getLaunchConfigurationType(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_APP);
- }
-
- protected ILaunchManager getLaunchManager() {
- return DebugPlugin.getDefault().getLaunchManager();
- }
-
- protected void registerLaunch() {
- ILaunchConfigurationWorkingCopy lc;
- try {
- lc = getCLaunchConfigType().newInstance(null, "TestLaunch");
- } catch(CoreException e) {
- fail(e.getMessage());
- return;
- }
- ISourceLocator sourceLocator = null;
- DsfLaunch dsfLaunch = new DsfLaunch(lc, ILaunchManager.DEBUG_MODE, sourceLocator);
- fSession.registerModelAdapter(ILaunch.class, dsfLaunch);
- }
-
- protected RequestMonitor newRequestMonitor() {
- return new RequestMonitor(fSession.getExecutor(), null);
- }
-
- protected <T> DataRequestMonitor<T> newDataRequestMonitor() {
- return new DataRequestMonitor<>(fSession.getExecutor(), null);
- }
-}
-
-/**
- * Misc test utilities.
- */
-class CommonTest {
- /* ----------------- ----------------- */
-
- @SafeVarargs
- public static <T> T[] array(T... elems) {
- return elems;
- }
+/*******************************************************************************
+ * Copyright (c) 2017 Renesas Electronics 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:
+ * Bruno Medeiros (Renesas) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.gdb.service;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor;
+import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
+import org.eclipse.cdt.dsf.debug.model.DsfLaunch;
+import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.ISourceLocator;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+/**
+ * Helper base class for running DSF related tests
+ */
+public class CommonDsfTest extends CommonTest {
+
+ protected static DsfSession fSession = null;
+
+ /**
+ * Setup the test.
+ * The session is typically configured once per class load, but we allow subclasses to override this,
+ * and sometimes re-setup during a test (or interactive debugging).
+ * Therefore {@link Before} is used, not {@link BeforeClass}.
+ */
+ @Before
+ public void setup() {
+ if(fSession != null) {
+ return; // Already set-up
+ }
+
+ doSetupSession();
+ }
+
+ protected void doSetupSession() {
+ fSession = DsfSession.startSession(new DefaultDsfExecutor(GdbPlugin.PLUGIN_ID), GdbPlugin.PLUGIN_ID);
+
+ registerLaunch();
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ if(fSession != null) {
+ DsfSession.endSession(fSession);
+ fSession = null;
+ }
+ }
+
+ protected ILaunchConfigurationType getCLaunchConfigType() {
+ return getLaunchManager().getLaunchConfigurationType(ICDTLaunchConfigurationConstants.ID_LAUNCH_C_APP);
+ }
+
+ protected ILaunchManager getLaunchManager() {
+ return DebugPlugin.getDefault().getLaunchManager();
+ }
+
+ protected void registerLaunch() {
+ ILaunchConfigurationWorkingCopy lc;
+ try {
+ lc = getCLaunchConfigType().newInstance(null, "TestLaunch");
+ } catch(CoreException e) {
+ fail(e.getMessage());
+ return;
+ }
+ ISourceLocator sourceLocator = null;
+ DsfLaunch dsfLaunch = new DsfLaunch(lc, ILaunchManager.DEBUG_MODE, sourceLocator);
+ fSession.registerModelAdapter(ILaunch.class, dsfLaunch);
+ }
+
+ protected RequestMonitor newRequestMonitor() {
+ return new RequestMonitor(fSession.getExecutor(), null);
+ }
+
+ protected <T> DataRequestMonitor<T> newDataRequestMonitor() {
+ return new DataRequestMonitor<>(fSession.getExecutor(), null);
+ }
+}
+
+/**
+ * Misc test utilities.
+ */
+class CommonTest {
+ /* ----------------- ----------------- */
+
+ @SafeVarargs
+ public static <T> T[] array(T... elems) {
+ return elems;
+ }
} \ No newline at end of file
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/mi/service/command/commands/TestMIGDBSetSysroot.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/mi/service/command/commands/TestMIGDBSetSysroot.java
index 2de9908980..50623c1373 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/mi/service/command/commands/TestMIGDBSetSysroot.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.tests/src/org/eclipse/cdt/dsf/mi/service/command/commands/TestMIGDBSetSysroot.java
@@ -1,73 +1,73 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ingenico.
- * 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:
- * Ingenico - Sysroot with spaces (Bug 497693)
- *******************************************************************************/
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import static org.junit.Assert.assertEquals;
-
-import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor;
-import org.eclipse.cdt.dsf.datamodel.IDMContext;
-import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
-import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
-import org.eclipse.cdt.dsf.gdb.service.command.GDBControlDMContext;
-import org.eclipse.cdt.dsf.service.DsfSession;
-import org.junit.Test;
-
-/**
- * Verifies that the set sysroot MI command don't add double quotes if path contains space.
- *
- */
-public class TestMIGDBSetSysroot {
-
- @Test
- public void pathWithSpaceShouldNotBe() {
- MIGDBSetSysroot setSysrootCommand = new MIGDBSetSysroot(new TestContext(), "/tmp/test with space/");
- assertEquals("Wrong syntax for command", "-gdb-set sysroot /tmp/test with space/\n",
- setSysrootCommand.constructCommand());
- }
-
- @Test
- public void pathWithDoubleQuotesShouldNotBe() {
- MIGDBSetSysroot setSysrootCommand = new MIGDBSetSysroot(new TestContext(), "/tmp/test with\"double quotes/");
- assertEquals("Wrong syntax for command", "-gdb-set sysroot /tmp/test with\"double quotes/\n",
- setSysrootCommand.constructCommand());
-
-
- }
-
- private class TestContext implements ICommandControlDMContext {
- private DsfSession session = null;
-
- public TestContext() {
- session = DsfSession.startSession(new DefaultDsfExecutor(GdbPlugin.PLUGIN_ID), GdbPlugin.PLUGIN_ID);
- }
-
- @Override
- public IDMContext[] getParents() {
- return new IDMContext[] { new GDBControlDMContext(getSessionId(), "1") };
- }
-
- @Override
- public String getSessionId() {
- return session.getId();
- }
-
- @Override
- public <T> T getAdapter(Class<T> adapter) {
- return null;
- }
-
- @Override
- public String getCommandControlId() {
- return null;
- }
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2016 Ingenico.
+ * 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:
+ * Ingenico - Sysroot with spaces (Bug 497693)
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor;
+import org.eclipse.cdt.dsf.datamodel.IDMContext;
+import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
+import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
+import org.eclipse.cdt.dsf.gdb.service.command.GDBControlDMContext;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.junit.Test;
+
+/**
+ * Verifies that the set sysroot MI command don't add double quotes if path contains space.
+ *
+ */
+public class TestMIGDBSetSysroot {
+
+ @Test
+ public void pathWithSpaceShouldNotBe() {
+ MIGDBSetSysroot setSysrootCommand = new MIGDBSetSysroot(new TestContext(), "/tmp/test with space/");
+ assertEquals("Wrong syntax for command", "-gdb-set sysroot /tmp/test with space/\n",
+ setSysrootCommand.constructCommand());
+ }
+
+ @Test
+ public void pathWithDoubleQuotesShouldNotBe() {
+ MIGDBSetSysroot setSysrootCommand = new MIGDBSetSysroot(new TestContext(), "/tmp/test with\"double quotes/");
+ assertEquals("Wrong syntax for command", "-gdb-set sysroot /tmp/test with\"double quotes/\n",
+ setSysrootCommand.constructCommand());
+
+
+ }
+
+ private class TestContext implements ICommandControlDMContext {
+ private DsfSession session = null;
+
+ public TestContext() {
+ session = DsfSession.startSession(new DefaultDsfExecutor(GdbPlugin.PLUGIN_ID), GdbPlugin.PLUGIN_ID);
+ }
+
+ @Override
+ public IDMContext[] getParents() {
+ return new IDMContext[] { new GDBControlDMContext(getSessionId(), "1") };
+ }
+
+ @Override
+ public String getSessionId() {
+ return session.getId();
+ }
+
+ @Override
+ public <T> T getAdapter(Class<T> adapter) {
+ return null;
+ }
+
+ @Override
+ public String getCommandControlId() {
+ return null;
+ }
+ }
+
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbDebugOptions.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbDebugOptions.java
index 3db5fe29c4..916c38b65a 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbDebugOptions.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbDebugOptions.java
@@ -1,123 +1,123 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2014 Sage Electronic Engineering, LLC. 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:
- * Jason Litton (Sage Electronic Engineering, LLC) - initial API and implementation
+/*******************************************************************************
+ * Copyright (c) 2012, 2014 Sage Electronic Engineering, LLC. 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:
+ * Jason Litton (Sage Electronic Engineering, LLC) - initial API and implementation
*******************************************************************************/
-
-package org.eclipse.cdt.dsf.gdb.internal;
-
-import java.util.Hashtable;
-
-import org.eclipse.osgi.service.debug.DebugOptions;
-import org.eclipse.osgi.service.debug.DebugOptionsListener;
-import org.eclipse.osgi.service.debug.DebugTrace;
-import org.osgi.framework.BundleContext;
-
-/**
- * Hooks our debug options to the Platform trace functionality.
- * In essence, we can open Window -> Preferences -> Tracing
- * and turn on debug options for this package. The debug output
- * will come out on the console and can be saved directly to
- * a file. Classes that need to be debugged can call into
- * GdbDebugOptions to get debug flags. If new flags need to be
- * created, they will need to have a unique identifier and added to
- * the .options file in this plugin
- *
- * @since 4.1
- *
- */
-public class GdbDebugOptions implements DebugOptionsListener {
-
- private static final String DEBUG_FLAG = "org.eclipse.cdt.dsf.gdb/debug"; //$NON-NLS-1$
- private static final String DEBUG_TIMEOUTS_FLAG = "org.eclipse.cdt.dsf.gdb/debug/timeouts"; //$NON-NLS-1$
-
- public static boolean DEBUG = false;
- public static boolean DEBUG_COMMAND_TIMEOUTS = false;
-
- /**
- * The {@link DebugTrace} object to print to OSGi tracing
- */
- private static DebugTrace fgDebugTrace;
-
- /**
- * Constructor
- */
- public GdbDebugOptions(BundleContext context) {
- Hashtable<String, String> props = new Hashtable<String, String>(2);
- props.put(org.eclipse.osgi.service.debug.DebugOptions.LISTENER_SYMBOLICNAME, GdbPlugin.getUniqueIdentifier());
- context.registerService(DebugOptionsListener.class.getName(), this, props);
- }
-
-
- @Override
- public void optionsChanged(DebugOptions options) {
- fgDebugTrace = options.newDebugTrace(GdbPlugin.getUniqueIdentifier());
- DEBUG = options.getBooleanOption(DEBUG_FLAG, false);
- DEBUG_COMMAND_TIMEOUTS = options.getBooleanOption(DEBUG_TIMEOUTS_FLAG, false);
- }
-
- /**
- * Prints the given message to System.out and to the OSGi tracing (if started)
- * @param option the option or <code>null</code>
- * @param message the message to print or <code>null</code>
- * @param throwable the {@link Throwable} or <code>null</code>
- */
- public static void trace(String option, String message, Throwable throwable) {
- trace(option, message, 100, throwable);
- }
-
- /**
- * Prints the given message to System.out and to the OSGi tracing (if started)
- * @param option the option or <code>null</code>
- * @param message the message to print or <code>null</code>
- * @param lineMax the number of character at which point the line should be
- * split. Minimum 100. Negative number to indicate no split.
- * @param throwable the {@link Throwable} or <code>null</code>
- */
- public static void trace(String option, String message, int lineMax, Throwable throwable) {
- if (lineMax < 0) {
- lineMax = Integer.MAX_VALUE;
- } else if (lineMax < 100) {
- lineMax = 100;
- }
-
- //divide the string into substrings of 'lineMax' chars or less for printing to console
- String systemPrintableMessage = message;
- while (systemPrintableMessage.length() > lineMax) {
- String partial = systemPrintableMessage.substring(0, lineMax);
- systemPrintableMessage = systemPrintableMessage.substring(lineMax);
- System.out.println(partial + "\\"); //$NON-NLS-1$
- }
- System.out.print(systemPrintableMessage);
- //then pass the original message to be traced into a file
- if(fgDebugTrace != null) {
- fgDebugTrace.trace(option, message, throwable);
- }
- }
-
- /**
- * Prints the given message to System.out and to the OSGi tracing (if enabled)
- *
- * @param message the message or <code>null</code>
- * @param lineMax the number of character at which point the line should be
- * split. Minimum 100. Negative number to indicate no split.
- */
- public static void trace(String message, int lineMax) {
- trace(null, message, lineMax, null);
- }
-
- /**
- * Prints the given message to System.out and to the OSGi tracing (if enabled)
- *
- * @param message the message or <code>null</code>
- */
- public static void trace(String message) {
- trace(null, message, null);
- }
-
-}
+
+package org.eclipse.cdt.dsf.gdb.internal;
+
+import java.util.Hashtable;
+
+import org.eclipse.osgi.service.debug.DebugOptions;
+import org.eclipse.osgi.service.debug.DebugOptionsListener;
+import org.eclipse.osgi.service.debug.DebugTrace;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Hooks our debug options to the Platform trace functionality.
+ * In essence, we can open Window -> Preferences -> Tracing
+ * and turn on debug options for this package. The debug output
+ * will come out on the console and can be saved directly to
+ * a file. Classes that need to be debugged can call into
+ * GdbDebugOptions to get debug flags. If new flags need to be
+ * created, they will need to have a unique identifier and added to
+ * the .options file in this plugin
+ *
+ * @since 4.1
+ *
+ */
+public class GdbDebugOptions implements DebugOptionsListener {
+
+ private static final String DEBUG_FLAG = "org.eclipse.cdt.dsf.gdb/debug"; //$NON-NLS-1$
+ private static final String DEBUG_TIMEOUTS_FLAG = "org.eclipse.cdt.dsf.gdb/debug/timeouts"; //$NON-NLS-1$
+
+ public static boolean DEBUG = false;
+ public static boolean DEBUG_COMMAND_TIMEOUTS = false;
+
+ /**
+ * The {@link DebugTrace} object to print to OSGi tracing
+ */
+ private static DebugTrace fgDebugTrace;
+
+ /**
+ * Constructor
+ */
+ public GdbDebugOptions(BundleContext context) {
+ Hashtable<String, String> props = new Hashtable<String, String>(2);
+ props.put(org.eclipse.osgi.service.debug.DebugOptions.LISTENER_SYMBOLICNAME, GdbPlugin.getUniqueIdentifier());
+ context.registerService(DebugOptionsListener.class.getName(), this, props);
+ }
+
+
+ @Override
+ public void optionsChanged(DebugOptions options) {
+ fgDebugTrace = options.newDebugTrace(GdbPlugin.getUniqueIdentifier());
+ DEBUG = options.getBooleanOption(DEBUG_FLAG, false);
+ DEBUG_COMMAND_TIMEOUTS = options.getBooleanOption(DEBUG_TIMEOUTS_FLAG, false);
+ }
+
+ /**
+ * Prints the given message to System.out and to the OSGi tracing (if started)
+ * @param option the option or <code>null</code>
+ * @param message the message to print or <code>null</code>
+ * @param throwable the {@link Throwable} or <code>null</code>
+ */
+ public static void trace(String option, String message, Throwable throwable) {
+ trace(option, message, 100, throwable);
+ }
+
+ /**
+ * Prints the given message to System.out and to the OSGi tracing (if started)
+ * @param option the option or <code>null</code>
+ * @param message the message to print or <code>null</code>
+ * @param lineMax the number of character at which point the line should be
+ * split. Minimum 100. Negative number to indicate no split.
+ * @param throwable the {@link Throwable} or <code>null</code>
+ */
+ public static void trace(String option, String message, int lineMax, Throwable throwable) {
+ if (lineMax < 0) {
+ lineMax = Integer.MAX_VALUE;
+ } else if (lineMax < 100) {
+ lineMax = 100;
+ }
+
+ //divide the string into substrings of 'lineMax' chars or less for printing to console
+ String systemPrintableMessage = message;
+ while (systemPrintableMessage.length() > lineMax) {
+ String partial = systemPrintableMessage.substring(0, lineMax);
+ systemPrintableMessage = systemPrintableMessage.substring(lineMax);
+ System.out.println(partial + "\\"); //$NON-NLS-1$
+ }
+ System.out.print(systemPrintableMessage);
+ //then pass the original message to be traced into a file
+ if(fgDebugTrace != null) {
+ fgDebugTrace.trace(option, message, throwable);
+ }
+ }
+
+ /**
+ * Prints the given message to System.out and to the OSGi tracing (if enabled)
+ *
+ * @param message the message or <code>null</code>
+ * @param lineMax the number of character at which point the line should be
+ * split. Minimum 100. Negative number to indicate no split.
+ */
+ public static void trace(String message, int lineMax) {
+ trace(null, message, lineMax, null);
+ }
+
+ /**
+ * Prints the given message to System.out and to the OSGi tracing (if enabled)
+ *
+ * @param message the message or <code>null</code>
+ */
+ public static void trace(String message) {
+ trace(null, message, null);
+ }
+
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/CommandFactory_6_8.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/CommandFactory_6_8.java
index 6388702239..b8b1abd946 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/CommandFactory_6_8.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/CommandFactory_6_8.java
@@ -1,40 +1,40 @@
-/*******************************************************************************
- * Copyright (c) 2010 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ericsson - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.dsf.gdb.service.command;
-
-import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext;
-import org.eclipse.cdt.dsf.debug.service.command.ICommand;
-import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
-import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakInsert;
-import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakInsertInfo;
-
-/**
- * A command factory for commands that should only be used starting with GDB 6.8
- * @since 4.0 */
-public class CommandFactory_6_8 extends CommandFactory {
-
- @Override
- public ICommand<MIBreakInsertInfo> createMIBreakInsert(IBreakpointsTargetDMContext ctx, String func) {
- return new MIBreakInsert(ctx, func, true);
- }
-
- @Override
- public ICommand<MIBreakInsertInfo> createMIBreakInsert(IBreakpointsTargetDMContext ctx, boolean isTemporary,
- boolean isHardware, String condition, int ignoreCount, String line, String tid) {
- return new MIBreakInsert(ctx, isTemporary, isHardware, condition, ignoreCount, line, tid, true);
- }
-
- @Override
- public ICommand<MIBreakInsertInfo> createMIBreakInsert(IBreakpointsTargetDMContext ctx, boolean isTemporary,
- boolean isHardware, String condition, int ignoreCount, String location, String tid, boolean disabled, boolean isTracepoint) {
- return new MIBreakInsert(ctx, isTemporary, isHardware, condition, ignoreCount, location, tid, disabled, isTracepoint, true);
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ericsson - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.gdb.service.command;
+
+import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointsTargetDMContext;
+import org.eclipse.cdt.dsf.debug.service.command.ICommand;
+import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
+import org.eclipse.cdt.dsf.mi.service.command.commands.MIBreakInsert;
+import org.eclipse.cdt.dsf.mi.service.command.output.MIBreakInsertInfo;
+
+/**
+ * A command factory for commands that should only be used starting with GDB 6.8
+ * @since 4.0 */
+public class CommandFactory_6_8 extends CommandFactory {
+
+ @Override
+ public ICommand<MIBreakInsertInfo> createMIBreakInsert(IBreakpointsTargetDMContext ctx, String func) {
+ return new MIBreakInsert(ctx, func, true);
+ }
+
+ @Override
+ public ICommand<MIBreakInsertInfo> createMIBreakInsert(IBreakpointsTargetDMContext ctx, boolean isTemporary,
+ boolean isHardware, String condition, int ignoreCount, String line, String tid) {
+ return new MIBreakInsert(ctx, isTemporary, isHardware, condition, ignoreCount, line, tid, true);
+ }
+
+ @Override
+ public ICommand<MIBreakInsertInfo> createMIBreakInsert(IBreakpointsTargetDMContext ctx, boolean isTemporary,
+ boolean isHardware, String condition, int ignoreCount, String location, String tid, boolean disabled, boolean isTracepoint) {
+ return new MIBreakInsert(ctx, isTemporary, isHardware, condition, ignoreCount, location, tid, disabled, isTracepoint, true);
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIJump.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIJump.java
index c6c02a7c31..bfbc007c6d 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIJump.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/CLIJump.java
@@ -1,28 +1,28 @@
-/*******************************************************************************
- * Copyright (c) 2010 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ericsson - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
-import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
-
-/**
- * jump LINESPEC
- * jump LOCATION
- * Resume execution at line LINESPEC or at address given by LOCATION.
- *
- * @since 3.0
- */
-public class CLIJump extends CLICommand<MIInfo> {
-
- public CLIJump(IExecutionDMContext ctx, String location) {
- super(ctx, "jump " + location); //$NON-NLS-1$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ericsson - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
+import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
+
+/**
+ * jump LINESPEC
+ * jump LOCATION
+ * Resume execution at line LINESPEC or at address given by LOCATION.
+ *
+ * @since 3.0
+ */
+public class CLIJump extends CLICommand<MIInfo> {
+
+ public CLIJump(IExecutionDMContext ctx, String location) {
+ super(ctx, "jump " + location); //$NON-NLS-1$
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIExecArguments.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIExecArguments.java
index 15753e1336..36f98f216b 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIExecArguments.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIExecArguments.java
@@ -1,31 +1,31 @@
-/*******************************************************************************
- * Copyright (c) 2011 Tensilica 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:
- * Abeer Bagul (Tensilica) - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
-import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
-
-/**
- *
- * -exec-arguments ARGS
- *
- * Set the inferior program arguments, to be used in the next `-exec-run'.
- * Equivalent to using {@link MIGDBSetArgs}
- *
- * @since 4.0
- */
-public class MIExecArguments extends MICommand<MIInfo>
-{
- public MIExecArguments(IMIContainerDMContext ctx, String[] args) {
- super(ctx, "-exec-arguments", args); //$NON-NLS-1$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2011 Tensilica 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:
+ * Abeer Bagul (Tensilica) - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
+import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
+
+/**
+ *
+ * -exec-arguments ARGS
+ *
+ * Set the inferior program arguments, to be used in the next `-exec-run'.
+ * Equivalent to using {@link MIGDBSetArgs}
+ *
+ * @since 4.0
+ */
+public class MIExecArguments extends MICommand<MIInfo>
+{
+ public MIExecArguments(IMIContainerDMContext ctx, String[] args) {
+ super(ctx, "-exec-arguments", args); //$NON-NLS-1$
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetCharset.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetCharset.java
index 1b842f27ee..e6c6bbd8c6 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetCharset.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetCharset.java
@@ -1,30 +1,30 @@
-/*******************************************************************************
- * Copyright (c) 2012 Mathias Kunter 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:
- * Mathias Kunter - Initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
-
-/**
- *
- * -gdb-set charset CHARSET
- *
- * Sets both the current host and target charset to CHARSET. The host charset is the
- * charset used by gdb. The target charset is the charset used by the char type of the
- * inferior program.
- *
- * @since 4.1
- */
-public class MIGDBSetCharset extends MIGDBSet {
- public MIGDBSetCharset(ICommandControlDMContext ctx, String charset) {
- super(ctx, new String[] {"charset", charset}); //$NON-NLS-1$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Mathias Kunter 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:
+ * Mathias Kunter - Initial API and implementation
+*******************************************************************************/
+
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
+
+/**
+ *
+ * -gdb-set charset CHARSET
+ *
+ * Sets both the current host and target charset to CHARSET. The host charset is the
+ * charset used by gdb. The target charset is the charset used by the char type of the
+ * inferior program.
+ *
+ * @since 4.1
+ */
+public class MIGDBSetCharset extends MIGDBSet {
+ public MIGDBSetCharset(ICommandControlDMContext ctx, String charset) {
+ super(ctx, new String[] {"charset", charset}); //$NON-NLS-1$
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetHostCharset.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetHostCharset.java
index 86047488bf..59cf05f257 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetHostCharset.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetHostCharset.java
@@ -1,28 +1,28 @@
-/*******************************************************************************
- * Copyright (c) 2012 Mathias Kunter 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:
- * Mathias Kunter - Initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
-
-/**
- *
- * -gdb-set host-charset CHARSET
- *
- * Sets the current host charset to CHARSET. The host charset is the charset used by gdb.
- *
- * @since 4.1
- */
-public class MIGDBSetHostCharset extends MIGDBSet {
- public MIGDBSetHostCharset(ICommandControlDMContext ctx, String hostCharset) {
- super(ctx, new String[] {"host-charset", hostCharset}); //$NON-NLS-1$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Mathias Kunter 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:
+ * Mathias Kunter - Initial API and implementation
+*******************************************************************************/
+
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
+
+/**
+ *
+ * -gdb-set host-charset CHARSET
+ *
+ * Sets the current host charset to CHARSET. The host charset is the charset used by gdb.
+ *
+ * @since 4.1
+ */
+public class MIGDBSetHostCharset extends MIGDBSet {
+ public MIGDBSetHostCharset(ICommandControlDMContext ctx, String hostCharset) {
+ super(ctx, new String[] {"host-charset", hostCharset}); //$NON-NLS-1$
+ }
+}
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
index 814b822dfa..e99d7a451b 100644
--- 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
@@ -1,27 +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$
- }
-}
+/*******************************************************************************
+ * 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/MIGDBSetPrintObject.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintObject.java
index f78900958e..cecd32a90f 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintObject.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintObject.java
@@ -1,30 +1,30 @@
-/*******************************************************************************
- * Copyright (c) 2012 Anton Gorenkov 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:
- * Anton Gorenkov - initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
-
-/**
- *
- * -gdb-set print object [on | off]
- *
- * When on:
- * for GDB <= 7.4, Runtime Type Information will be used in the gdb console.
- * for GDB >= 7.5, Runtime Type Information will be used in the debug views.
- * When off, only static type of variable is taken into account.
- *
- * @since 4.1
- */
-public class MIGDBSetPrintObject extends MIGDBSet {
- public MIGDBSetPrintObject(ICommandControlDMContext ctx, boolean enable) {
- super(ctx, new String[] {"print", "object", enable ? "on" : "off"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Anton Gorenkov 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:
+ * Anton Gorenkov - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
+
+/**
+ *
+ * -gdb-set print object [on | off]
+ *
+ * When on:
+ * for GDB <= 7.4, Runtime Type Information will be used in the gdb console.
+ * for GDB >= 7.5, Runtime Type Information will be used in the debug views.
+ * When off, only static type of variable is taken into account.
+ *
+ * @since 4.1
+ */
+public class MIGDBSetPrintObject extends MIGDBSet {
+ public MIGDBSetPrintObject(ICommandControlDMContext ctx, boolean enable) {
+ super(ctx, new String[] {"print", "object", enable ? "on" : "off"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintSevenbitStrings.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintSevenbitStrings.java
index 9ec0c93ebc..4ea1730548 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintSevenbitStrings.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintSevenbitStrings.java
@@ -1,29 +1,29 @@
-/*******************************************************************************
- * Copyright (c) 2012 Mathias Kunter 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:
- * Mathias Kunter - Initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
-
-/**
- *
- * -gdb-set print sevenbit-strings [on | off]
- *
- * When on, gdb displays any eight-bit characters (in strings or character values) using
- * the octal escape notation \nnn. When off, prints full eight-bit characters.
- *
- * @since 4.1
- */
-public class MIGDBSetPrintSevenbitStrings extends MIGDBSet {
- public MIGDBSetPrintSevenbitStrings(ICommandControlDMContext ctx, boolean enable) {
- super(ctx, new String[] {"print", "sevenbit-strings", enable ? "on" : "off"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Mathias Kunter 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:
+ * Mathias Kunter - Initial API and implementation
+*******************************************************************************/
+
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
+
+/**
+ *
+ * -gdb-set print sevenbit-strings [on | off]
+ *
+ * When on, gdb displays any eight-bit characters (in strings or character values) using
+ * the octal escape notation \nnn. When off, prints full eight-bit characters.
+ *
+ * @since 4.1
+ */
+public class MIGDBSetPrintSevenbitStrings extends MIGDBSet {
+ public MIGDBSetPrintSevenbitStrings(ICommandControlDMContext ctx, boolean enable) {
+ super(ctx, new String[] {"print", "sevenbit-strings", enable ? "on" : "off"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetCharset.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetCharset.java
index 26f1def437..ac93ccfdec 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetCharset.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetCharset.java
@@ -1,29 +1,29 @@
-/*******************************************************************************
- * Copyright (c) 2012 Mathias Kunter 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:
- * Mathias Kunter - Initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
-
-/**
- *
- * -gdb-set target-charset CHARSET
- *
- * Sets the current target charset to CHARSET. The target charset is the charset used
- * by the char type of the inferior program.
- *
- * @since 4.1
- */
-public class MIGDBSetTargetCharset extends MIGDBSet {
- public MIGDBSetTargetCharset(ICommandControlDMContext ctx, String targetCharset) {
- super(ctx, new String[] {"target-charset", targetCharset}); //$NON-NLS-1$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Mathias Kunter 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:
+ * Mathias Kunter - Initial API and implementation
+*******************************************************************************/
+
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
+
+/**
+ *
+ * -gdb-set target-charset CHARSET
+ *
+ * Sets the current target charset to CHARSET. The target charset is the charset used
+ * by the char type of the inferior program.
+ *
+ * @since 4.1
+ */
+public class MIGDBSetTargetCharset extends MIGDBSet {
+ public MIGDBSetTargetCharset(ICommandControlDMContext ctx, String targetCharset) {
+ super(ctx, new String[] {"target-charset", targetCharset}); //$NON-NLS-1$
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetWideCharset.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetWideCharset.java
index 1ebf277075..afa5322f08 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetWideCharset.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetWideCharset.java
@@ -1,31 +1,31 @@
-/*******************************************************************************
- * Copyright (c) 2012 Mathias Kunter 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:
- * Mathias Kunter - Initial API and implementation
-*******************************************************************************/
-
-package org.eclipse.cdt.dsf.mi.service.command.commands;
-
-import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
-
-/**
- *
- * -gdb-set target-wide-charset CHARSET
- *
- * Sets the current target wide charset to CHARSET. The target wide charset is the charset
- * used by the wchar_t type of the inferior program.
- *
- * Available with gdb 7.0
- *
- * @since 4.1
- */
-public class MIGDBSetTargetWideCharset extends MIGDBSet {
- public MIGDBSetTargetWideCharset(ICommandControlDMContext ctx, String targetWideCharset) {
- super(ctx, new String[] {"target-wide-charset", targetWideCharset}); //$NON-NLS-1$
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Mathias Kunter 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:
+ * Mathias Kunter - Initial API and implementation
+*******************************************************************************/
+
+package org.eclipse.cdt.dsf.mi.service.command.commands;
+
+import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
+
+/**
+ *
+ * -gdb-set target-wide-charset CHARSET
+ *
+ * Sets the current target wide charset to CHARSET. The target wide charset is the charset
+ * used by the wchar_t type of the inferior program.
+ *
+ * Available with gdb 7.0
+ *
+ * @since 4.1
+ */
+public class MIGDBSetTargetWideCharset extends MIGDBSet {
+ public MIGDBSetTargetWideCharset(ICommandControlDMContext ctx, String targetWideCharset) {
+ super(ctx, new String[] {"target-wide-charset", targetWideCharset}); //$NON-NLS-1$
+ }
+}
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
index 49fa6dddc8..1ffac2d0b1 100644
--- 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
@@ -1,34 +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<MIGDBShowNewConsoleInfo> {
-
- public MIGDBShowNewConsole(IDMContext ctx) {
- super(ctx, new String[] { "new-console" }); //$NON-NLS-1$
- }
-
- @Override
- public MIGDBShowNewConsoleInfo getResult(MIOutput miResult) {
- return new MIGDBShowNewConsoleInfo(miResult);
- }
-}
+/*******************************************************************************
+ * 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<MIGDBShowNewConsoleInfo> {
+
+ 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
index 3ba608be8d..c9cf9e24cb 100644
--- 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
@@ -1,51 +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 <code>null</code> if
- * new-console unsupported.
- */
- public Boolean isSet() {
- return fIsSet;
- }
-}
+/*******************************************************************************
+ * 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 <code>null</code> if
+ * new-console unsupported.
+ */
+ public Boolean isSet() {
+ return fIsSet;
+ }
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStringHandler.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStringHandler.java
index d0c9a86b95..63ccb20984 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStringHandler.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStringHandler.java
@@ -1,459 +1,459 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2016 Mathias Kunter 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:
- * Mathias Kunter - Initial Implementation (Bug 307311)
- *******************************************************************************/
-package org.eclipse.cdt.dsf.mi.service.command.output;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.text.ParseException;
-import java.util.EnumSet;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * The MIStringHandler class provides several static functions to handle C and / or MI strings.
- * @since 4.1
- */
-public class MIStringHandler {
-
- /**
- * A map of special characters which are used within escape notations to represent a
- * corresponding Unicode code point (i.e. character code).
- */
- // Use a LinkedHashMap to preserve order, so as to get 'e' and not 'E'
- private static Map<Character,Integer> fSpecialCharactersToCodePointMap = new LinkedHashMap<Character,Integer>();
- static {
- fSpecialCharactersToCodePointMap.put('a', 0x07); // Alert (bell) character
- fSpecialCharactersToCodePointMap.put('b', 0x08); // Backspace character
- fSpecialCharactersToCodePointMap.put('e', 0x1B); // GNU extension: Escape character
- fSpecialCharactersToCodePointMap.put('E', 0x1B); // same as 'e'
- fSpecialCharactersToCodePointMap.put('f', 0x0C); // Form feed character
- fSpecialCharactersToCodePointMap.put('n', 0x0A); // New line character
- fSpecialCharactersToCodePointMap.put('r', 0x0D); // Carriage return character
- fSpecialCharactersToCodePointMap.put('t', 0x09); // Horizontal tabulation character
- fSpecialCharactersToCodePointMap.put('v', 0x0B); // Vertical tabulation character
- fSpecialCharactersToCodePointMap.put('\'', 0x27); // Single quotation mark
- fSpecialCharactersToCodePointMap.put('"', 0x22); // Double quotation mark
- fSpecialCharactersToCodePointMap.put('\\', 0x5C); // Backslash
- fSpecialCharactersToCodePointMap.put('?', 0x3F); // Literal question mark
- }
-
- /**
- * An internal helper enumeration which holds the current status while parsing an escaped
- * text sequence.
- */
- private enum EscapeStatus {
- NONE,
- BEGIN,
- OCTAL_NUMBER,
- HEX_NUMBER,
- UNICODE_SHORT_NUMBER,
- UNICODE_LONG_NUMBER,
- VALID,
- INVALID
- }
-
- /**
- * An enumeration defining the escape sequences which should be parsed.
- */
- public enum ParseFlags {
- SPECIAL_CHARS,
- OCTAL_NUMBERS,
- HEX_NUMBERS,
- UNICODE_SHORT_NUMBERS,
- UNICODE_LONG_NUMBERS
- }
-
- /**
- * Translates the given C string into a string suitable for display. This includes handling
- * of escaped characters and different string encodings. This is necessary in order to correctly
- * deal with non-ASCII strings.
- * @param str The C string to translate.
- * @param escapeChars Defines whether non-printable characters should be escaped within
- * the translated string, or not.
- * @return The translated string.
- */
- public static String translateCString(String str, boolean escapeChars) {
- if (escapeChars) {
- // Don't parse the special character escape notations here. We can do this here because
- // we want to keep them in their escaped form anyway, and because the following string
- // transcoding process isn't affected by escaped special chars. By doing so we avoid
- // caring about some nasty details of the special character escaping process: for
- // example, single quotation marks are commonly only escaped within character constants,
- // while double quotation marks are commonly only escaped within string constants. By
- // not parsing the special character escape notations at all here, we just keep the
- // original special character escaping provided by the given MI string.
- str = parseString(str, EnumSet.complementOf(EnumSet.of(ParseFlags.SPECIAL_CHARS)));
- } else {
- // Parse all escaped characters.
- str = parseString(str);
- }
-
- // Transcode the string in order to handle non-ASCII strings correctly.
- str = transcodeString(str);
-
- if (escapeChars) {
- // Escape any non-printable characters again, as we want to be able to display them.
- // However, don't escape any printable special chars, as they haven't been parsed before.
- str = escapeString(str, false);
- } else {
- // No escaping necessary here. We however have to make sure that we use the correct line
- // separation character sequence.
- str = str.replace("\n", System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- return str;
- }
-
- /**
- * Returns whether the given character is a special character, or not.
- * @param c The character to test.
- * @return The test result.
- */
- public static boolean isSpecialChar(char c) {
- return fSpecialCharactersToCodePointMap.containsKey(c);
- }
-
- /**
- * Returns whether the given Unicode code point is a special code point, or not.
- * @param codePoint The Unicode code point to test.
- * @return The test result.
- */
- public static boolean isSpecialCodePoint(int codePoint) {
- return fSpecialCharactersToCodePointMap.containsValue(codePoint);
- }
-
- /**
- * Parses the given special character into an Unicode code point.
- * @param c The special character to parse.
- * @return The parsed Unicode code point.
- * @throws ParseException Thrown when the given character can't be parsed. This happens when it's
- * not a special character.
- */
- public static int parseSpecialChar(char c) throws ParseException {
- Integer codePoint = fSpecialCharactersToCodePointMap.get(c);
- if (codePoint != null) {
- return codePoint;
- }
- throw new ParseException("The given character '" + c + "' is not a special character.", 0); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Parses the given special Unicode code point into a character.
- * @param codePoint The special Unicode code point to parse.
- * @return The parsed character.
- * @throws ParseException Thrown when the given Unicode code point can't be parsed. This happens
- * when it's not a special code point.
- */
- public static char parseSpecialCodePoint(int codePoint) throws ParseException {
- for (Entry<Character, Integer> entry : fSpecialCharactersToCodePointMap.entrySet()) {
- if (entry.getValue().equals(codePoint)) {
- return entry.getKey();
- }
- }
- throw new ParseException("The given Unicode code point " + codePoint + " is not a special code point.", 0); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * This is an overloaded function. See the Javadoc of the other function overload for details.
- * @param str The string which should be parsed.
- * @return The parsed string.
- */
- public static String parseString(String str) {
- return parseString(str, EnumSet.allOf(ParseFlags.class));
- }
-
- /**
- * Parses any escaped characters and replaces them with their corresponding Unicode code points.
- * This function parses all escape notations which are supported by gcc and / or gdb. Those are:</br></br>
- *
- * <ul>
- * <li>Special char escape notations: \a, \b, \e, \E, \f, \n, \r, \t, \v, \', \", \\, and \?</li>
- *
- * <li>Octal escape notation: An initial backslash, followed by 1, 2, or 3 octal digits. Values
- * above 0xFF are ignored. Octal escape notations may not use more than 3 octal digits.</li>
- *
- * <li>Hexadecimal escape notation: An initial backslash, followed by an "x" and 1 or more
- * hexadecimal digits. Hexadecimal escape notations may not use more than 4 hexadecimal digits
- * (although gcc accepts hexadecimal escape notations of any arbitrary length).</li>
- *
- * <li>Short Unicode escape notation: An initial backslash, followed by an "u" and exactly 4
- * hexadecimal digits.</li>
- *
- * <li>Long Unicode escape notation: An initial backslash, followed by an "U" and exactly 8
- * hexadecimal digits.</li>
- * </ul>
- * @param str The string which should be parsed.
- * @param parseFlags The set of escape notations which should be parsed.
- * @return The parsed string.
- */
- public static String parseString(String str, EnumSet<ParseFlags> parseFlags) {
- StringBuilder buffer = new StringBuilder();
- StringBuilder escapeBuffer = new StringBuilder();
- EscapeStatus escStatus = EscapeStatus.NONE;
-
- for (int i = 0; i < str.length(); i++) {
- char c = str.charAt(i);
- boolean consumeChar = true;
- boolean isLastChar = i == str.length() - 1;
-
- if (escStatus == EscapeStatus.NONE) {
- if (c == '\\') {
- // Escaping begins. Reset the escape buffer.
- escapeBuffer.setLength(0);
- escapeBuffer.append(c);
- escStatus = EscapeStatus.BEGIN;
- }
- } else if (escStatus == EscapeStatus.BEGIN) {
- if (parseFlags.contains(ParseFlags.SPECIAL_CHARS) && isSpecialChar(c)) {
- try {
- buffer.appendCodePoint(parseSpecialChar(c));
- escStatus = EscapeStatus.VALID;
- } catch (ParseException e) {
- // This is just for completeness. We will actually never catch any ParseException here
- // since we already checked the character with isSpecialChar() before.
- escapeBuffer.append(c);
- escStatus = EscapeStatus.INVALID;
- }
- } else if (parseFlags.contains(ParseFlags.OCTAL_NUMBERS) && c >= '0' && c <= '7') {
- escStatus = EscapeStatus.OCTAL_NUMBER;
- // Don't consume this character right now - as this wouldn't work if it's the last character.
- consumeChar = false;
- } else if (parseFlags.contains(ParseFlags.HEX_NUMBERS) && c == 'x') {
- escStatus = EscapeStatus.HEX_NUMBER;
- } else if (parseFlags.contains(ParseFlags.UNICODE_SHORT_NUMBERS) && c == 'u') {
- escStatus = EscapeStatus.UNICODE_SHORT_NUMBER;
- } else if (parseFlags.contains(ParseFlags.UNICODE_LONG_NUMBERS) && c == 'U') {
- escStatus = EscapeStatus.UNICODE_LONG_NUMBER;
- } else {
- escStatus = EscapeStatus.INVALID;
- }
- if (consumeChar) {
- escapeBuffer.append(c);
- }
- } else if (escStatus == EscapeStatus.HEX_NUMBER) {
- // Only consume this character if it belongs to the escape sequence.
- consumeChar = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
- if (consumeChar) {
- escapeBuffer.append(c);
- }
-
- if (!consumeChar || isLastChar || escapeBuffer.length() == 6) {
- // The escape sequence is terminated. Set the escape status to invalid until
- // we know that it's actually valid.
- escStatus = EscapeStatus.INVALID;
- if (escapeBuffer.length() > 2) {
- // Decode the hexadecimal number.
- try {
- int codePoint = Integer.parseInt(escapeBuffer.toString().substring(2), 16);
- if (codePoint <= 0x10FFFF) {
- buffer.appendCodePoint(codePoint);
- escStatus = EscapeStatus.VALID;
- }
- } catch (NumberFormatException e) {
- }
- }
- }
- } else if (escStatus == EscapeStatus.UNICODE_SHORT_NUMBER || escStatus == EscapeStatus.UNICODE_LONG_NUMBER) {
- // Only consume this character if it belongs to the escape sequence.
- consumeChar = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
- if (consumeChar) {
- escapeBuffer.append(c);
- }
-
- int finalLength = escStatus == EscapeStatus.UNICODE_SHORT_NUMBER ? 6 : 10;
- if (escapeBuffer.length() == finalLength) {
- // The escape sequence is terminated. Set the escape status to invalid until
- // we know that it's actually valid. Decode the hexadecimal number.
- escStatus = EscapeStatus.INVALID;
- try {
- int codePoint = Integer.parseInt(escapeBuffer.toString().substring(2), 16);
- if (codePoint <= 0x10FFFF) {
- buffer.appendCodePoint(codePoint);
- escStatus = EscapeStatus.VALID;
- }
- } catch (NumberFormatException e) {
- }
- } else if (!consumeChar || isLastChar) {
- // The escape sequence is terminated and invalid.
- escStatus = EscapeStatus.INVALID;
- }
- } else if (escStatus == EscapeStatus.OCTAL_NUMBER) {
- // Only consume this character if it belongs to the escape sequence.
- consumeChar = c >= '0' && c <= '7';
- if (consumeChar) {
- escapeBuffer.append(c);
- }
-
- if (!consumeChar || isLastChar || escapeBuffer.length() == 4) {
- // The escape sequence is terminated. Set the escape status to invalid until
- // we know that it's actually valid.
- escStatus = EscapeStatus.INVALID;
- if (escapeBuffer.length() > 1) {
- // Decode the octal number.
- try {
- int codePoint = Integer.parseInt(escapeBuffer.toString().substring(1), 8);
- if (codePoint <= 0xFF) {
- buffer.appendCodePoint(codePoint);
- escStatus = EscapeStatus.VALID;
- }
- } catch (NumberFormatException e) {
- }
- }
- }
- }
-
- if (escStatus == EscapeStatus.NONE) {
- // Current character isn't escaped - copy it over to the destination buffer.
- buffer.append(c);
- } else if (escStatus == EscapeStatus.VALID) {
- escStatus = EscapeStatus.NONE;
- } else if (escStatus == EscapeStatus.INVALID) {
- buffer.append(escapeBuffer);
- escStatus = EscapeStatus.NONE;
- }
-
- if (!consumeChar) {
- // Don't consume the current character.
- i--;
- }
- }
-
- // Check for non-finished escape sequences at the end of the string.
- if (escStatus != EscapeStatus.NONE) {
- buffer.append(escapeBuffer);
- }
-
- // Convert the buffer into a string and return it.
- return buffer.toString();
- }
-
- /**
- * Transcodes the given string. This is done as follows:</br></br>
- * 1) The given string is encoded into a binary byte buffer.</br></br>
- * 2) It's tested whether this binary byte buffer seems to represent a string which is encoded as
- * either ASCII, Latin-1, or UTF-8. If this is the case, the binary byte buffer is decoded back into
- * a string and this string is returned. If the test is negative, the given string is returned without
- * modification because its encoding can't be reliably determined in this case.
- * The most important use case of this function is to transcode a string which is actually UTF-8 but has
- * been incorrectly decoded as Latin-1 instead.
- * @param str The string to transcode.
- * @return The transcoded string.
- */
- public static String transcodeString(String str) {
- // Try to transcode the string from Latin-1 to UTF-8 (ASCII doesn't need to be explicitly
- // considered here since Latin-1 is backwards compatible with ASCII). The transcoding will
- // almost certainly only succeed if the string actually *is* encoded in UTF-8. If the
- // transcoding fails, the string is simply left unchanged.
- try {
- // First, try to encode the string as Latin-1 in order to obtain the binary byte
- // representation of the string.
- CharsetEncoder latin1Encoder = Charset.forName("ISO-8859-1").newEncoder(); //$NON-NLS-1$
- ByteBuffer stringBytes = latin1Encoder.encode(CharBuffer.wrap(str.toCharArray()));
-
- // Next, try to decode the string as UTF-8. This will almost certainly only succeed
- // if the string actually *is* encoded in UTF-8. Note that if the decoding fails,
- // an exception is thrown before the str variable is assigned. The original string
- // is therefore left unchanged in this case.
- CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder(); //$NON-NLS-1$
- str = utf8Decoder.decode(stringBytes).toString();
- } catch (Exception e) {
- }
-
- return str;
- }
-
- /**
- * Escapes any non-printable characters as well as the printable special characters single quotation
- * mark, double quotation mark, backslash, and literal question mark within the given string. Supports
- * the entire Unicode code space.
- * @param str The string which should be escaped.
- * @return The escaped string.
- */
- public static String escapeString(String str) {
- return escapeString(str, true);
- }
-
- /**
- * Escapes any non-printable characters within the given string. Supports the entire Unicode code space.
- * @param str The string which should be escaped.
- * @param escapePrintableSpecialChars Defines whether the printable special characters single
- * quotation mark, double quotation mark, backslash, and literal question mark should be
- * escaped as well, or not.
- * @return The escaped string.
- */
- public static String escapeString(String str, boolean escapePrintableSpecialChars) {
- StringBuilder buffer = new StringBuilder();
-
- for (int i = 0; i < str.length(); i++) {
- // Get the current character code point. Note that using the Java "char" data type isn't
- // sufficient here, as it can't handle all Unicode characters.
- int codePoint = str.codePointAt(i);
- if (Character.isSupplementaryCodePoint(codePoint)) {
- i++;
- }
-
- // Check the code point type of the character in order to determine whether it's
- // printable or not.
- int codePointType = Character.getType(codePoint);
- switch (codePointType) {
- case Character.LINE_SEPARATOR:
- case Character.PARAGRAPH_SEPARATOR:
- case Character.CONTROL:
- case Character.PRIVATE_USE:
- case Character.SURROGATE:
- case Character.UNASSIGNED:
- // Non-printable character.
- if (isSpecialCodePoint(codePoint)) {
- // Escape by using the special character escape notation.
- buffer.append('\\');
- try {
- buffer.append(parseSpecialCodePoint(codePoint));
- } catch (ParseException e) {
- buffer.appendCodePoint(codePoint);
- }
- } else if (codePoint == 0x00) {
- // Escape the null character separately - don't use leading zeros.
- buffer.append("\\0"); //$NON-NLS-1$
- } else if (codePoint <= 0xFF) {
- // Escape by using the octal escape notation.
- buffer.append(String.format("\\%03o", codePoint)); //$NON-NLS-1$
- } else if (codePoint <= 0xFFFF) {
- // Escape by using the short Unicode escape notation.
- buffer.append(String.format("\\u%04x", codePoint)); //$NON-NLS-1$
- } else {
- // Escape by using the long Unicode escape notation.
- buffer.append(String.format("\\U%08x", codePoint)); //$NON-NLS-1$
- }
- break;
- default:
- // Printable character.
- if (escapePrintableSpecialChars && isSpecialCodePoint(codePoint)) {
- // Escape by using the special character escape notation.
- buffer.append('\\');
- try {
- buffer.append(parseSpecialCodePoint(codePoint));
- } catch (ParseException e) {
- buffer.appendCodePoint(codePoint);
- }
- } else {
- // Don't escape.
- buffer.appendCodePoint(codePoint);
- }
- }
- }
-
- return buffer.toString();
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2016 Mathias Kunter 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:
+ * Mathias Kunter - Initial Implementation (Bug 307311)
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.mi.service.command.output;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.text.ParseException;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * The MIStringHandler class provides several static functions to handle C and / or MI strings.
+ * @since 4.1
+ */
+public class MIStringHandler {
+
+ /**
+ * A map of special characters which are used within escape notations to represent a
+ * corresponding Unicode code point (i.e. character code).
+ */
+ // Use a LinkedHashMap to preserve order, so as to get 'e' and not 'E'
+ private static Map<Character,Integer> fSpecialCharactersToCodePointMap = new LinkedHashMap<Character,Integer>();
+ static {
+ fSpecialCharactersToCodePointMap.put('a', 0x07); // Alert (bell) character
+ fSpecialCharactersToCodePointMap.put('b', 0x08); // Backspace character
+ fSpecialCharactersToCodePointMap.put('e', 0x1B); // GNU extension: Escape character
+ fSpecialCharactersToCodePointMap.put('E', 0x1B); // same as 'e'
+ fSpecialCharactersToCodePointMap.put('f', 0x0C); // Form feed character
+ fSpecialCharactersToCodePointMap.put('n', 0x0A); // New line character
+ fSpecialCharactersToCodePointMap.put('r', 0x0D); // Carriage return character
+ fSpecialCharactersToCodePointMap.put('t', 0x09); // Horizontal tabulation character
+ fSpecialCharactersToCodePointMap.put('v', 0x0B); // Vertical tabulation character
+ fSpecialCharactersToCodePointMap.put('\'', 0x27); // Single quotation mark
+ fSpecialCharactersToCodePointMap.put('"', 0x22); // Double quotation mark
+ fSpecialCharactersToCodePointMap.put('\\', 0x5C); // Backslash
+ fSpecialCharactersToCodePointMap.put('?', 0x3F); // Literal question mark
+ }
+
+ /**
+ * An internal helper enumeration which holds the current status while parsing an escaped
+ * text sequence.
+ */
+ private enum EscapeStatus {
+ NONE,
+ BEGIN,
+ OCTAL_NUMBER,
+ HEX_NUMBER,
+ UNICODE_SHORT_NUMBER,
+ UNICODE_LONG_NUMBER,
+ VALID,
+ INVALID
+ }
+
+ /**
+ * An enumeration defining the escape sequences which should be parsed.
+ */
+ public enum ParseFlags {
+ SPECIAL_CHARS,
+ OCTAL_NUMBERS,
+ HEX_NUMBERS,
+ UNICODE_SHORT_NUMBERS,
+ UNICODE_LONG_NUMBERS
+ }
+
+ /**
+ * Translates the given C string into a string suitable for display. This includes handling
+ * of escaped characters and different string encodings. This is necessary in order to correctly
+ * deal with non-ASCII strings.
+ * @param str The C string to translate.
+ * @param escapeChars Defines whether non-printable characters should be escaped within
+ * the translated string, or not.
+ * @return The translated string.
+ */
+ public static String translateCString(String str, boolean escapeChars) {
+ if (escapeChars) {
+ // Don't parse the special character escape notations here. We can do this here because
+ // we want to keep them in their escaped form anyway, and because the following string
+ // transcoding process isn't affected by escaped special chars. By doing so we avoid
+ // caring about some nasty details of the special character escaping process: for
+ // example, single quotation marks are commonly only escaped within character constants,
+ // while double quotation marks are commonly only escaped within string constants. By
+ // not parsing the special character escape notations at all here, we just keep the
+ // original special character escaping provided by the given MI string.
+ str = parseString(str, EnumSet.complementOf(EnumSet.of(ParseFlags.SPECIAL_CHARS)));
+ } else {
+ // Parse all escaped characters.
+ str = parseString(str);
+ }
+
+ // Transcode the string in order to handle non-ASCII strings correctly.
+ str = transcodeString(str);
+
+ if (escapeChars) {
+ // Escape any non-printable characters again, as we want to be able to display them.
+ // However, don't escape any printable special chars, as they haven't been parsed before.
+ str = escapeString(str, false);
+ } else {
+ // No escaping necessary here. We however have to make sure that we use the correct line
+ // separation character sequence.
+ str = str.replace("\n", System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ return str;
+ }
+
+ /**
+ * Returns whether the given character is a special character, or not.
+ * @param c The character to test.
+ * @return The test result.
+ */
+ public static boolean isSpecialChar(char c) {
+ return fSpecialCharactersToCodePointMap.containsKey(c);
+ }
+
+ /**
+ * Returns whether the given Unicode code point is a special code point, or not.
+ * @param codePoint The Unicode code point to test.
+ * @return The test result.
+ */
+ public static boolean isSpecialCodePoint(int codePoint) {
+ return fSpecialCharactersToCodePointMap.containsValue(codePoint);
+ }
+
+ /**
+ * Parses the given special character into an Unicode code point.
+ * @param c The special character to parse.
+ * @return The parsed Unicode code point.
+ * @throws ParseException Thrown when the given character can't be parsed. This happens when it's
+ * not a special character.
+ */
+ public static int parseSpecialChar(char c) throws ParseException {
+ Integer codePoint = fSpecialCharactersToCodePointMap.get(c);
+ if (codePoint != null) {
+ return codePoint;
+ }
+ throw new ParseException("The given character '" + c + "' is not a special character.", 0); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Parses the given special Unicode code point into a character.
+ * @param codePoint The special Unicode code point to parse.
+ * @return The parsed character.
+ * @throws ParseException Thrown when the given Unicode code point can't be parsed. This happens
+ * when it's not a special code point.
+ */
+ public static char parseSpecialCodePoint(int codePoint) throws ParseException {
+ for (Entry<Character, Integer> entry : fSpecialCharactersToCodePointMap.entrySet()) {
+ if (entry.getValue().equals(codePoint)) {
+ return entry.getKey();
+ }
+ }
+ throw new ParseException("The given Unicode code point " + codePoint + " is not a special code point.", 0); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * This is an overloaded function. See the Javadoc of the other function overload for details.
+ * @param str The string which should be parsed.
+ * @return The parsed string.
+ */
+ public static String parseString(String str) {
+ return parseString(str, EnumSet.allOf(ParseFlags.class));
+ }
+
+ /**
+ * Parses any escaped characters and replaces them with their corresponding Unicode code points.
+ * This function parses all escape notations which are supported by gcc and / or gdb. Those are:</br></br>
+ *
+ * <ul>
+ * <li>Special char escape notations: \a, \b, \e, \E, \f, \n, \r, \t, \v, \', \", \\, and \?</li>
+ *
+ * <li>Octal escape notation: An initial backslash, followed by 1, 2, or 3 octal digits. Values
+ * above 0xFF are ignored. Octal escape notations may not use more than 3 octal digits.</li>
+ *
+ * <li>Hexadecimal escape notation: An initial backslash, followed by an "x" and 1 or more
+ * hexadecimal digits. Hexadecimal escape notations may not use more than 4 hexadecimal digits
+ * (although gcc accepts hexadecimal escape notations of any arbitrary length).</li>
+ *
+ * <li>Short Unicode escape notation: An initial backslash, followed by an "u" and exactly 4
+ * hexadecimal digits.</li>
+ *
+ * <li>Long Unicode escape notation: An initial backslash, followed by an "U" and exactly 8
+ * hexadecimal digits.</li>
+ * </ul>
+ * @param str The string which should be parsed.
+ * @param parseFlags The set of escape notations which should be parsed.
+ * @return The parsed string.
+ */
+ public static String parseString(String str, EnumSet<ParseFlags> parseFlags) {
+ StringBuilder buffer = new StringBuilder();
+ StringBuilder escapeBuffer = new StringBuilder();
+ EscapeStatus escStatus = EscapeStatus.NONE;
+
+ for (int i = 0; i < str.length(); i++) {
+ char c = str.charAt(i);
+ boolean consumeChar = true;
+ boolean isLastChar = i == str.length() - 1;
+
+ if (escStatus == EscapeStatus.NONE) {
+ if (c == '\\') {
+ // Escaping begins. Reset the escape buffer.
+ escapeBuffer.setLength(0);
+ escapeBuffer.append(c);
+ escStatus = EscapeStatus.BEGIN;
+ }
+ } else if (escStatus == EscapeStatus.BEGIN) {
+ if (parseFlags.contains(ParseFlags.SPECIAL_CHARS) && isSpecialChar(c)) {
+ try {
+ buffer.appendCodePoint(parseSpecialChar(c));
+ escStatus = EscapeStatus.VALID;
+ } catch (ParseException e) {
+ // This is just for completeness. We will actually never catch any ParseException here
+ // since we already checked the character with isSpecialChar() before.
+ escapeBuffer.append(c);
+ escStatus = EscapeStatus.INVALID;
+ }
+ } else if (parseFlags.contains(ParseFlags.OCTAL_NUMBERS) && c >= '0' && c <= '7') {
+ escStatus = EscapeStatus.OCTAL_NUMBER;
+ // Don't consume this character right now - as this wouldn't work if it's the last character.
+ consumeChar = false;
+ } else if (parseFlags.contains(ParseFlags.HEX_NUMBERS) && c == 'x') {
+ escStatus = EscapeStatus.HEX_NUMBER;
+ } else if (parseFlags.contains(ParseFlags.UNICODE_SHORT_NUMBERS) && c == 'u') {
+ escStatus = EscapeStatus.UNICODE_SHORT_NUMBER;
+ } else if (parseFlags.contains(ParseFlags.UNICODE_LONG_NUMBERS) && c == 'U') {
+ escStatus = EscapeStatus.UNICODE_LONG_NUMBER;
+ } else {
+ escStatus = EscapeStatus.INVALID;
+ }
+ if (consumeChar) {
+ escapeBuffer.append(c);
+ }
+ } else if (escStatus == EscapeStatus.HEX_NUMBER) {
+ // Only consume this character if it belongs to the escape sequence.
+ consumeChar = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
+ if (consumeChar) {
+ escapeBuffer.append(c);
+ }
+
+ if (!consumeChar || isLastChar || escapeBuffer.length() == 6) {
+ // The escape sequence is terminated. Set the escape status to invalid until
+ // we know that it's actually valid.
+ escStatus = EscapeStatus.INVALID;
+ if (escapeBuffer.length() > 2) {
+ // Decode the hexadecimal number.
+ try {
+ int codePoint = Integer.parseInt(escapeBuffer.toString().substring(2), 16);
+ if (codePoint <= 0x10FFFF) {
+ buffer.appendCodePoint(codePoint);
+ escStatus = EscapeStatus.VALID;
+ }
+ } catch (NumberFormatException e) {
+ }
+ }
+ }
+ } else if (escStatus == EscapeStatus.UNICODE_SHORT_NUMBER || escStatus == EscapeStatus.UNICODE_LONG_NUMBER) {
+ // Only consume this character if it belongs to the escape sequence.
+ consumeChar = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
+ if (consumeChar) {
+ escapeBuffer.append(c);
+ }
+
+ int finalLength = escStatus == EscapeStatus.UNICODE_SHORT_NUMBER ? 6 : 10;
+ if (escapeBuffer.length() == finalLength) {
+ // The escape sequence is terminated. Set the escape status to invalid until
+ // we know that it's actually valid. Decode the hexadecimal number.
+ escStatus = EscapeStatus.INVALID;
+ try {
+ int codePoint = Integer.parseInt(escapeBuffer.toString().substring(2), 16);
+ if (codePoint <= 0x10FFFF) {
+ buffer.appendCodePoint(codePoint);
+ escStatus = EscapeStatus.VALID;
+ }
+ } catch (NumberFormatException e) {
+ }
+ } else if (!consumeChar || isLastChar) {
+ // The escape sequence is terminated and invalid.
+ escStatus = EscapeStatus.INVALID;
+ }
+ } else if (escStatus == EscapeStatus.OCTAL_NUMBER) {
+ // Only consume this character if it belongs to the escape sequence.
+ consumeChar = c >= '0' && c <= '7';
+ if (consumeChar) {
+ escapeBuffer.append(c);
+ }
+
+ if (!consumeChar || isLastChar || escapeBuffer.length() == 4) {
+ // The escape sequence is terminated. Set the escape status to invalid until
+ // we know that it's actually valid.
+ escStatus = EscapeStatus.INVALID;
+ if (escapeBuffer.length() > 1) {
+ // Decode the octal number.
+ try {
+ int codePoint = Integer.parseInt(escapeBuffer.toString().substring(1), 8);
+ if (codePoint <= 0xFF) {
+ buffer.appendCodePoint(codePoint);
+ escStatus = EscapeStatus.VALID;
+ }
+ } catch (NumberFormatException e) {
+ }
+ }
+ }
+ }
+
+ if (escStatus == EscapeStatus.NONE) {
+ // Current character isn't escaped - copy it over to the destination buffer.
+ buffer.append(c);
+ } else if (escStatus == EscapeStatus.VALID) {
+ escStatus = EscapeStatus.NONE;
+ } else if (escStatus == EscapeStatus.INVALID) {
+ buffer.append(escapeBuffer);
+ escStatus = EscapeStatus.NONE;
+ }
+
+ if (!consumeChar) {
+ // Don't consume the current character.
+ i--;
+ }
+ }
+
+ // Check for non-finished escape sequences at the end of the string.
+ if (escStatus != EscapeStatus.NONE) {
+ buffer.append(escapeBuffer);
+ }
+
+ // Convert the buffer into a string and return it.
+ return buffer.toString();
+ }
+
+ /**
+ * Transcodes the given string. This is done as follows:</br></br>
+ * 1) The given string is encoded into a binary byte buffer.</br></br>
+ * 2) It's tested whether this binary byte buffer seems to represent a string which is encoded as
+ * either ASCII, Latin-1, or UTF-8. If this is the case, the binary byte buffer is decoded back into
+ * a string and this string is returned. If the test is negative, the given string is returned without
+ * modification because its encoding can't be reliably determined in this case.
+ * The most important use case of this function is to transcode a string which is actually UTF-8 but has
+ * been incorrectly decoded as Latin-1 instead.
+ * @param str The string to transcode.
+ * @return The transcoded string.
+ */
+ public static String transcodeString(String str) {
+ // Try to transcode the string from Latin-1 to UTF-8 (ASCII doesn't need to be explicitly
+ // considered here since Latin-1 is backwards compatible with ASCII). The transcoding will
+ // almost certainly only succeed if the string actually *is* encoded in UTF-8. If the
+ // transcoding fails, the string is simply left unchanged.
+ try {
+ // First, try to encode the string as Latin-1 in order to obtain the binary byte
+ // representation of the string.
+ CharsetEncoder latin1Encoder = Charset.forName("ISO-8859-1").newEncoder(); //$NON-NLS-1$
+ ByteBuffer stringBytes = latin1Encoder.encode(CharBuffer.wrap(str.toCharArray()));
+
+ // Next, try to decode the string as UTF-8. This will almost certainly only succeed
+ // if the string actually *is* encoded in UTF-8. Note that if the decoding fails,
+ // an exception is thrown before the str variable is assigned. The original string
+ // is therefore left unchanged in this case.
+ CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder(); //$NON-NLS-1$
+ str = utf8Decoder.decode(stringBytes).toString();
+ } catch (Exception e) {
+ }
+
+ return str;
+ }
+
+ /**
+ * Escapes any non-printable characters as well as the printable special characters single quotation
+ * mark, double quotation mark, backslash, and literal question mark within the given string. Supports
+ * the entire Unicode code space.
+ * @param str The string which should be escaped.
+ * @return The escaped string.
+ */
+ public static String escapeString(String str) {
+ return escapeString(str, true);
+ }
+
+ /**
+ * Escapes any non-printable characters within the given string. Supports the entire Unicode code space.
+ * @param str The string which should be escaped.
+ * @param escapePrintableSpecialChars Defines whether the printable special characters single
+ * quotation mark, double quotation mark, backslash, and literal question mark should be
+ * escaped as well, or not.
+ * @return The escaped string.
+ */
+ public static String escapeString(String str, boolean escapePrintableSpecialChars) {
+ StringBuilder buffer = new StringBuilder();
+
+ for (int i = 0; i < str.length(); i++) {
+ // Get the current character code point. Note that using the Java "char" data type isn't
+ // sufficient here, as it can't handle all Unicode characters.
+ int codePoint = str.codePointAt(i);
+ if (Character.isSupplementaryCodePoint(codePoint)) {
+ i++;
+ }
+
+ // Check the code point type of the character in order to determine whether it's
+ // printable or not.
+ int codePointType = Character.getType(codePoint);
+ switch (codePointType) {
+ case Character.LINE_SEPARATOR:
+ case Character.PARAGRAPH_SEPARATOR:
+ case Character.CONTROL:
+ case Character.PRIVATE_USE:
+ case Character.SURROGATE:
+ case Character.UNASSIGNED:
+ // Non-printable character.
+ if (isSpecialCodePoint(codePoint)) {
+ // Escape by using the special character escape notation.
+ buffer.append('\\');
+ try {
+ buffer.append(parseSpecialCodePoint(codePoint));
+ } catch (ParseException e) {
+ buffer.appendCodePoint(codePoint);
+ }
+ } else if (codePoint == 0x00) {
+ // Escape the null character separately - don't use leading zeros.
+ buffer.append("\\0"); //$NON-NLS-1$
+ } else if (codePoint <= 0xFF) {
+ // Escape by using the octal escape notation.
+ buffer.append(String.format("\\%03o", codePoint)); //$NON-NLS-1$
+ } else if (codePoint <= 0xFFFF) {
+ // Escape by using the short Unicode escape notation.
+ buffer.append(String.format("\\u%04x", codePoint)); //$NON-NLS-1$
+ } else {
+ // Escape by using the long Unicode escape notation.
+ buffer.append(String.format("\\U%08x", codePoint)); //$NON-NLS-1$
+ }
+ break;
+ default:
+ // Printable character.
+ if (escapePrintableSpecialChars && isSpecialCodePoint(codePoint)) {
+ // Escape by using the special character escape notation.
+ buffer.append('\\');
+ try {
+ buffer.append(parseSpecialCodePoint(codePoint));
+ } catch (ParseException e) {
+ buffer.appendCodePoint(codePoint);
+ }
+ } else {
+ // Don't escape.
+ buffer.appendCodePoint(codePoint);
+ }
+ }
+ }
+
+ return buffer.toString();
+ }
+}

Back to the top