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

Bug 136896: View variables in binary format.

Applied modified patch from Mark Mitchell (CodeSourcery).
This commit is contained in:
Mikhail Khodjaiants 2006-08-16 08:45:36 +00:00
parent 23daefc02e
commit 0198b4400b
11 changed files with 159 additions and 5 deletions

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Intel Corporation - Initial API and implementation * Intel Corporation - Initial API and implementation
* Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core; package org.eclipse.cdt.core;
@ -20,8 +21,7 @@ import java.math.BigInteger;
* Please see Addr32 and Addr64 classes to see how this interface should * Please see Addr32 and Addr64 classes to see how this interface should
* be extended * be extended
*/ */
public interface IAddress extends Comparable public interface IAddress extends Comparable {
{
/** /**
* Adds offset to address and returns new address object * Adds offset to address and returns new address object
* which is the result * which is the result
@ -103,6 +103,16 @@ public interface IAddress extends Comparable
*/ */
String toHexAddressString(); String toHexAddressString();
/**
* Converts address to the binary representation with '0b' prefix and
* with all leading zeros. The length of returned string should be
* the same for all addresses of given class. I.e. 34 for 32-bit
* addresses and 66 for 64-bit addresses
* @return
*/
String toBinaryAddressString();
/** /**
* Returns amount of symbols in hex representation. Is identical to * Returns amount of symbols in hex representation. Is identical to
* toHexAddressString().length(). It is present for perfomance purpose. * toHexAddressString().length(). It is present for perfomance purpose.

View file

@ -7,7 +7,8 @@
* *
* Contributors: * Contributors:
* Intel Corporation - Initial API and implementation * Intel Corporation - Initial API and implementation
******************************************************************************/ * Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
******************************************************************************/
package org.eclipse.cdt.utils; package org.eclipse.cdt.utils;
import java.math.BigInteger; import java.math.BigInteger;
@ -26,6 +27,8 @@ public class Addr32 implements IAddress {
private static final int BYTES_NUM = 4; private static final int BYTES_NUM = 4;
private static final int DIGITS_NUM = BYTES_NUM * 2; private static final int DIGITS_NUM = BYTES_NUM * 2;
private static final int CHARS_NUM = DIGITS_NUM + 2; private static final int CHARS_NUM = DIGITS_NUM + 2;
private static final int BINARY_DIGITS_NUM = BYTES_NUM * 8;
private static final int BINARY_CHARS_NUM = BINARY_DIGITS_NUM + 2;
private final long address; private final long address;
@ -131,6 +134,18 @@ public class Addr32 implements IAddress {
return sb.toString(); return sb.toString();
} }
public String toBinaryAddressString() {
String addressString = Long.toString(address, 2);
StringBuffer sb = new StringBuffer(BINARY_CHARS_NUM);
int count = BINARY_DIGITS_NUM - addressString.length();
sb.append("0b"); //$NON-NLS-1$
for (int i = 0; i < count; ++i) {
sb.append('0');
}
sb.append(addressString);
return sb.toString();
}
public int getCharsNum() { public int getCharsNum() {
return CHARS_NUM; return CHARS_NUM;
} }

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Intel Corporation - Initial API and implementation * Intel Corporation - Initial API and implementation
* Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.utils; package org.eclipse.cdt.utils;
@ -24,6 +25,8 @@ public class Addr64 implements IAddress {
private static final int BYTES_NUM = 8; private static final int BYTES_NUM = 8;
private static final int DIGITS_NUM = BYTES_NUM * 2; private static final int DIGITS_NUM = BYTES_NUM * 2;
private static final int CHARS_NUM = DIGITS_NUM + 2; private static final int CHARS_NUM = DIGITS_NUM + 2;
private static final int BINARY_DIGITS_NUM = BYTES_NUM * 8;
private static final int BINARY_CHARS_NUM = BINARY_DIGITS_NUM + 2;
private final BigInteger address; private final BigInteger address;
@ -126,6 +129,18 @@ public class Addr64 implements IAddress {
return sb.toString(); return sb.toString();
} }
public String toBinaryAddressString() {
String addressString = address.toString(2);
StringBuffer sb = new StringBuffer(BINARY_CHARS_NUM);
int count = BINARY_DIGITS_NUM - addressString.length();
sb.append("0b"); //$NON-NLS-1$
for (int i = 0; i < count; ++i) {
sb.append('0');
}
sb.append(addressString);
return sb.toString();
}
public int getCharsNum() { public int getCharsNum() {
return CHARS_NUM; return CHARS_NUM;
} }

View file

@ -1,3 +1,8 @@
2006-08-14 Mikhail Khodjaiants
Bug 136896: View variables in binary format.
Applied modified patch from Mark Mitchell (CodeSourcery).
* CValue.java
2006-05-31 Mikhail Khodjaiants 2006-05-31 Mikhail Khodjaiants
Bug 144719: [Modules view] Modules from from different sessions are mixed up. Bug 144719: [Modules view] Modules from from different sessions are mixed up.
* CDebugElement.java * CDebugElement.java

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.core.model; package org.eclipse.cdt.debug.internal.core.model;
@ -246,6 +247,12 @@ public class CValue extends AbstractCValue {
sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : stringValue ); sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : stringValue );
return sb.toString(); 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; return null;
} }
@ -260,6 +267,12 @@ public class CValue extends AbstractCValue {
sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue ); sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
return sb.toString(); 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() );
sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
return sb.toString();
}
return null; return null;
} }
@ -274,6 +287,12 @@ public class CValue extends AbstractCValue {
sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString(); 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() );
sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue );
return sb.toString();
}
return null; return null;
} }
@ -297,6 +316,16 @@ public class CValue extends AbstractCValue {
sb.append( Long.toHexString( value.longValue() ) ); sb.append( Long.toHexString( value.longValue() ) );
return sb.toString(); return sb.toString();
} }
else if ( CVariableFormat.BINARY.equals( format ) ) {
StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$
if ( isUnsigned() ) {
BigInteger bigValue = new BigInteger( value.getValueString() );
sb.append( bigValue.toString( 2 ) );
}
else
sb.append( Long.toBinaryString( value.longValue() ) );
return sb.toString();
}
} }
catch( NumberFormatException e ) { catch( NumberFormatException e ) {
} }
@ -323,6 +352,16 @@ public class CValue extends AbstractCValue {
sb.append( Long.toHexString( value.longValue() ) ); sb.append( Long.toHexString( value.longValue() ) );
return sb.toString(); return sb.toString();
} }
else if ( CVariableFormat.BINARY.equals( format ) ) {
StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$
if ( isUnsigned() ) {
BigInteger bigValue = new BigInteger( value.getValueString() );
sb.append( bigValue.toString( 2 ) );
}
else
sb.append( Long.toBinaryString( value.longValue() ) );
return sb.toString();
}
} }
catch( NumberFormatException e ) { catch( NumberFormatException e ) {
} }
@ -348,6 +387,12 @@ public class CValue extends AbstractCValue {
sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString(); return sb.toString();
} }
else if ( CVariableFormat.BINARY.equals( format ) ) {
StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$
String stringValue = Long.toBinaryString( longValue );
sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue );
return sb.toString();
}
return null; return null;
} }
@ -370,6 +415,12 @@ public class CValue extends AbstractCValue {
sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue ); sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
return sb.toString(); return sb.toString();
} }
else if ( CVariableFormat.BINARY.equals( format ) ) {
StringBuffer sb = new StringBuffer( "0b" ); //$NON-NLS-1$
String stringValue = Long.toHexString( longValue );
sb.append( (stringValue.length() > 64) ? stringValue.substring( stringValue.length() - 64 ) : stringValue );
return sb.toString();
}
return null; return null;
} }
@ -387,6 +438,8 @@ public class CValue extends AbstractCValue {
return address.toHexAddressString(); return address.toHexAddressString();
if ( CVariableFormat.DECIMAL.equals( format ) ) if ( CVariableFormat.DECIMAL.equals( format ) )
return address.toString(); return address.toString();
if ( CVariableFormat.BINARY.equals( format ) )
return address.toBinaryAddressString();
return null; return null;
} }
@ -404,6 +457,12 @@ public class CValue extends AbstractCValue {
sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue ); sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : stringValue );
return sb.toString(); 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() );
sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
return sb.toString();
}
} }
if ( size == 4 ) { if ( size == 4 ) {
CVariableFormat format = getParentVariable().getFormat(); CVariableFormat format = getParentVariable().getFormat();
@ -416,6 +475,12 @@ public class CValue extends AbstractCValue {
sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue ); sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
return sb.toString(); 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() );
sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue );
return sb.toString();
}
} }
} }
return value.getValueString(); return value.getValueString();

