From c61ae8a137725a03e7b8bb3a71f618aa2fa88b58 Mon Sep 17 00:00:00 2001 From: Mathias Kunter Date: Mon, 5 Mar 2012 16:08:53 -0500 Subject: Bug 370462: Improving the debug preferences - add support for different charsets and unify DSF and CDI debug preferences --- .../src/org/eclipse/cdt/core/IAddress.java | 11 +- .../utils/org/eclipse/cdt/utils/Addr32.java | 23 +++- .../utils/org/eclipse/cdt/utils/Addr64.java | 23 +++- .../org/eclipse/cdt/debug/core/CDebugUtils.java | 7 +- .../eclipse/cdt/debug/core/ICDebugConstants.java | 22 ++-- .../core/CDebugCorePreferenceInitializer.java | 11 +- .../debug/internal/core/model/CIndexedValue.java | 9 +- .../cdt/debug/internal/core/model/CValue.java | 117 +++++++++++++++++++-- .../ui/preferences/CDebugPreferencePage.java | 112 +++++++++++++++----- .../ui/preferences/PreferenceMessages.properties | 19 ++-- .../images/view_debug_prefs.png | Bin 22587 -> 39301 bytes .../reference/cdt_u_dbg_pref.htm | 26 ++--- .../cdt/dsf/gdb/launching/FinalLaunchSequence.java | 17 ++- .../cdt/dsf/gdb/service/command/GDBControl.java | 27 ++++- .../dsf/gdb/service/command/GDBControl_7_0.java | 30 +++++- .../cdt/dsf/gdb/service/command/IGDBControl.java | 11 +- .../cdt/dsf/mi/service/command/CommandFactory.java | 26 +++++ .../service/command/commands/MIGDBSetCharset.java | 30 ++++++ .../command/commands/MIGDBSetHostCharset.java | 28 +++++ .../commands/MIGDBSetPrintSevenbitStrings.java | 29 +++++ .../command/commands/MIGDBSetTargetCharset.java | 29 +++++ .../commands/MIGDBSetTargetWideCharset.java | 31 ++++++ .../numberformat/FormattedValueVMUtil.java | 35 +++++- .../cdt/dsf/debug/service/IExpressions.java | 4 +- 24 files changed, 590 insertions(+), 87 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetCharset.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetHostCharset.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintSevenbitStrings.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetCharset.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetWideCharset.java diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IAddress.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IAddress.java index 13e94048c90..200fb426a35 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IAddress.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IAddress.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 Intel Corporation and others. + * Copyright (c) 2004, 2012 Intel 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 @@ -8,6 +8,7 @@ * Contributors: * Intel Corporation - Initial API and implementation * Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format + * Mathias Kunter - Bug 370462: View variables in octal format *******************************************************************************/ package org.eclipse.cdt.core; @@ -103,6 +104,14 @@ public interface IAddress extends Comparable { */ String toHexAddressString(); + /** + * Converts address to the octal representation with '0' prefix and + * with all leading zeros. The length of returned string should be + * the same for all addresses of given class. I.e. 12 for 32-bit + * addresses and 23 for 64-bit addresses + * @since 5.4 + */ + String toOctalAddressString(); /** * Converts address to the binary representation with '0b' prefix and diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java index 08ed4f425de..34291bc8ed5 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 Intel Corporation and others. + * Copyright (c) 2004, 2012 Intel 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 @@ -8,6 +8,7 @@ * Contributors: * Intel Corporation - Initial API and implementation * Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format + * Mathias Kunter - Bug 370462: View variables in octal format *******************************************************************************/ package org.eclipse.cdt.utils; @@ -29,6 +30,8 @@ public class Addr32 implements IAddress, Serializable { private static final int BYTES_NUM = 4; private static final int DIGITS_NUM = BYTES_NUM * 2; private static final int CHARS_NUM = DIGITS_NUM + 2; + private static final int OCTAL_DIGITS_NUM = (BYTES_NUM * 8 + 2) / 3; + private static final int OCTAL_CHARS_NUM = OCTAL_DIGITS_NUM + 1; private static final int BINARY_DIGITS_NUM = BYTES_NUM * 8; private static final int BINARY_CHARS_NUM = BINARY_DIGITS_NUM + 2; @@ -157,7 +160,23 @@ public class Addr32 implements IAddress, Serializable { sb.append(addressString); return sb.toString(); } - + + /** + * @since 5.4 + */ + @Override + public String toOctalAddressString() { + String addressString = Long.toString(address, 8); + StringBuffer sb = new StringBuffer(OCTAL_CHARS_NUM); + int count = OCTAL_DIGITS_NUM - addressString.length(); + sb.append("0"); //$NON-NLS-1$ + for (int i = 0; i < count; ++i) { + sb.append('0'); + } + sb.append(addressString); + return sb.toString(); + } + @Override public String toBinaryAddressString() { String addressString = Long.toString(address, 2); diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java index f7321cc39ff..9babfb41c18 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 Intel Corporation and others. + * Copyright (c) 2004, 2012 Intel 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 @@ -8,6 +8,7 @@ * Contributors: * Intel Corporation - Initial API and implementation * Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format + * Mathias Kunter - Bug 370462: View variables in octal format *******************************************************************************/ package org.eclipse.cdt.utils; @@ -27,6 +28,8 @@ public class Addr64 implements IAddress, Serializable { private static final int BYTES_NUM = 8; private static final int DIGITS_NUM = BYTES_NUM * 2; private static final int CHARS_NUM = DIGITS_NUM + 2; + private static final int OCTAL_DIGITS_NUM = (BYTES_NUM * 8 + 2) / 3; + private static final int OCTAL_CHARS_NUM = OCTAL_DIGITS_NUM + 1; private static final int BINARY_DIGITS_NUM = BYTES_NUM * 8; private static final int BINARY_CHARS_NUM = BINARY_DIGITS_NUM + 2; @@ -161,7 +164,23 @@ public class Addr64 implements IAddress, Serializable { sb.append(addressString); return sb.toString(); } - + + /** + * @since 5.4 + */ + @Override + public String toOctalAddressString() { + String addressString = address.toString(8); + StringBuffer sb = new StringBuffer(OCTAL_CHARS_NUM); + int count = OCTAL_DIGITS_NUM - addressString.length(); + sb.append("0"); //$NON-NLS-1$ + for (int i = 0; i < count; ++i) { + sb.append('0'); + } + sb.append(addressString); + return sb.toString(); + } + @Override public String toBinaryAddressString() { String addressString = address.toString(2); diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java index b5795ec4946..e3894da28da 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 QNX Software Systems and others. + * Copyright (c) 2000, 2012 QNX Software Systems 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 @@ -9,6 +9,7 @@ * QNX Software Systems - Initial API and implementation * Freescale Semiconductor - Address watchpoints, https://bugs.eclipse.org/bugs/show_bug.cgi?id=118299 * Patrick Chuong (Texas Instruments) - Update CDT ToggleBreakpointTargetFactory enablement (340177) + * Mathias Kunter - PREF_CHARSET has been renamed to PREF_WIDE_CHARSET (bug 370462) *******************************************************************************/ package org.eclipse.cdt.debug.core; @@ -502,7 +503,7 @@ public class CDebugUtils { private static CharsetDecoder fDecoder; public static CharsetDecoder getCharsetDecoder() { - String charsetName = CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_CHARSET); + String charsetName = CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_WIDE_CHARSET); if (fDecoder == null || !fDecoder.charset().name().equals(charsetName)) { Charset charset = Charset.forName(charsetName); fDecoder = charset.newDecoder(); @@ -756,4 +757,4 @@ public class CDebugUtils { String customModel = System.getProperty(ICDebugConstants.PREF_TOGGLE_BREAKPOINT_MODEL_IDENTIFIER, null); return customModel != null && Boolean.valueOf(customModel); } -} \ No newline at end of file +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugConstants.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugConstants.java index c56fd788c15..386035ec333 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugConstants.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDebugConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 QNX Software Systems and others. + * Copyright (c) 2000, 2012 QNX Software Systems 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 @@ -9,6 +9,7 @@ * QNX Software Systems - Initial API and implementation * Ken Ryall (Nokia) - 207675 * Patrick Chuong (Texas Instruments) - Update CDT ToggleBreakpointTargetFactory enablement (340177) + * Mathias Kunter - Support for different charsets (bug 370462) *******************************************************************************/ package org.eclipse.cdt.debug.core; @@ -38,10 +39,17 @@ public interface ICDebugConstants { public static final String PREF_DEFAULT_REGISTER_FORMAT = PLUGIN_ID + "cDebug.default_register_format"; //$NON-NLS-1$ /** - * The identifier of the character set to use with unicode types - * view + * The charset to use for decoding char type strings. We however can't use the ID + * "character_set" here because that would break backwards compatibility. + */ + public static final String PREF_CHARSET = PLUGIN_ID + "cDebug.non_wide_character_set"; //$NON-NLS-1$ + + /** + * The charset to use for decoding wchar_t type strings. We have to use the ID + * "character_set" here so that we don't break backwards compatibility. + * @since 7.2 */ - public static final String PREF_CHARSET = PLUGIN_ID + "cDebug.character_set"; //$NON-NLS-1$ + public static final String PREF_WIDE_CHARSET = PLUGIN_ID + "cDebug.character_set"; //$NON-NLS-1$ /** * The identifier of the default expression format to use in the expressions @@ -105,10 +113,12 @@ public interface ICDebugConstants { public static final String PREF_INSTRUCTION_STEP_MODE_ON = PLUGIN_ID + "cDebug.Disassembly.instructionStepOn"; //$NON-NLS-1$ /** - * The default character set to use with unicode strings. + * The default character set to use. + * @deprecated Provided for compatibility reasons only. Use the default value + * from the Preferences object instead. */ public static final String DEF_CHARSET = "UTF-16"; //$NON-NLS-1$ - + /** * Specifies the stepping mode (context/source/instruction) */ diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugCorePreferenceInitializer.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugCorePreferenceInitializer.java index a5d67555f1c..d857953ab98 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugCorePreferenceInitializer.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugCorePreferenceInitializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 QNX Software Systems and others. + * Copyright (c) 2004, 2012 QNX Software Systems 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 @@ -8,9 +8,12 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Ken Ryall (Nokia) - 207675 + * Mathias Kunter - Using adequate default charsets (bug 370462) *******************************************************************************/ package org.eclipse.cdt.debug.internal.core; +import java.nio.charset.Charset; + import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDebugConstants; import org.eclipse.cdt.debug.core.cdi.ICDIFormat; @@ -37,7 +40,11 @@ public class CDebugCorePreferenceInitializer extends AbstractPreferenceInitializ CDebugCorePlugin.getDefault().getPluginPreferences().setDefault( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT, ICDIFormat.NATURAL ); CDebugCorePlugin.getDefault().getPluginPreferences().setDefault( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT, ICDIFormat.NATURAL ); CDebugCorePlugin.getDefault().getPluginPreferences().setDefault( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT, ICDIFormat.NATURAL ); - CDebugCorePlugin.getDefault().getPluginPreferences().setDefault( ICDebugConstants.PREF_CHARSET, ICDebugConstants.DEF_CHARSET ); + CDebugCorePlugin.getDefault().getPluginPreferences().setDefault( ICDebugConstants.PREF_CHARSET, Charset.defaultCharset().name() ); + if (System.getProperty("os.name").toLowerCase().startsWith("windows")) //$NON-NLS-1$ //$NON-NLS-2$ + CDebugCorePlugin.getDefault().getPluginPreferences().setDefault( ICDebugConstants.PREF_WIDE_CHARSET, "UTF-16"); //$NON-NLS-1$ + else + CDebugCorePlugin.getDefault().getPluginPreferences().setDefault( ICDebugConstants.PREF_WIDE_CHARSET, "UTF-32"); //$NON-NLS-1$ CDebugCorePlugin.getDefault().getPluginPreferences().setDefault( ICDebugConstants.PREF_INSTRUCTION_STEP_MODE_ON, false ); } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java index 2c7483df20b..e6ca4898757 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CIndexedValue.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 QNX Software Systems and others. + * Copyright (c) 2004, 2012 QNX Software Systems 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Mathias Kunter - Support for octal number format (bug 370462) *******************************************************************************/ package org.eclipse.cdt.debug.internal.core.model; @@ -162,9 +163,11 @@ public class CIndexedValue extends AbstractCValue implements IIndexedValue { CVariableFormat format = getParentVariable().getFormat(); if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) ) return address.toHexAddressString(); - if ( CVariableFormat.DECIMAL.equals( format ) ) + else if ( CVariableFormat.DECIMAL.equals( format ) ) return address.toString(); - if ( CVariableFormat.BINARY.equals( format ) ) + else if ( CVariableFormat.OCTAL.equals( format ) ) + return address.toOctalAddressString(); + else if ( CVariableFormat.BINARY.equals( format ) ) return address.toBinaryAddressString(); return null; } catch (CDIException e) { diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java index 5614958f953..eca33a16f55 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CValue.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 QNX Software Systems and others. + * Copyright (c) 2000, 2012 QNX Software Systems 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 @@ -10,6 +10,7 @@ * Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format * Warren Paul (Nokia) - 150860, 150864, 150862, 150863, 217493 * Ken Ryall (Nokia) - 207675 + * Mathias Kunter - Support for octal number format (bug 370462) *******************************************************************************/ package org.eclipse.cdt.debug.internal.core.model; @@ -277,6 +278,19 @@ public class CValue extends AbstractCValue { sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : stringValue ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + String stringValue = (isUnsigned()) ? Integer.toOctalString( value.shortValue() ) : Integer.toOctalString( (byte)value.byteValue() ); + stringValue = (stringValue.length() > 3) ? stringValue.substring( stringValue.length() - 3 ) : stringValue; + sb.append( (stringValue.length() == 3 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); + return sb.toString(); + } + else if ( CVariableFormat.BINARY.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ + String stringValue = (isUnsigned()) ? Integer.toBinaryString( value.shortValue() ) : Integer.toBinaryString( (byte)value.byteValue() ); + sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); + return sb.toString(); + } return null; } @@ -313,6 +327,13 @@ public class CValue extends AbstractCValue { sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : stringValue ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + String stringValue = (isUnsigned()) ? Integer.toOctalString( value.shortValue() ) : Integer.toOctalString( (byte)value.byteValue() ); + stringValue = (stringValue.length() > 3) ? stringValue.substring( stringValue.length() - 3 ) : stringValue; + sb.append( (stringValue.length() == 3 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); + return sb.toString(); + } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ String stringValue = (isUnsigned()) ? Integer.toBinaryString( value.shortValue() ) : Integer.toBinaryString( (byte)value.byteValue() ); @@ -338,6 +359,13 @@ public class CValue extends AbstractCValue { sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + String stringValue = Integer.toOctalString( (isUnsigned()) ? value.intValue() : value.shortValue() ); + stringValue = (stringValue.length() > 6) ? stringValue.substring( stringValue.length() - 6 ) : stringValue; + sb.append( (stringValue.length() == 6 && stringValue.charAt( 0 ) >= '2') ? (char)((stringValue.charAt( 0 ) - '0') % 2 + '0') + stringValue.substring( 1 ) : stringValue ); + return sb.toString(); + } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ String stringValue = Integer.toBinaryString( (isUnsigned()) ? value.intValue() : value.shortValue() ); @@ -363,6 +391,13 @@ public class CValue extends AbstractCValue { sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + String stringValue = (isUnsigned()) ? Long.toOctalString( value.longValue() ) : Integer.toOctalString( value.intValue() ); + stringValue = (stringValue.length() > 11) ? stringValue.substring( stringValue.length() - 11 ) : stringValue; + sb.append( (stringValue.length() == 11 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); + return sb.toString(); + } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ String stringValue = (isUnsigned()) ? Long.toBinaryString( value.longValue() ) : Integer.toBinaryString( value.intValue() ); @@ -385,7 +420,7 @@ public class CValue extends AbstractCValue { BigInteger bigValue = new BigInteger( value.getValueString() ); return bigValue.toString(); } - return Long.toString( value.longValue() ); + return Integer.toString( value.intValue() ); } else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { StringBuffer sb = new StringBuffer( "0x" ); //$NON-NLS-1$ @@ -394,7 +429,17 @@ public class CValue extends AbstractCValue { sb.append( bigValue.toString( 16 ) ); } else - sb.append( Long.toHexString( value.longValue() ) ); + sb.append( Integer.toHexString( value.intValue() ) ); + return sb.toString(); + } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + if ( isUnsigned() ) { + BigInteger bigValue = new BigInteger( value.getValueString() ); + sb.append( bigValue.toString( 8 ) ); + } + else + sb.append( Integer.toOctalString( value.intValue() ) ); return sb.toString(); } else if ( CVariableFormat.BINARY.equals( format ) ) { @@ -404,7 +449,7 @@ public class CValue extends AbstractCValue { sb.append( bigValue.toString( 2 ) ); } else - sb.append( Long.toBinaryString( value.longValue() ) ); + sb.append( Integer.toBinaryString( value.intValue() ) ); return sb.toString(); } } @@ -438,6 +483,16 @@ public class CValue extends AbstractCValue { sb.append( Long.toHexString( value.longValue() ) ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + if ( isUnsigned() ) { + BigInteger bigValue = new BigInteger( value.getValueString() ); + sb.append( bigValue.toString( 8 ) ); + } + else + sb.append( Long.toOctalString( value.longValue() ) ); + return sb.toString(); + } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ if ( isUnsigned() ) { @@ -470,6 +525,13 @@ public class CValue extends AbstractCValue { } else sb.append(Long.toHexString(bigValue.longValue())); return sb.toString(); + } else if (CVariableFormat.OCTAL.equals(format)) { + StringBuffer sb = new StringBuffer("0"); //$NON-NLS-1$ + if (isUnsigned()) { + sb.append(bigValue.toString(8)); + } else + sb.append(Long.toOctalString(bigValue.longValue())); + return sb.toString(); } else if (CVariableFormat.BINARY.equals(format)) { StringBuffer sb = new StringBuffer("0b"); //$NON-NLS-1$ if (isUnsigned()) { @@ -504,6 +566,13 @@ public class CValue extends AbstractCValue { sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + String stringValue = Long.toOctalString( Float.floatToIntBits(floatValue) ); + stringValue = (stringValue.length() > 11) ? stringValue.substring( stringValue.length() - 11 ) : stringValue; + sb.append( (stringValue.length() == 11 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); + return sb.toString(); + } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ String stringValue = Long.toBinaryString( Float.floatToIntBits(floatValue) ); @@ -533,6 +602,13 @@ public class CValue extends AbstractCValue { sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + String stringValue = Long.toOctalString( Double.doubleToLongBits(doubleValue) ); + stringValue = (stringValue.length() > 22) ? stringValue.substring( stringValue.length() - 22 ) : stringValue; + sb.append( (stringValue.length() == 22 && stringValue.charAt( 0 ) >= '2') ? (char)((stringValue.charAt( 0 ) - '0') % 2 + '0') + stringValue.substring( 1 ) : stringValue ); + return sb.toString(); + } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ String stringValue = Long.toBinaryString( Double.doubleToLongBits(doubleValue) ); @@ -554,9 +630,11 @@ public class CValue extends AbstractCValue { CVariableFormat format = getParentVariable().getFormat(); if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.HEXADECIMAL.equals( format ) ) return address.toHexAddressString(); - if ( CVariableFormat.DECIMAL.equals( format ) ) + else if ( CVariableFormat.DECIMAL.equals( format ) ) return address.toString(); - if ( CVariableFormat.BINARY.equals( format ) ) + else if ( CVariableFormat.OCTAL.equals( format ) ) + return address.toOctalAddressString(); + else if ( CVariableFormat.BINARY.equals( format ) ) return address.toBinaryAddressString(); return null; } @@ -590,6 +668,13 @@ public class CValue extends AbstractCValue { sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + String stringValue = Integer.toOctalString( (isUnsigned()) ? value.intValue() : value.shortValue() ); + stringValue = (stringValue.length() > 6) ? stringValue.substring( stringValue.length() - 6 ) : stringValue; + sb.append( (stringValue.length() == 6 && stringValue.charAt( 0 ) >= '2') ? (char)((stringValue.charAt( 0 ) - '0') % 2 + '0') + stringValue.substring( 1 ) : stringValue ); + return sb.toString(); + } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ String stringValue = Integer.toBinaryString( (isUnsigned()) ? value.intValue() : value.shortValue() ); @@ -623,9 +708,16 @@ public class CValue extends AbstractCValue { sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); return sb.toString(); } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer( "0" ); //$NON-NLS-1$ + String stringValue = (isUnsigned()) ? Long.toOctalString( value.longValue() ) : Integer.toOctalString( value.intValue() ); + stringValue = (stringValue.length() > 11) ? stringValue.substring( stringValue.length() - 11 ) : stringValue; + sb.append( (stringValue.length() == 11 && stringValue.charAt( 0 ) >= '4') ? (char)(stringValue.charAt( 0 ) - 4) + stringValue.substring( 1 ) : stringValue ); + return sb.toString(); + } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$ - String stringValue = (isUnsigned()) ? Long.toBinaryString( value.longValue() ) : Integer.toHexString( value.intValue() ); + String stringValue = (isUnsigned()) ? Long.toBinaryString( value.longValue() ) : Integer.toBinaryString( value.intValue() ); sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue ); return sb.toString(); } @@ -648,14 +740,17 @@ public class CValue extends AbstractCValue { } else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) { StringBuffer sb = new StringBuffer("0x"); //$NON-NLS-1$ - BigInteger bigValue = value.bigIntegerValue(); - sb.append(bigValue.toString(16)); + sb.append(value.bigIntegerValue().toString(16)); + return sb.toString(); + } + else if ( CVariableFormat.OCTAL.equals( format ) ) { + StringBuffer sb = new StringBuffer("0"); //$NON-NLS-1$ + sb.append(value.bigIntegerValue().toString(8)); return sb.toString(); } else if ( CVariableFormat.BINARY.equals( format ) ) { StringBuffer sb = new StringBuffer("0b"); //$NON-NLS-1$ - BigInteger bigValue = value.bigIntegerValue(); - sb.append(bigValue.toString(2)); + sb.append(value.bigIntegerValue().toString(2)); return sb.toString(); } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/CDebugPreferencePage.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/CDebugPreferencePage.java index 8e0da95abd1..1960ddd60a5 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/CDebugPreferencePage.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/CDebugPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 QNX Software Systems and others. + * Copyright (c) 2004, 2012 QNX Software Systems 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 @@ -8,14 +8,10 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Ken Ryall (Nokia) - 207675 + * Mathias Kunter - Support for different charsets (bug 370462) *******************************************************************************/ package org.eclipse.cdt.debug.internal.ui.preferences; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.SortedMap; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePreferenceConstants; import org.eclipse.cdt.debug.core.CDebugCorePlugin; @@ -26,8 +22,10 @@ import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.preference.PreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.StructuredViewer; @@ -46,6 +44,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.ide.dialogs.EncodingFieldEditor; /** * Preference page for debug preferences that apply specifically to C/C++ Debugging. @@ -57,15 +56,29 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr private Combo fVariableFormatCombo; private Combo fExpressionFormatCombo; - + private Combo fRegisterFormatCombo; - private Combo fCharsetCombo; + private EncodingFieldEditor fCharsetEditor; + + private EncodingFieldEditor fWideCharsetEditor; // Format constants - private static int[] fFormatIds = new int[]{ ICDIFormat.NATURAL, ICDIFormat.HEXADECIMAL, ICDIFormat.DECIMAL, ICDIFormat.BINARY }; - - private static String[] fFormatLabels = new String[]{ PreferenceMessages.getString( "CDebugPreferencePage.0" ), PreferenceMessages.getString( "CDebugPreferencePage.1" ), PreferenceMessages.getString( "CDebugPreferencePage.2" ), PreferenceMessages.getString( "CDebugPreferencePage.14" ) }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + private static int[] fFormatIds = new int[] { + ICDIFormat.NATURAL, + ICDIFormat.HEXADECIMAL, + ICDIFormat.DECIMAL, + ICDIFormat.OCTAL, + ICDIFormat.BINARY + }; + + private static String[] fFormatLabels = new String[] { + PreferenceMessages.getString( "CDebugPreferencePage.0" ), //$NON-NLS-1$ + PreferenceMessages.getString( "CDebugPreferencePage.1" ), //$NON-NLS-1$ + PreferenceMessages.getString( "CDebugPreferencePage.2" ), //$NON-NLS-1$ + PreferenceMessages.getString( "CDebugPreferencePage.17" ), //$NON-NLS-1$ + PreferenceMessages.getString( "CDebugPreferencePage.14" ) //$NON-NLS-1$ + }; private PropertyChangeListener fPropertyChangeListener; @@ -79,10 +92,21 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr public void propertyChange( PropertyChangeEvent event ) { if ( event.getProperty().equals( ICDebugPreferenceConstants.PREF_SHOW_HEX_VALUES ) ) { fHasStateChanged = true; - } - else if ( event.getProperty().equals( ICDebugPreferenceConstants.PREF_SHOW_CHAR_VALUES ) ) { + } else if ( event.getProperty().equals( ICDebugPreferenceConstants.PREF_SHOW_CHAR_VALUES ) ) { fHasStateChanged = true; + } else if (event.getProperty().equals(FieldEditor.VALUE)) { + fHasStateChanged = true; + } else if (event.getProperty().equals(FieldEditor.IS_VALID)) { + setValid(fCharsetEditor.isValid() && fWideCharsetEditor.isValid()); + if (!fCharsetEditor.isValid()) { + setErrorMessage(PreferenceMessages.getString("CDebugPreferencePage.19")); //$NON-NLS-1$ + } else if (!fWideCharsetEditor.isValid()) { + setErrorMessage(PreferenceMessages.getString("CDebugPreferencePage.20")); //$NON-NLS-1$ + } else { + setErrorMessage(null); + } } + } protected boolean hasStateChanged() { @@ -122,6 +146,8 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr createSpacer( composite, 1 ); createViewSettingPreferences( composite ); createSpacer( composite, 1 ); + createCharsetSettingPreferences( composite ); + createSpacer( composite, 1 ); createBinarySettings( composite ); setValues(); return composite; @@ -146,10 +172,29 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr * Set the values of the component widgets based on the values in the preference store */ private void setValues() { + // Number format combos fVariableFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT ) ) ); fExpressionFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) ); fRegisterFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) ); - fCharsetCombo.setText( CDebugCorePlugin.getDefault().getPluginPreferences().getString( ICDebugConstants.PREF_CHARSET ) ); + + // Charset editors + PreferenceStore ps = new PreferenceStore(); + + ps.setDefault(ICDebugConstants.PREF_CHARSET, CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultString(ICDebugConstants.PREF_CHARSET)); + ps.setValue(ICDebugConstants.PREF_CHARSET, CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_CHARSET)); + fCharsetEditor.setPreferenceStore(ps); + fCharsetEditor.load(); + if (CDebugCorePlugin.getDefault().getPluginPreferences().isDefault(ICDebugConstants.PREF_CHARSET)) + fCharsetEditor.loadDefault(); + + ps.setDefault(ICDebugConstants.PREF_WIDE_CHARSET, CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultString(ICDebugConstants.PREF_WIDE_CHARSET)); + ps.setValue(ICDebugConstants.PREF_WIDE_CHARSET, CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_WIDE_CHARSET)); + fWideCharsetEditor.setPreferenceStore(ps); + fWideCharsetEditor.load(); + if (CDebugCorePlugin.getDefault().getPluginPreferences().isDefault(ICDebugConstants.PREF_WIDE_CHARSET)) + fWideCharsetEditor.loadDefault(); + + // Others fShowBinarySourceFilesButton.setSelection( CCorePlugin.getDefault().getPluginPreferences().getBoolean( CCorePreferenceConstants.SHOW_SOURCE_FILES_IN_BINARIES ) ); } @@ -196,21 +241,25 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr fVariableFormatCombo = createComboBox( formatComposite, PreferenceMessages.getString( "CDebugPreferencePage.8" ), fFormatLabels, fFormatLabels[0] ); //$NON-NLS-1$ fExpressionFormatCombo = createComboBox( formatComposite, PreferenceMessages.getString( "CDebugPreferencePage.9" ), fFormatLabels, fFormatLabels[0] ); //$NON-NLS-1$ fRegisterFormatCombo = createComboBox( formatComposite, PreferenceMessages.getString( "CDebugPreferencePage.10" ), fFormatLabels, fFormatLabels[0] ); //$NON-NLS-1$ - String[] charsetNames = getCharsetNames(); - fCharsetCombo = createComboBox( formatComposite, PreferenceMessages.getString( "CDebugPreferencePage.16" ), charsetNames, charsetNames[0] ); //$NON-NLS-1$ } - - private String[] getCharsetNames() { - ArrayList names = new ArrayList(); - SortedMap setmap = Charset.availableCharsets(); + + private void createCharsetSettingPreferences( Composite parent ) { + // Create containing composite + Composite formatComposite = ControlFactory.createComposite( parent, 2); + ((GridLayout)formatComposite.getLayout()).marginWidth = 0; + ((GridLayout)formatComposite.getLayout()).marginHeight = 0; - for (Iterator iterator = setmap.keySet().iterator(); iterator.hasNext();) { - String entry = (String) iterator.next(); - names.add(entry); - } - return (String[]) names.toArray(new String[names.size()]); + // Create charset editor + Composite charsetComposite = ControlFactory.createComposite(formatComposite, 1); + fCharsetEditor = new EncodingFieldEditor(ICDebugConstants.PREF_CHARSET, "", PreferenceMessages.getString( "CDebugPreferencePage.18" ), charsetComposite); //$NON-NLS-1$ //$NON-NLS-2$ + fCharsetEditor.setPropertyChangeListener(getPropertyChangeListener()); + + // Create wide charset editor + Composite wideCharsetComposite = ControlFactory.createComposite(formatComposite, 1); + fWideCharsetEditor = new EncodingFieldEditor(ICDebugConstants.PREF_WIDE_CHARSET, "", PreferenceMessages.getString( "CDebugPreferencePage.16" ), wideCharsetComposite); //$NON-NLS-1$ //$NON-NLS-2$ + fWideCharsetEditor.setPropertyChangeListener(getPropertyChangeListener()); } - + private void createBinarySettings( Composite parent ) { fShowBinarySourceFilesButton = createCheckButton( parent, PreferenceMessages.getString("CDebugPreferencePage.15") ); //$NON-NLS-1$ } @@ -304,7 +353,13 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT, getFormatId( fVariableFormatCombo.getSelectionIndex() ) ); CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT, getFormatId( fExpressionFormatCombo.getSelectionIndex() ) ); CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT, getFormatId( fRegisterFormatCombo.getSelectionIndex() ) ); - CDebugCorePlugin.getDefault().getPluginPreferences().setValue( ICDebugConstants.PREF_CHARSET, fCharsetCombo.getItem( fCharsetCombo.getSelectionIndex()) ); + + fCharsetEditor.store(); + CDebugCorePlugin.getDefault().getPluginPreferences().setValue(ICDebugConstants.PREF_CHARSET, fCharsetEditor.getPreferenceStore().getString(ICDebugConstants.PREF_CHARSET)); + + fWideCharsetEditor.store(); + CDebugCorePlugin.getDefault().getPluginPreferences().setValue(ICDebugConstants.PREF_WIDE_CHARSET, fWideCharsetEditor.getPreferenceStore().getString(ICDebugConstants.PREF_WIDE_CHARSET)); + CCorePlugin.getDefault().getPluginPreferences().setValue( CCorePreferenceConstants.SHOW_SOURCE_FILES_IN_BINARIES, fShowBinarySourceFilesButton.getSelection() ); } @@ -323,7 +378,8 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr fVariableFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT ) ) ); fExpressionFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ) ) ); fRegisterFormatCombo.select( getFormatIndex( CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ) ) ); - fCharsetCombo.setText( CDebugCorePlugin.getDefault().getPluginPreferences().getDefaultString( ICDebugConstants.PREF_CHARSET ) ); + fCharsetEditor.loadDefault(); + fWideCharsetEditor.loadDefault(); } private static int getFormatId( int index ) { diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/PreferenceMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/PreferenceMessages.properties index f3fe088b32c..7723772da27 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/PreferenceMessages.properties +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/preferences/PreferenceMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2010 QNX Software Systems and others. +# Copyright (c) 2003, 2012 QNX Software Systems 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 @@ -8,23 +8,28 @@ # Contributors: # QNX Software Systems - initial API and implementation # IBM Corporation +# Mathias Kunter - Support for different charsets (bug 370462) ############################################################################### CDebugPreferencePage.Color_of_disassembly_source_lines_1=Color of source lines: -CDebugPreferencePage.0=Natural +CDebugPreferencePage.0=Default CDebugPreferencePage.1=Hexadecimal CDebugPreferencePage.2=Decimal CDebugPreferencePage.3=General settings for C/C++ Debugging. -CDebugPreferencePage.4=Opened view default settings -CDebugPreferencePage.8=Default variable format: -CDebugPreferencePage.9=Default expression format: -CDebugPreferencePage.10=Default register format: +CDebugPreferencePage.4=Default number format +CDebugPreferencePage.8=Variables: +CDebugPreferencePage.9=Expressions: +CDebugPreferencePage.10=Registers: CDebugPreferencePage.11=Disassembly options CDebugPreferencePage.12=Maximum number of displayed instructions: CDebugPreferencePage.13=Value must be an integer between {0} and {1}. CDebugPreferencePage.14=Binary CDebugPreferencePage.15=Show source files in binaries -CDebugPreferencePage.16=Character encoding: +CDebugPreferencePage.16=Wide character encoding +CDebugPreferencePage.17=Octal +CDebugPreferencePage.18=Character encoding +CDebugPreferencePage.19=The selected character encoding is not supported. +CDebugPreferencePage.20=The selected wide character encoding is not supported. SourcePreferencePage.0=Default S&ource Lookup Path: DebuggerTypesPage.0=Select All DebuggerTypesPage.1=Deselect All diff --git a/doc/org.eclipse.cdt.doc.user/images/view_debug_prefs.png b/doc/org.eclipse.cdt.doc.user/images/view_debug_prefs.png index df849f3de2a..1e23bdc7c9e 100644 Binary files a/doc/org.eclipse.cdt.doc.user/images/view_debug_prefs.png and b/doc/org.eclipse.cdt.doc.user/images/view_debug_prefs.png differ diff --git a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_dbg_pref.htm b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_dbg_pref.htm index c95ca9ac8ab..de013804f14 100644 --- a/doc/org.eclipse.cdt.doc.user/reference/cdt_u_dbg_pref.htm +++ b/doc/org.eclipse.cdt.doc.user/reference/cdt_u_dbg_pref.htm @@ -24,30 +24,26 @@ Option Description - - Show full paths - Displays the full path of resources. - Default variable format - Specifies the number system in which to display variables (Natural, Hexadecimal, Decimal, or Binary). + Select the default variable format from either Default, Hexadecimal, Decimal, Octal or Binary. Default expression format - Specifies the number system in which to display expressions (Natural, Hexadecimal, Decimal, or Binary). + Select the default expression format from either Default, Hexadecimal, Decimal, Octal or Binary. Default register format - Specifies the number system in which to display registers (Natural, Hexadecimal, Decimal, or Binary). - - - Maximum number of displayed instructions - The maximum number of assembler instructions displayed in the Disassembly view. - - - Color of source lines - The color of source lines in the Disassembly view if mixed source/disassembly code is shown. + Select the default register format from either Default, Hexadecimal, Decimal, Octal or Binary. + + Character encoding + Select the character encoding of the debugged program. This applies to char type strings. Note that this requires GDB version 7.0 or later. + + + Wide character encoding + Select the wide character encoding of the debugged program. This applies to wchar_t type strings. Note that this requires GDB version 7.0 or later. + Show source files in binaries Show source files associated with project binaries. diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java index 92ee9fb219d..9f5b09f9034 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/FinalLaunchSequence.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Ericsson and others. + * Copyright (c) 2008, 2012 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 @@ -12,14 +12,17 @@ * Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) * Sergey Prigogin (Google) * Marc Khouzam (Ericsson) - No longer call method to check non-stop for GDB < 7.0 (Bug 365471) + * Mathias Kunter - Support for different charsets (bug 370462) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.launching; import java.util.List; import java.util.Map; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.core.ICDebugConstants; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor; @@ -79,6 +82,7 @@ public class FinalLaunchSequence extends ReflectionSequence { "stepSetEnvironmentDirectory", //$NON-NLS-1$ "stepSetBreakpointPending", //$NON-NLS-1$ "stepEnablePrettyPrinting", //$NON-NLS-1$ + "stepSetCharset", //$NON-NLS-1$ "stepSourceGDBInitFile", //$NON-NLS-1$ "stepSetAutoLoadSharedLibrarySymbols", //$NON-NLS-1$ "stepSetSharedLibraryPaths", //$NON-NLS-1$ @@ -212,6 +216,17 @@ public class FinalLaunchSequence extends ReflectionSequence { fCommandControl.setPrintPythonErrors(false, requestMonitor); } } + + /** + * Set the charsets. + * @since 4.0 + */ + @Execute + public void stepSetCharset(final RequestMonitor requestMonitor) { + String charset = CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_CHARSET); + String wideCharset = CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_WIDE_CHARSET); + fCommandControl.setCharsets(charset, wideCharset, requestMonitor); + } /** * Source the gdbinit file specified in the launch. diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java index 79b6a05d9be..f5901aed60c 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl.java @@ -9,10 +9,11 @@ * Wind River Systems - initial API and implementation * Ericsson - Modified for additional features in DSF Reference implementation * Nokia - create and use backend service. - * Vladimir Prus (CodeSourcery) - Support for -data-read-memory-bytes (bug 322658) + * Vladimir Prus (CodeSourcery) - Support for -data-read-memory-bytes (bug 322658) * Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) * Mikhail Khodjaiants (Mentor Graphics) - Refactor common code in GDBControl* classes (bug 372795) * Marc Khouzam (Ericsson) - Pass errorStream to startCommandProcessing() (Bug 350837) + * Mathias Kunter - Support for different charsets (bug 370462) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service.command; @@ -461,6 +462,30 @@ public class GDBControl extends AbstractMIControl implements IGDBControl { public void enablePrettyPrintingForMIVariableObjects(RequestMonitor rm) { rm.done(); } + + /** + * Sets the charsets. + * @param charset This parameter is ignored. GDB 7.0 or later required. + * @param wideCharset This parameter is ignored. GDB 7.0 or later required. + * @param rm + */ + @Override + public void setCharsets(String charset, String wideCharset, RequestMonitor rm) { + // Enable printing of sevenbit-strings. This is required to avoid charset issues. + // See bug 307311 for details. + queueCommand( + getCommandFactory().createMIGDBSetPrintSevenbitStrings(fControlDmc, true), + new DataRequestMonitor(getExecutor(), rm)); + + // Set the charset to ISO-8859-1. We have to do this here because GDB earlier than + // 7.0 has no proper Unicode support. Note that we can still handle UTF-8 though, as + // we can determine and decode UTF-8 encoded strings on our own. This makes ISO-8859-1 + // the most suitable option here. See the MIStringHandler class and bug 307311 for + // details. + queueCommand( + getCommandFactory().createMIGDBSetCharset(fControlDmc, "ISO-8859-1"), //$NON-NLS-1$ + new DataRequestMonitor(getExecutor(), rm)); + } /** * @since 4.0 diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java index 717de153560..ca74cd3c3d5 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/GDBControl_7_0.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Wind River Systems and others. + * Copyright (c) 2006, 2012 Wind River Systems 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 @@ -13,6 +13,7 @@ * Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) * Marc Khouzam (Ericsson) - Call new FinalLaunchSequence_7_0 (Bug 365471) * Mikhail Khodjaiants (Mentor Graphics) - Refactor common code in GDBControl* classes (bug 372795) + * Mathias Kunter - Support for different charsets (bug 370462) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service.command; @@ -236,6 +237,33 @@ public class GDBControl_7_0 extends GDBControl { getCommandFactory().createMIEnablePrettyPrinting(getControlDMContext()), new DataRequestMonitor(getExecutor(), rm)); } + + @Override + public void setCharsets(String charset, String wideCharset, RequestMonitor rm) { + // Enable printing of sevenbit-strings. This is required to avoid charset issues. + // See bug 307311 for details. + queueCommand( + getCommandFactory().createMIGDBSetPrintSevenbitStrings(getControlDMContext(), true), + new DataRequestMonitor(getExecutor(), rm)); + + // Set the host charset to UTF-8. This ensures that we can correctly handle different + // charsets used by the inferior program. + queueCommand( + getCommandFactory().createMIGDBSetHostCharset(getControlDMContext(), "UTF-8"), //$NON-NLS-1$ + new DataRequestMonitor(getExecutor(), rm)); + + // Set the target charset. The target charset is the charset used by the char type of + // the inferior program. Note that GDB only accepts upper case charset names. + queueCommand( + getCommandFactory().createMIGDBSetTargetCharset(getControlDMContext(), charset.toUpperCase()), + new DataRequestMonitor(getExecutor(), rm)); + + // Set the target wide charset. The target wide charset is the charset used by the wchar_t + // type of the inferior program. Note that GDB only accepts upper case charset names. + queueCommand( + getCommandFactory().createMIGDBSetTargetWideCharset(getControlDMContext(), wideCharset.toUpperCase()), + new DataRequestMonitor(getExecutor(), rm)); + } /** * @since 4.0 diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/IGDBControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/IGDBControl.java index fb7ef002ba5..a40f7c61eba 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/IGDBControl.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/command/IGDBControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Ericsson and others. + * Copyright (c) 2008, 2012 Ericsson and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * Ericsson - initial API and implementation * Vladimir Prus (CodeSourcery) - Support for -data-read-memory-bytes (bug 322658) * Jens Elmenthaler (Verigy) - Added Full GDB pretty-printing support (bug 302121) + * Mathias Kunter - Support for different charsets (bug 370462) *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.service.command; @@ -92,4 +93,12 @@ public interface IGDBControl extends IMICommandControl { * @since 4.0 */ void setPrintPythonErrors(boolean enabled, RequestMonitor rm); + + /** + * Sets the charsets. + * @param charset The charset used by the char type of the inferior program. + * @param wideCharset The charset used by the wchar_t type of the inferior program. + * @param rm + */ + void setCharsets(String charset, String wideCharset, RequestMonitor rm); } \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java index 3f15f8eee18..2a53698b8c2 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/CommandFactory.java @@ -16,6 +16,7 @@ * Abeer Bagul - Support for -exec-arguments (bug 337687) * Marc Khouzam (Ericsson) - New methods for new MIDataDisassemble (Bug 357073) * Marc Khouzam (Ericsson) - New method for new MIGDBSetPythonPrintStack (Bug 367788) + * Mathias Kunter - New methods for handling different charsets (Bug 370462) *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command; @@ -98,15 +99,20 @@ import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSet; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetArgs; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetAutoSolib; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetBreakpointPending; +import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetCharset; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetDetachOnFork; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetEnv; +import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetHostCharset; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetNonStop; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetPagination; +import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetPrintSevenbitStrings; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetPythonPrintStack; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetSchedulerLocking; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetSolibAbsolutePrefix; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetSolibSearchPath; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTargetAsync; +import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTargetCharset; +import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBSetTargetWideCharset; import org.eclipse.cdt.dsf.mi.service.command.commands.MIGDBShowExitCode; import org.eclipse.cdt.dsf.mi.service.command.commands.MIInferiorTTYSet; import org.eclipse.cdt.dsf.mi.service.command.commands.MIInterpreterExec; @@ -644,6 +650,26 @@ public class CommandFactory { } /** @since 4.0 */ + public ICommand createMIGDBSetPrintSevenbitStrings(ICommandControlDMContext ctx, boolean enable) { + return new MIGDBSetPrintSevenbitStrings(ctx, enable); + } + + public ICommand createMIGDBSetCharset(ICommandControlDMContext ctx, String charset) { + return new MIGDBSetCharset(ctx, charset); + } + + public ICommand createMIGDBSetHostCharset(ICommandControlDMContext ctx, String hostCharset) { + return new MIGDBSetHostCharset(ctx, hostCharset); + } + + public ICommand createMIGDBSetTargetCharset(ICommandControlDMContext ctx, String targetCharset) { + return new MIGDBSetTargetCharset(ctx, targetCharset); + } + + public ICommand createMIGDBSetTargetWideCharset(ICommandControlDMContext ctx, String targetWideCharset) { + return new MIGDBSetTargetWideCharset(ctx, targetWideCharset); + } + public ICommand createMIGDBSetSolibAbsolutePrefix(ICommandControlDMContext ctx, String prefix) { return new MIGDBSetSolibAbsolutePrefix(ctx, prefix); } 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 new file mode 100644 index 00000000000..1bc7701547d --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetCharset.java @@ -0,0 +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.0 + */ +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 new file mode 100644 index 00000000000..7bc2535cb57 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetHostCharset.java @@ -0,0 +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.0 + */ +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/MIGDBSetPrintSevenbitStrings.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintSevenbitStrings.java new file mode 100644 index 00000000000..68769e77266 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetPrintSevenbitStrings.java @@ -0,0 +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.0 + */ +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 new file mode 100644 index 00000000000..aabae61b922 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetCharset.java @@ -0,0 +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.0 + */ +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 new file mode 100644 index 00000000000..264c8e5e0f7 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MIGDBSetTargetWideCharset.java @@ -0,0 +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.0 + */ +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/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/FormattedValueVMUtil.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/FormattedValueVMUtil.java index 18f79bd6881..3b4e57dffab 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/FormattedValueVMUtil.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/FormattedValueVMUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems and others. + * Copyright (c) 2009, 2012 Wind River Systems 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 @@ -7,6 +7,7 @@ * * Contributors: * Wind River Systems - initial API and implementation + * Mathias Kunter - Use CDI number format defaults (bug 370462) *******************************************************************************/ package org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat; @@ -16,6 +17,9 @@ import java.util.Iterator; import java.util.Map; import java.util.TreeMap; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICDebugConstants; +import org.eclipse.cdt.debug.core.cdi.ICDIFormat; import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor; import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor; import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; @@ -32,6 +36,7 @@ import org.eclipse.cdt.dsf.ui.concurrent.ViewerDataRequestMonitor; import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.ui.IDebugUIConstants; import com.ibm.icu.text.MessageFormat; @@ -204,7 +209,33 @@ public class FormattedValueVMUtil { if ( prop != null ) { return (String) prop; } - return IFormattedValues.NATURAL_FORMAT; + + // Get the CDI number format from the preferences. + int formatID; + if (context.getId() == IDebugUIConstants.ID_VARIABLE_VIEW) { + formatID = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_VARIABLE_FORMAT ); + } else if (context.getId() == IDebugUIConstants.ID_EXPRESSION_VIEW) { + formatID = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_EXPRESSION_FORMAT ); + } else if (context.getId() == IDebugUIConstants.ID_REGISTER_VIEW) { + formatID = CDebugCorePlugin.getDefault().getPluginPreferences().getInt( ICDebugConstants.PREF_DEFAULT_REGISTER_FORMAT ); + } else { + // Use the default natural format. + formatID = ICDIFormat.NATURAL; + } + + // Map the CDI number format to the DSF number format. + if (formatID == ICDIFormat.HEXADECIMAL) { + return IFormattedValues.HEX_FORMAT; + } else if (formatID == ICDIFormat.DECIMAL) { + return IFormattedValues.DECIMAL_FORMAT; + } else if (formatID == ICDIFormat.OCTAL) { + return IFormattedValues.OCTAL_FORMAT; + } else if (formatID == ICDIFormat.BINARY) { + return IFormattedValues.BINARY_FORMAT; + } else { + // Everything else is mapped to the default natural format. + return IFormattedValues.NATURAL_FORMAT; + } } diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/IExpressions.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/IExpressions.java index fac33c4a85c..0c9b1c446fe 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/IExpressions.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/service/IExpressions.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 Wind River Systems and others. + * Copyright (c) 2006, 2012 Wind River Systems 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 @@ -8,6 +8,7 @@ * Contributors: * Wind River Systems - initial API and implementation * Ericsson - Update for GDB/MI + * Mathias Kunter - Support for octal number format (bug 370462) *******************************************************************************/ package org.eclipse.cdt.dsf.debug.service; @@ -107,6 +108,7 @@ public interface IExpressions extends IFormattedValues { @Override public boolean isMax() { return false; } @Override public String toString(int radix) { return "INVALID"; } @Override public String toHexAddressString() { return toString(); } + @Override public String toOctalAddressString() { return toString(); } @Override public String toBinaryAddressString() { return toString(); } @Override public int getCharsNum() { return 0; } @Override public int getSize() { return 0; } -- cgit v1.2.3