Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Implementing decimal format support of the Memory view

Implementing decimal format support of the Memory view.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/ChangeLog,v
retrieving revision 1.25
diff -u -r1.25 ChangeLog
--- ChangeLog 31 Oct 2002 23:29:27 -0000 1.25
+++ ChangeLog 1 Nov 2002 23:24:37 -0000
@@ -1,3 +1,7 @@
+2002-11-01 Mikhail Khodjaiants
+ Implementing decimal format support of the Memory view.
+ * MemoryPresentation.java
+
 2002-10-31 Mikhail Khodjaiants
  Removed the 'Modified Value Color' field from the 'Debug/Memory Views'
  preference page.
Index: src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java,v
retrieving revision 1.9
diff -u -r1.9 MemoryPresentation.java
--- src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java 30 Oct 2002 05:03:21 -0000 1.9
+++ src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java 1 Nov 2002 23:24:37 -0000
@@ -151,7 +151,7 @@
   String[] items = row.getData();
   for ( int i = 0; i < items.length; ++i )
   {
-   result.append( items[i] );
+   result.append( getDataItemPresentation( items[i] ) );
    result.append( getInterval( INTERVAL_BETWEEN_DATA_ITEMS ) );
   }
   if ( displayASCII() )
@@ -238,7 +238,17 @@
  private int getDataItemLength()
  {
   if ( getMemoryBlock() != null )
-   return getMemoryBlock().getWordSize() * 2;
+  {
+   switch( getDataFormat() )
+   {
+    case IFormattedMemoryBlock.MEMORY_FORMAT_HEX:
+     return getMemoryBlock().getWordSize() * 2;
+    case IFormattedMemoryBlock.MEMORY_FORMAT_SIGNED_DECIMAL:
+     return getDecimalDataItemLength( getMemoryBlock().getWordSize(), true );
+    case IFormattedMemoryBlock.MEMORY_FORMAT_UNSIGNED_DECIMAL:
+     return getDecimalDataItemLength( getMemoryBlock().getWordSize(), false );
+   }
+  }
   return 0;
  }
  
@@ -302,7 +312,7 @@
  {
   if ( getMemoryBlock() != null )
    return getMemoryBlock().getFormat();
-  return -1;
+  return IFormattedMemoryBlock.MEMORY_FORMAT_HEX;
  }
  
  private Long[] getChangedAddresses()
@@ -495,5 +505,55 @@
    return getMemoryBlock().isDirty();
   }
   return false;
+ }

+ private String getDataItemPresentation( String item )
+ {
+  switch( getDataFormat() )
+  {
+   case IFormattedMemoryBlock.MEMORY_FORMAT_HEX:
+    return item;
+   case IFormattedMemoryBlock.MEMORY_FORMAT_SIGNED_DECIMAL:
+    return convertToDecimal( getWordSize(), item, true );
+   case IFormattedMemoryBlock.MEMORY_FORMAT_UNSIGNED_DECIMAL:
+    return convertToDecimal( getWordSize(), item, false );
+  }
+  return "";
+ }

+ private int getDecimalDataItemLength( int wordSize, boolean signed )
+ {
+  switch( wordSize )
+  {
+   case IFormattedMemoryBlock.MEMORY_SIZE_HALF_WORD:
+    return ( signed ) ? 6 : 5;
+   case IFormattedMemoryBlock.MEMORY_SIZE_WORD:
+    return ( signed ) ? 11 : 10;
+  }
+  return 0;
+ }

+ private int getWordSize()
+ {
+  if ( getMemoryBlock() != null )
+  {
+   return getMemoryBlock().getWordSize();
+  }
+  return 0;
+ }

+ private String convertToDecimal( int wordSize, String item, boolean signed )
+ {
+  String result = "";
+  switch( wordSize )
+  {
+   case IFormattedMemoryBlock.MEMORY_SIZE_HALF_WORD:
+    result = Long.toString( CDebugUtils.toShort( item.toCharArray(), signed ) );
+    break;
+   case IFormattedMemoryBlock.MEMORY_SIZE_WORD:
+    result = Long.toString( CDebugUtils.toInt( item.toCharArray(), signed ) );
+    break;
+  }
+  return CDebugUtils.prependString( result, getDataItemLength(), ' ' );
  }
 }


Back to the top