From f5a02f5aabacfd326ca6cc1591267aadfbd03ade Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Wed, 30 Oct 2002 21:55:59 +0000 Subject: [PATCH] Implementation of the 'SaveMemoryChanges' action. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 7 ++- .../cdt/debug/core/IFormattedMemoryBlock.java | 2 + .../core/model/CFormattedMemoryBlock.java | 62 +++++++++++++++++-- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index a679bb6d101..d13527fcafd 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,4 +1,9 @@ -2002-10-29 Mikhail Khodjaiants +2002-10-30 Mikhail Khodjaiants + Implementation of the 'SaveMemoryChanges' action. + * IFormattedMemoryBlock.java: added the 'saveChanges' method. + * CFormattedMemoryBlock.java: implementation of the 'saveChanges' method. + +2002-10-30 Mikhail Khodjaiants Fix for bug 25283. * CDebugTarget.java: in 'setCurrentThread' method set the 'isCurrent' flag to false for the currently current thread. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java index e5fc105585d..df6c7fb5197 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java @@ -126,4 +126,6 @@ public interface IFormattedMemoryBlock extends IMemoryBlock void setFrozen( boolean frozen ); boolean isDirty(); + + void saveChanges() throws DebugException; } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java index 8f9dbfd7d25..2a48b1a9887 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java @@ -6,6 +6,7 @@ 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; @@ -84,8 +85,7 @@ public class CFormattedMemoryBlock extends CDebugElement private char fPaddingChar = '.'; private List fRows = null; private Long[] fChangedAddresses = new Long[0]; - // temporary - private boolean fIsDirty = false; + private boolean[] fDirtyBytes = null; /** * Constructor for CFormattedMemoryBlock. @@ -199,7 +199,7 @@ public class CFormattedMemoryBlock extends CDebugElement private void resetBytes() { fBytes = null; - fIsDirty = false; + fDirtyBytes = null; } private void resetRows() @@ -305,6 +305,8 @@ public class CFormattedMemoryBlock extends CDebugElement try { fBytes = fCDIMemoryBlock.getBytes(); + fDirtyBytes = new boolean[fBytes.length]; + Arrays.fill( fDirtyBytes, false ); } catch( CDIException e ) { @@ -486,7 +488,7 @@ public class CFormattedMemoryBlock extends CDebugElement { byte[] bytes = itemToBytes( newValue.toCharArray() ); setBytes( index * getWordSize(), bytes ); - fIsDirty = true; + Arrays.fill( fDirtyBytes, index * getWordSize(), index * getWordSize() + bytes.length, true ); resetRows(); } @@ -530,6 +532,56 @@ public class CFormattedMemoryBlock extends CDebugElement */ public boolean isDirty() { - return fIsDirty; + if ( fDirtyBytes != null ) + { + for ( int i = 0; i < fDirtyBytes.length; ++i ) + { + if ( fDirtyBytes[i] ) + return true; + } + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IFormattedMemoryBlock#saveChanges() + */ + public void saveChanges() throws DebugException + { + if ( getBytes() != null && fDirtyBytes != null && getCDIMemoryBlock() != null ) + { + int startIndex = -1; + for ( int i = 0; i < fDirtyBytes.length; ++i ) + { + if ( fDirtyBytes[i] ) + { + if ( startIndex == -1 ) + { + startIndex = i; + } + } + else + { + if ( startIndex != -1 ) + { + byte[] bytes = new byte[i - startIndex]; + for ( int j = startIndex; j < i; ++j ) + { + bytes[j - startIndex] = getBytes()[j]; + } + try + { + getCDIMemoryBlock().setValue( startIndex, bytes ); + startIndex = -1; + } + catch( CDIException e ) + { + targetRequestFailed( e.getMessage(), null ); + } + } + } + } + Arrays.fill( fDirtyBytes, false ); + } } }