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:
parent
23daefc02e
commit
0198b4400b
11 changed files with 159 additions and 5 deletions
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
* Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
|
||||
*******************************************************************************/
|
||||
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
|
||||
* be extended
|
||||
*/
|
||||
public interface IAddress extends Comparable
|
||||
{
|
||||
public interface IAddress extends Comparable {
|
||||
/**
|
||||
* Adds offset to address and returns new address object
|
||||
* which is the result
|
||||
|
@ -103,6 +103,16 @@ public interface IAddress extends Comparable
|
|||
*/
|
||||
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
|
||||
* toHexAddressString().length(). It is present for perfomance purpose.
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
******************************************************************************/
|
||||
* Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.utils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
@ -26,6 +27,8 @@ public class Addr32 implements IAddress {
|
|||
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 BINARY_DIGITS_NUM = BYTES_NUM * 8;
|
||||
private static final int BINARY_CHARS_NUM = BINARY_DIGITS_NUM + 2;
|
||||
|
||||
private final long address;
|
||||
|
||||
|
@ -131,6 +134,18 @@ public class Addr32 implements IAddress {
|
|||
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() {
|
||||
return CHARS_NUM;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
* Mark Mitchell, CodeSourcery - Bug 136896: View variables in binary format
|
||||
******************************************************************************/
|
||||
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 DIGITS_NUM = BYTES_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;
|
||||
|
||||
|
@ -126,6 +129,18 @@ public class Addr64 implements IAddress {
|
|||
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() {
|
||||
return CHARS_NUM;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
Bug 144719: [Modules view] Modules from from different sessions are mixed up.
|
||||
* CDebugElement.java
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* 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;
|
||||
|
||||
|
@ -246,6 +247,12 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( (stringValue.length() > 2) ? stringValue.substring( stringValue.length() - 2 ) : 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;
|
||||
}
|
||||
|
||||
|
@ -260,6 +267,12 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : 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() );
|
||||
sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
|
||||
return sb.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -274,6 +287,12 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : 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() );
|
||||
sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue );
|
||||
return sb.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -297,6 +316,16 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( Long.toHexString( value.longValue() ) );
|
||||
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 ) {
|
||||
}
|
||||
|
@ -323,6 +352,16 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( Long.toHexString( value.longValue() ) );
|
||||
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 ) {
|
||||
}
|
||||
|
@ -348,6 +387,12 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : stringValue );
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -370,6 +415,12 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -387,6 +438,8 @@ public class CValue extends AbstractCValue {
|
|||
return address.toHexAddressString();
|
||||
if ( CVariableFormat.DECIMAL.equals( format ) )
|
||||
return address.toString();
|
||||
if ( CVariableFormat.BINARY.equals( format ) )
|
||||
return address.toBinaryAddressString();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -404,6 +457,12 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( (stringValue.length() > 4) ? stringValue.substring( stringValue.length() - 4 ) : 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() );
|
||||
sb.append( (stringValue.length() > 16) ? stringValue.substring( stringValue.length() - 16 ) : stringValue );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
if ( size == 4 ) {
|
||||
CVariableFormat format = getParentVariable().getFormat();
|
||||
|
@ -416,6 +475,12 @@ public class CValue extends AbstractCValue {
|
|||
sb.append( (stringValue.length() > 8) ? stringValue.substring( stringValue.length() - 8 ) : 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() );
|
||||
sb.append( (stringValue.length() > 32) ? stringValue.substring( stringValue.length() - 32 ) : stringValue );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return value.getValueString();
|
||||
|
|
|
@ -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
|
||||
Bug 144719: [Modules view] Modules from from different sessions are mixed up.
|
||||
* ModulesViewEventHandler.java
|
||||
|
|
|
@ -62,6 +62,7 @@ CVariableFormatMenu.label=Format
|
|||
HexVariableFormatAction.label=Hexadecimal
|
||||
DecVariableFormatAction.label=Decimal
|
||||
NaturalVariableFormatAction.label=Natural
|
||||
BinaryVariableFormatAction.label=Binary
|
||||
|
||||
CDebugActionGroup.name=C/C++ Debug
|
||||
|
||||
|
|
|
@ -397,6 +397,13 @@
|
|||
enablesFor="1"
|
||||
id="org.eclipse.cdt.debug.internal.ui.actions.NaturalVariableFormatActionDelegate">
|
||||
</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
|
||||
objectClass="org.eclipse.cdt.debug.core.model.ICSignal"
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
|
@ -71,9 +71,9 @@ public class CDebugPreferencePage extends PreferencePage implements IWorkbenchPr
|
|||
private static final int NUMBER_OF_DIGITS = 3;
|
||||
|
||||
// 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;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ CDebugPreferencePage.10=Default register format:
|
|||
CDebugPreferencePage.11=Disassembly options
|
||||
CDebugPreferencePage.12=Maximum number of displayed instructions:
|
||||
CDebugPreferencePage.13=The valid value range is [{0},{1}].
|
||||
CDebugPreferencePage.14=Binary
|
||||
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