View file

@ -1,3 +1,12 @@
2006-08-14 Mikhail Khodjaiants
Bug 136896: View variables in binary format.
Applied modified patch from Mark Mitchell (CodeSourcery).
* plugin.properties
* plugin.xml
* PreferenceMessages.properties
* CDebugPreferencePage.java
* BinaryVariableFormatActionDelegate.java
2006-05-31 Mikhail Khodjaiants 2006-05-31 Mikhail Khodjaiants
Bug 144719: [Modules view] Modules from from different sessions are mixed up. Bug 144719: [Modules view] Modules from from different sessions are mixed up.
* ModulesViewEventHandler.java * ModulesViewEventHandler.java

View file

@ -62,6 +62,7 @@ CVariableFormatMenu.label=Format
HexVariableFormatAction.label=Hexadecimal HexVariableFormatAction.label=Hexadecimal
DecVariableFormatAction.label=Decimal DecVariableFormatAction.label=Decimal
NaturalVariableFormatAction.label=Natural NaturalVariableFormatAction.label=Natural
BinaryVariableFormatAction.label=Binary
CDebugActionGroup.name=C/C++ Debug CDebugActionGroup.name=C/C++ Debug

View file

@ -397,6 +397,13 @@
enablesFor="1" enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.NaturalVariableFormatActionDelegate"> id="org.eclipse.cdt.debug.internal.ui.actions.NaturalVariableFormatActionDelegate">
</action> </action>
<action
class="org.eclipse.cdt.debug.internal.ui.actions.BinaryVariableFormatActionDelegate"
enablesFor="1"
helpContextId="binary_variable_format_action_context"
id="org.eclipse.cdt.debug.internal.ui.actions.BinaryVariableFormatActionDelegate"
label="%BinaryVariableFormatAction.label"
menubarPath="org.eclipse.cdt.debug.ui.CVariableFormatMenu/formatGroup"/>
</objectContribution> </objectContribution>
<objectContribution <objectContribution
objectClass="org.eclipse.cdt.debug.core.model.ICSignal" objectClass="org.eclipse.cdt.debug.core.model.ICSignal"

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.model.CVariableFormat;
/**
* The delegate of the "Binary Format" action.
*/
public class BinaryVariableFormatActionDelegate extends VariableFormatActionDelegate {
/**
* Constructor for BinaryVariableFormatActionDelegate.
*/
public BinaryVariableFormatActionDelegate() {
super( CVariableFormat.BINARY );
}
}

