Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Implementing editing features of the memory view

Implementing editing features of the memory view.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.35
diff -u -r1.35 ChangeLog
--- ChangeLog 28 Oct 2002 23:30:22 -0000 1.35
+++ ChangeLog 30 Oct 2002 04:58:54 -0000
@@ -1,3 +1,9 @@
+2002-10-29 Mikhail Khodjaiants
+ Implementing editing features of the memory view.
+ * IFormattedMemoryBlockRow.java
+ * IFormattedMemoryBlock.java
+ * CFormattedMemoryBlock.java
+
 2002-10-28 Mikhail Khodjaiants
  Implementing editing features of the memory view.
  * IFormattedMemoryBlockRow.java
Index: src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java,v
retrieving revision 1.9
diff -u -r1.9 IFormattedMemoryBlock.java
--- src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java 28 Oct 2002 02:46:38 -0000 1.9
+++ src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java 30 Oct 2002 04:58:54 -0000
@@ -124,4 +124,6 @@
  boolean isFrozen();
  
  void setFrozen( boolean frozen );

+ boolean isDirty();
 }
Index: src/org/eclipse/cdt/debug/core/IFormattedMemoryBlockRow.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IFormattedMemoryBlockRow.java,v
retrieving revision 1.2
diff -u -r1.2 IFormattedMemoryBlockRow.java
--- src/org/eclipse/cdt/debug/core/IFormattedMemoryBlockRow.java 28 Oct 2002 23:30:22 -0000 1.2
+++ src/org/eclipse/cdt/debug/core/IFormattedMemoryBlockRow.java 30 Oct 2002 04:58:54 -0000
@@ -34,6 +34,4 @@
   * @return the ASCII dump for this row
   */
  String getASCII();

- Integer[] getDirtyItems();
 }
Index: src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java,v
retrieving revision 1.8
diff -u -r1.8 CFormattedMemoryBlock.java
--- src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java 28 Oct 2002 23:30:22 -0000 1.8
+++ src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java 30 Oct 2002 04:58:55 -0000
@@ -6,7 +6,6 @@
 package org.eclipse.cdt.debug.internal.core.model;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.eclipse.cdt.debug.core.CDebugCorePlugin;
@@ -38,7 +37,6 @@
   private long fAddress;
   private String[] fData;
   private String fAscii;
-  private boolean[] fDirtyItems;
 
   /**
    * Constructor for CFormattedMemoryBlockRow.
@@ -48,8 +46,6 @@
    fAddress = address;
    fData = data;
    fAscii = ascii;
-   fDirtyItems = new boolean[fData.length];
-   Arrays.fill( fDirtyItems, false );
   }
 
   /* (non-Javadoc)
@@ -75,30 +71,11 @@
   {
    return fData;
   }
-
-  protected void setData( int colIndex, String newValue )
-  {
-   if ( colIndex < fData.length )
-   {
-    fData[colIndex] = newValue;
-    fDirtyItems[colIndex] = true;
-   }
-  }
-  
-  public Integer[] getDirtyItems()
-  {
-   ArrayList list = new ArrayList( fDirtyItems.length );
-   for ( int i = 0; i < fDirtyItems.length; ++i )
-   {
-    if ( fDirtyItems[i] )
-     list.add( new Integer( i ) );
-   }
-   return (Integer[])list.toArray( new Integer[list.size()] );
-  }
  }
 
  private String fAddressExpression;
  private ICDIMemoryBlock fCDIMemoryBlock;
+ private byte[] fBytes = null;
  private int fFormat;
  private int fWordSize;
  private int fNumberOfRows;
@@ -107,6 +84,8 @@
  private char fPaddingChar = '.';
  private List fRows = null;
  private Long[] fChangedAddresses = new Long[0];
+ // temporary
+ private boolean fIsDirty = false;
 
  /**
   * Constructor for CFormattedMemoryBlock.
@@ -200,7 +179,7 @@
    {
     int offset = 0;
     byte[] bytes = getBytes();
-    while( offset < bytes.length )
+    while( bytes != null && offset < bytes.length )
     {
      int length = Math.min( fWordSize * fNumberOfColumns, bytes.length - offset );
      fRows.add( new CFormattedMemoryBlockRow( getStartAddress() + offset,
@@ -216,7 +195,13 @@
   }
   return (IFormattedMemoryBlockRow[])fRows.toArray( new IFormattedMemoryBlockRow[fRows.size()] );
  }

+
+ private void resetBytes()
+ {
+  fBytes = null;
+  fIsDirty = false;
+ }
+
  private void resetRows()
  {
   fRows = null;
@@ -313,18 +298,21 @@
   */
  public byte[] getBytes() throws DebugException
  {
-  if ( fCDIMemoryBlock != null )
-  {
-   try
-   {
-    return fCDIMemoryBlock.getBytes();
-   }
-   catch( CDIException e )
+  if ( fBytes == null )
+  {
+   if ( fCDIMemoryBlock != null )
    {
-    targetRequestFailed( e.getMessage(), null );
+    try
+    {
+     fBytes = fCDIMemoryBlock.getBytes();
+    }
+    catch( CDIException e )
+    {
+     targetRequestFailed( e.getMessage(), null );
+    }
    }
   }
-  return new byte[0];
+  return fBytes;
  }
 
  /* (non-Javadoc)
@@ -454,6 +442,7 @@
  
  private void handleChangedEvent( ICDIMemoryChangedEvent event )
  {
+  resetBytes();
   resetRows();
   setChangedAddresses( event.getAddresses() );
   fireChangeEvent( DebugEvent.CONTENT );
@@ -495,15 +484,52 @@
   */
  public void setItemValue( int index, String newValue ) throws DebugException
  {
-  int rowIndex = index / getNumberOfColumns();
-  if ( rowIndex < getRows().length )
+  byte[] bytes = itemToBytes( newValue.toCharArray() );
+  setBytes( index * getWordSize(), bytes );
+  fIsDirty = true;
+  resetRows();
+ }

+ private void setBytes( int index, byte[] newBytes )
+ {
+  try
   {
-   CFormattedMemoryBlockRow row = (CFormattedMemoryBlockRow)getRows()[rowIndex];
-   int colIndex = index % getNumberOfColumns();
-   if ( colIndex < row.getData().length )
+   byte[] bytes = getBytes();
+   for ( int i = index; i < index + newBytes.length; ++i )
    {
-    row.setData( colIndex, newValue );
-   }   
+    bytes[i] = newBytes[i - index];
+   }
   }
+  catch( DebugException e )
+  {
+  }
+ }

+ private byte[] itemToBytes( char[] chars )
+ {
+  switch( getFormat() )
+  {
+   case IFormattedMemoryBlock.MEMORY_FORMAT_HEX:
+    return hexItemToBytes( chars );
+  }
+  return new byte[0];
+ }

+ private byte[] hexItemToBytes( char[] chars )
+ {
+  byte[] result = new byte[chars.length / 2];
+  for ( int i = 0; i < result.length; ++i )
+  {
+   result[i] = CDebugUtils.textToByte( new char[] { chars[2 * i], chars[2 * i + 1] } );
+  }
+  return result;
+ }
+
+ /**
+  * @see org.eclipse.cdt.debug.core.IFormattedMemoryBlock#isDirty()
+  */
+ public boolean isDirty()
+ {
+  return fIsDirty;
  }
 }


Back to the top