mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Bug 207675, display wchar_t as unicode chars.
This commit is contained in:
parent
3d87af69f1
commit
1a138c44af
6 changed files with 94 additions and 6 deletions
|
@ -12,6 +12,8 @@ package org.eclipse.cdt.debug.core;
|
|||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -415,4 +417,17 @@ public class CDebugUtils {
|
|||
private static boolean isEmpty( String string ) {
|
||||
return ( string == null || string.trim().length() == 0 );
|
||||
}
|
||||
|
||||
private static CharsetDecoder fDecoder;
|
||||
|
||||
public static CharsetDecoder getCharsetDecoder() {
|
||||
String charsetName = CDebugCorePlugin.getDefault().getPluginPreferences().getString( ICDebugConstants.PREF_CHARSET );
|
||||
if (fDecoder == null || !fDecoder.charset().name().equals(charsetName))
|
||||
{
|
||||
Charset charset = Charset.forName(charsetName);
|
||||
fDecoder = charset.newDecoder();
|
||||
}
|
||||
return fDecoder;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Ken Ryall (Nokia) - 207675
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.core;
|
||||
|
||||
|
@ -33,6 +34,12 @@ public interface ICDebugConstants {
|
|||
* view
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public static final String PREF_CHARSET = PLUGIN_ID + "cDebug.character_set"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The identifier of the default expression format to use in the expressions
|
||||
|
@ -90,4 +97,9 @@ public interface ICDebugConstants {
|
|||
* Temporary. See bugs 79872 and 80323.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public static final String DEF_CHARSET = "UTF-16";
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2005 QNX Software Systems and others.
|
||||
* Copyright (c) 2004, 2007 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,7 +7,8 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
* Ken Ryall (Nokia) - 207675
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.core;
|
||||
|
||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||
|
@ -35,6 +36,7 @@ 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_INSTRUCTION_STEP_MODE_ON, false );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,17 +9,22 @@
|
|||
* QNX Software Systems - Initial API and implementation
|
||||
* Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
|
||||
* Warren Paul (Nokia) - 150860, 150864, 150862, 150863
|
||||
*******************************************************************************/
|
||||
* Ken Ryall (Nokia) - 207675
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.core.model;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.IAddress;
|
||||
import org.eclipse.cdt.core.IAddressFactory;
|
||||
import org.eclipse.cdt.debug.core.CDebugUtils;
|
||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIFormat;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDIFormattable;
|
||||
|
@ -500,7 +505,22 @@ public class CValue extends AbstractCValue {
|
|||
int size = ((CVariable)getParentVariable()).sizeof();
|
||||
if ( size == 2 ) {
|
||||
CVariableFormat format = getParentVariable().getFormat();
|
||||
if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
|
||||
if ( CVariableFormat.NATURAL.equals( format ) ) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.putInt(value.intValue());
|
||||
buffer.position(2);
|
||||
String stringValue;
|
||||
try {
|
||||
stringValue = new String(CDebugUtils.getCharsetDecoder().decode(buffer).array());
|
||||
} catch (CharacterCodingException e) {
|
||||
stringValue = e.toString();
|
||||
}
|
||||
StringBuffer sb = new StringBuffer("'");
|
||||
sb.append(stringValue);
|
||||
sb.append('\'');
|
||||
return sb.toString();
|
||||
}
|
||||
else if ( CVariableFormat.DECIMAL.equals( format ) ) {
|
||||
return (isUnsigned()) ? Integer.toString( value.intValue() ) : Short.toString( value.shortValue() );
|
||||
}
|
||||
else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
|
||||
|
@ -518,7 +538,22 @@ public class CValue extends AbstractCValue {
|
|||
}
|
||||
if ( size == 4 ) {
|
||||
CVariableFormat format = getParentVariable().getFormat();
|
||||
if ( CVariableFormat.NATURAL.equals( format ) || CVariableFormat.DECIMAL.equals( format ) ) {
|
||||
if ( CVariableFormat.NATURAL.equals( format ) ) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
buffer.putLong(value.longValue());
|
||||
buffer.position(4);
|
||||
String stringValue;
|
||||
try {
|
||||
stringValue = new String(CDebugUtils.getCharsetDecoder().decode(buffer).array());
|
||||
} catch (CharacterCodingException e) {
|
||||
stringValue = e.toString();
|
||||
}
|
||||
StringBuffer sb = new StringBuffer("'");
|
||||
sb.append(stringValue);
|
||||
sb.append('\'');
|
||||
return sb.toString();
|
||||
}
|
||||
else if ( CVariableFormat.DECIMAL.equals( format ) ) {
|
||||
return (isUnsigned()) ? Long.toString( value.longValue() ) : Integer.toString( value.intValue() );
|
||||
}
|
||||
else if ( CVariableFormat.HEXADECIMAL.equals( format ) ) {
|
||||
|
|
|
@ -7,10 +7,15 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
* Ken Ryall (Nokia) - 207675
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.ui.preferences;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CCorePreferenceConstants;
|
||||
|
@ -65,6 +70,8 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
|
|||
|
||||
private Combo fRegisterFormatCombo;
|
||||
|
||||
private Combo fCharsetCombo;
|
||||
|
||||
// Maximum number of disassembly instructions to display
|
||||
private IntegerFieldEditor fMaxNumberOfInstructionsText;
|
||||
|
||||
|
@ -164,6 +171,7 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
|
|||
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 ) );
|
||||
fShowBinarySourceFilesButton.setSelection( CCorePlugin.getDefault().getPluginPreferences().getBoolean( CCorePreferenceConstants.SHOW_SOURCE_FILES_IN_BINARIES ) );
|
||||
}
|
||||
|
||||
|
@ -211,6 +219,19 @@ 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();
|
||||
|
||||
for (Iterator iterator = setmap.keySet().iterator(); iterator.hasNext();) {
|
||||
String entry = (String) iterator.next();
|
||||
names.add(entry);
|
||||
}
|
||||
return (String[]) names.toArray(new String[names.size()]);
|
||||
}
|
||||
|
||||
private void createBinarySettings( Composite parent ) {
|
||||
|
@ -344,6 +365,7 @@ 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()) );
|
||||
getDisassemblySourceColor().store();
|
||||
CCorePlugin.getDefault().getPluginPreferences().setValue( CCorePreferenceConstants.SHOW_SOURCE_FILES_IN_BINARIES, fShowBinarySourceFilesButton.getSelection() );
|
||||
}
|
||||
|
@ -366,6 +388,7 @@ 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 ) );
|
||||
}
|
||||
|
||||
private static int getFormatId( int index ) {
|
||||
|
|
|
@ -25,6 +25,7 @@ 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:
|
||||
SourcePreferencePage.0=Common source lookup path settings.
|
||||
SourcePreferencePage.0=Common S&ource Lookup Path:
|
||||
DebuggerTypesPage.0=Select All
|
||||
|
|
Loading…
Add table
Reference in a new issue