View file

@ -71,9 +71,9 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
private static final int NUMBER_OF_DIGITS = 3; private static final int NUMBER_OF_DIGITS = 3;
// Format constants // Format constants
private static int[] fFormatIds = new int[]{ ICDIFormat.NATURAL, ICDIFormat.HEXADECIMAL, ICDIFormat.DECIMAL }; 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" ) }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 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 PropertyChangeListener fPropertyChangeListener; private PropertyChangeListener fPropertyChangeListener;

View file

@ -22,6 +22,7 @@ CDebugPreferencePage.10=Default register format:
CDebugPreferencePage.11=Disassembly options CDebugPreferencePage.11=Disassembly options
CDebugPreferencePage.12=Maximum number of displayed instructions: CDebugPreferencePage.12=Maximum number of displayed instructions:
CDebugPreferencePage.13=The valid value range is [{0},{1}]. CDebugPreferencePage.13=The valid value range is [{0},{1}].
CDebugPreferencePage.14=Binary
SourcePreferencePage.0=Common source lookup path settings. SourcePreferencePage.0=Common source lookup path settings.
SourcePreferencePage.0=Common S&ource Lookup Path: SourcePreferencePage.0=Common S&ource Lookup Path:
DebuggerTypesPage.0=Select All DebuggerTypesPage.0=Select All