From f3214e243866661f0527533b496cbdbb9abf2772 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Thu, 17 Oct 2002 23:17:02 +0000 Subject: [PATCH] Implementing the memory view support. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 9 + .../eclipse/cdt/debug/core/CDebugModel.java | 8 +- .../cdt/debug/core/ICMemoryManager.java | 33 +++- .../cdt/debug/core/IFormattedMemoryBlock.java | 8 + .../cdt/debug/internal/core/CDebugUtils.java | 27 +++ .../debug/internal/core/CMemoryManager.java | 69 +++++--- .../core/model/CFormattedMemoryBlock.java | 156 +++++++++++++++-- debug/org.eclipse.cdt.debug.ui/ChangeLog | 7 + .../ui/views/memory/MemoryControlArea.java | 159 ++++++++++++++++-- .../ui/views/memory/MemoryPresentation.java | 7 +- .../internal/ui/views/memory/MemoryView.java | 40 +++-- .../ui/views/memory/MemoryViewer.java | 11 +- 12 files changed, 467 insertions(+), 67 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index bcc392b2a2d..f41f51613ce 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,12 @@ +2002-10-17 Mikhail Khodjaiants + Implementing the memory view support: + * CDebugModel.java + * ICMemoryManager.java + * IFormattedMemoryBlock.java + * CFormattedMemoryBlock.java + * CDebugUtils.java + * CMemoryManager.java + 2002-10-16 Alain Magloire In the memory manager a string should be allowed to diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java index 9850fea0d5e..d95fac59283 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java @@ -294,7 +294,7 @@ public class CDebugModel public static ICWatchpoint watchpointExists( IResource resource, boolean write, boolean read, String expression ) throws CoreException { - String modelId = getPluginIdentifier(); + String modelId = getPluginIdentifier(); String markerType = CWatchpoint.getMarkerType(); IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); IBreakpoint[] breakpoints = manager.getBreakpoints( modelId ); @@ -359,7 +359,7 @@ public class CDebugModel } public static IFormattedMemoryBlock createFormattedMemoryBlock( IDebugTarget target, - long startAddress, + String startAddress, int format, int wordSize, int numberOfRows, @@ -375,6 +375,7 @@ public class CDebugModel .createMemoryBlock( startAddress, wordSize * numberOfRows * numberOfColumns ); return new CFormattedMemoryBlock( (CDebugTarget)target, cdiMemoryBlock, + startAddress, format, wordSize, numberOfRows, @@ -394,7 +395,7 @@ public class CDebugModel } public static IFormattedMemoryBlock createFormattedMemoryBlock( IDebugTarget target, - long startAddress, + String startAddress, int format, int wordSize, int numberOfRows, @@ -409,6 +410,7 @@ public class CDebugModel .createMemoryBlock( startAddress, wordSize * numberOfRows * numberOfColumns ); return new CFormattedMemoryBlock( (CDebugTarget)target, cdiMemoryBlock, + startAddress, format, wordSize, numberOfRows, diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICMemoryManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICMemoryManager.java index 726462205ce..0168192fa7c 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICMemoryManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICMemoryManager.java @@ -7,7 +7,6 @@ package org.eclipse.cdt.debug.core; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IMemoryBlock; /** * Enter type comment. @@ -16,13 +15,37 @@ import org.eclipse.debug.core.model.IMemoryBlock; */ public interface ICMemoryManager extends IAdaptable { - void addBlock( IMemoryBlock memoryBlock ) throws DebugException; + public static final int MEMORY_SIZE_BYTE = 1; + public static final int MEMORY_SIZE_HALF_WORD = 2; + public static final int MEMORY_SIZE_WORD = 4; + public static final int MEMORY_SIZE_DOUBLE_WORD = 8; + public static final int MEMORY_SIZE_FLOAT = 8; + public static final int MEMORY_SIZE_DOUBLE_FLOAT = 16; - void removeBlock( IMemoryBlock memoryBlock ) throws DebugException; + public static final int MEMORY_FORMAT_HEX = 0; + public static final int MEMORY_FORMAT_BINARY = 1; + public static final int MEMORY_FORMAT_OCTAL = 2; + public static final int MEMORY_FORMAT_SIGNED_DECIMAL = 3; + public static final int MEMORY_FORMAT_UNSIGNED_DECIMAL = 4; + + public static final int MEMORY_BYTES_PER_ROW_4 = 4; + public static final int MEMORY_BYTES_PER_ROW_8 = 8; + public static final int MEMORY_BYTES_PER_ROW_16 = 16; + public static final int MEMORY_BYTES_PER_ROW_32 = 32; + public static final int MEMORY_BYTES_PER_ROW_64 = 64; + public static final int MEMORY_BYTES_PER_ROW_128 = 128; + + int[] getSupportedFormats() throws DebugException; + + void setBlockAt( int index, IFormattedMemoryBlock memoryBlock ) throws DebugException; + + void removeBlock( IFormattedMemoryBlock memoryBlock ) throws DebugException; + + void removeBlock( int index ) throws DebugException; void removeAllBlocks() throws DebugException; - IMemoryBlock getBlock( int index ); + IFormattedMemoryBlock getBlock( int index ); - IMemoryBlock[] getBlocks(); + IFormattedMemoryBlock[] getBlocks(); } 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 a5125c93525..18c15e36513 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 @@ -17,6 +17,13 @@ import org.eclipse.debug.core.model.IMemoryBlock; */ public interface IFormattedMemoryBlock extends IMemoryBlock { + /** + * Returns the address expression specified to obtain this memory block. + * + * @return the address expression + */ + public String getAddressExpression(); + /** * Returns the format of the memory words of this block. * @@ -79,4 +86,5 @@ public interface IFormattedMemoryBlock extends IMemoryBlock int numberOfRows, int numberOfColumns, char paddingChar ) throws DebugException; + void dispose(); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java index f185fc21414..65a48b605de 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java @@ -77,4 +77,31 @@ public class CDebugUtils sb.append( addressString ); return sb.toString(); } + + public static char[] getByteText( byte b ) + { + return new char[]{ charFromByte( (byte)((b >>> 4) & 0x0f) ), + charFromByte( (byte)(b & 0x0f) ) }; + } + + public static char charFromByte( byte value ) + { + if ( value >= 0x0 && value <= 0x9 ) + return (char)(value + '0'); + if ( value >= 0xa && value <= 0xf ) + return (char)(value - 0xa + 'a'); + return '0'; + } + + public static char bytesToChar( byte[] bytes ) + { + try + { + return (char)Short.parseShort( new String( bytes ), 16 ); + } + catch( RuntimeException e ) + { + } + return 0; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryManager.java index 4c1b83cbb7f..f9b17519398 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryManager.java @@ -5,14 +5,13 @@ */ package org.eclipse.cdt.debug.internal.core; -import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; import org.eclipse.cdt.debug.core.ICMemoryManager; +import org.eclipse.cdt.debug.core.IFormattedMemoryBlock; import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.core.model.IMemoryBlock; /** * Enter type comment. @@ -21,7 +20,7 @@ import org.eclipse.debug.core.model.IMemoryBlock; */ public class CMemoryManager implements ICMemoryManager { - private List fBlocks; + private IFormattedMemoryBlock[] fBlocks = new IFormattedMemoryBlock[4]; private CDebugTarget fDebugTarget; /** @@ -29,45 +28,43 @@ public class CMemoryManager implements ICMemoryManager */ public CMemoryManager( CDebugTarget target ) { - fBlocks = new ArrayList( 4 ); + Arrays.fill( fBlocks, null ); setDebugTarget( target ); } /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICMemoryManager#addBlock(IMemoryBlock) + * @see org.eclipse.cdt.debug.core.ICMemoryManager#removeBlock(IFormattedMemoryBlock) */ - public void addBlock( IMemoryBlock memoryBlock ) throws DebugException - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.ICMemoryManager#removeBlock(IMemoryBlock) - */ - public void removeBlock( IMemoryBlock memoryBlock ) throws DebugException + public synchronized void removeBlock( IFormattedMemoryBlock memoryBlock ) throws DebugException { } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.ICMemoryManager#removeAllBlocks() */ - public void removeAllBlocks() throws DebugException + public synchronized void removeAllBlocks() throws DebugException { + for ( int i = 0; i < fBlocks.length; ++i ) + { + fBlocks[i].dispose(); + fBlocks[i] = null; + } } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.ICMemoryManager#getBlock(int) */ - public IMemoryBlock getBlock( int index ) + public IFormattedMemoryBlock getBlock( int index ) { - return null; + return ( index >= 0 && index < fBlocks.length ) ? fBlocks[index] : null; } /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.ICMemoryManager#getBlocks() */ - public IMemoryBlock[] getBlocks() + public IFormattedMemoryBlock[] getBlocks() { - return null; + return fBlocks; } /* (non-Javadoc) @@ -103,4 +100,38 @@ public class CMemoryManager implements ICMemoryManager public void dispose() { } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.ICMemoryManager#removeBlock(int) + */ + public synchronized void removeBlock( int index ) throws DebugException + { + IFormattedMemoryBlock block = getBlock( index ); + if ( block != null ) + { + block.dispose(); + } + setBlockAt( index, null ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.ICMemoryManager#setBlockAt(int, IFormattedMemoryBlock) + */ + public synchronized void setBlockAt( int index, IFormattedMemoryBlock memoryBlock ) throws DebugException + { + IFormattedMemoryBlock block = getBlock( index ); + if ( block != null ) + { + block.dispose(); + } + fBlocks[index] = memoryBlock; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.ICMemoryManager#getSupportedFormats() + */ + public int[] getSupportedFormats() throws DebugException + { + return new int[0]; + } } 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 530f61926f3..6853ad7dc7d 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 @@ -5,9 +5,14 @@ */ package org.eclipse.cdt.debug.internal.core.model; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.cdt.debug.core.IFormattedMemoryBlock; import org.eclipse.cdt.debug.core.IFormattedMemoryBlockRow; +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDIMemoryBlock; +import org.eclipse.cdt.debug.internal.core.CDebugUtils; import org.eclipse.debug.core.DebugException; /** @@ -17,13 +22,56 @@ import org.eclipse.debug.core.DebugException; */ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMemoryBlock { + class CFormattedMemoryBlockRow implements IFormattedMemoryBlockRow + { + private long fAddress; + private String[] fData; + private String fAscii; + + /** + * Constructor for CFormattedMemoryBlockRow. + */ + public CFormattedMemoryBlockRow( long address, String[] data, String ascii ) + { + fAddress = address; + fData = data; + fAscii = ascii; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IFormattedMemoryBlockRow#getAddress() + */ + public long getAddress() + { + return fAddress; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IFormattedMemoryBlockRow#getASCII() + */ + public String getASCII() + { + return fAscii; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IFormattedMemoryBlockRow#getData() + */ + public String[] getData() + { + return fData; + } + } + + private String fAddressExpression; private ICDIMemoryBlock fCDIMemoryBlock; private int fFormat; private int fWordSize; private int fNumberOfRows; private int fNumberOfColumns; private boolean fDisplayAscii = true; - private char fPaddingChar = 0; + private char fPaddingChar = '.'; + private List fRows = null; /** * Constructor for CFormattedMemoryBlock. @@ -31,6 +79,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public CFormattedMemoryBlock( CDebugTarget target, ICDIMemoryBlock cdiMemoryBlock, + String addressExpression, int format, int wordSize, int numberOfRows, @@ -38,6 +87,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe { super( target ); fCDIMemoryBlock = cdiMemoryBlock; + fAddressExpression = addressExpression; fFormat = format; fWordSize = wordSize; fNumberOfRows = numberOfRows; @@ -52,6 +102,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public CFormattedMemoryBlock( CDebugTarget target, ICDIMemoryBlock cdiMemoryBlock, + String addressExpression, int format, int wordSize, int numberOfRows, @@ -60,12 +111,13 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe { super( target ); fCDIMemoryBlock = cdiMemoryBlock; + fAddressExpression = addressExpression; fFormat = format; fWordSize = wordSize; fNumberOfRows = numberOfRows; fNumberOfColumns = numberOfColumns; fDisplayAscii = true; - fPaddingChar = paddingChar; + fPaddingChar = paddingChar; } /* (non-Javadoc) @@ -73,7 +125,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public int getFormat() { - return 0; + return fFormat; } /* (non-Javadoc) @@ -81,7 +133,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public int getWordSize() { - return 0; + return fWordSize; } /* (non-Javadoc) @@ -89,7 +141,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public int getNumberOfRows() { - return 0; + return fNumberOfRows; } /* (non-Javadoc) @@ -97,7 +149,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public int getNumberOfColumns() { - return 0; + return fNumberOfColumns; } /* (non-Javadoc) @@ -105,7 +157,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public boolean displayASCII() { - return false; + return fDisplayAscii; } /* (non-Javadoc) @@ -113,7 +165,28 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public IFormattedMemoryBlockRow[] getRows() { - return null; + if ( fRows == null ) + { + fRows = new ArrayList(); + try + { + int offset = 0; + byte[] bytes = getBytes(); + while( offset < bytes.length ) + { + int length = Math.min( fWordSize * fNumberOfColumns, bytes.length - offset ); + fRows.add( new CFormattedMemoryBlockRow( getStartAddress() + offset, + createData( bytes, offset, length ), + createAscii( bytes, offset, length ) ) ); + offset += length; + } + + } + catch( DebugException e ) + { + } + } + return (IFormattedMemoryBlockRow[])fRows.toArray( new IFormattedMemoryBlockRow[fRows.size()] ); } /* (non-Javadoc) @@ -174,6 +247,10 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public long getStartAddress() { + if ( fCDIMemoryBlock != null ) + { + return fCDIMemoryBlock.getStartAddress(); + } return 0; } @@ -182,6 +259,10 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public long getLength() { + if ( fCDIMemoryBlock != null ) + { + return fCDIMemoryBlock.getLength(); + } return 0; } @@ -190,7 +271,18 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public byte[] getBytes() throws DebugException { - return null; + if ( fCDIMemoryBlock != null ) + { + try + { + return fCDIMemoryBlock.getBytes(); + } + catch( CDIException e ) + { + targetRequestFailed( e.getMessage(), null ); + } + } + return new byte[0]; } /* (non-Javadoc) @@ -213,7 +305,51 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe */ public char getPaddingCharacter() { - return 0; + return fPaddingChar; } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IFormattedMemoryBlock#dispose() + */ + public void dispose() + { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.IFormattedMemoryBlock#getAddressExpression() + */ + public String getAddressExpression() + { + return fAddressExpression; + } + + private String[] createData( byte[] bytes, int offset, int length ) + { + List data = new ArrayList( length / getWordSize() ); + for ( int i = offset; i < offset + length; i += getWordSize() ) + { + data.add( createDataItem( bytes, i, Math.min( length + offset - i, getWordSize() ) ) ); + } + return (String[])data.toArray( new String[data.size()] ); + } + + private String createDataItem( byte[] bytes, int offset, int length ) + { + StringBuffer sb = new StringBuffer( length * 2 ); + for ( int i = offset; i < length + offset; ++i ) + { + sb.append( CDebugUtils.getByteText( bytes[i] ) ); + } + return sb.toString(); + } + + private String createAscii( byte[] bytes, int offset, int length ) + { + StringBuffer sb = new StringBuffer( length ); + for ( int i = offset; i < offset + length; ++i ) + { + sb.append( ( Character.isISOControl( (char)bytes[i] ) || bytes[i] < 0 ) ? getPaddingCharacter() : (char)bytes[i] ); + } + return sb.toString(); + } } diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index 9cf1e4e5842..47a6e039e56 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,10 @@ +2002-10-17 Mikhail Khodjaiants + Implementing the memory view support: + * MemoryControlArea.java + * MemoryPresentation.java + * MemoryView.java + * MemoryViewer.java + 2002-10-15 Mikhail Khodjaiants * CDebugUIPlugin.java: Moved the memory management functionality to the core. * MemoryControlArea.java: Moved the memory management functionality to the core. diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java index ad677ca2486..d69adf52393 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java @@ -6,9 +6,13 @@ package org.eclipse.cdt.debug.internal.ui.views.memory; +import org.eclipse.cdt.debug.core.CDebugModel; +import org.eclipse.cdt.debug.core.ICMemoryManager; import org.eclipse.cdt.debug.core.IFormattedMemoryBlock; -import org.eclipse.cdt.debug.core.IFormattedMemoryRetrieval; import org.eclipse.cdt.debug.internal.ui.preferences.ICDebugPreferenceConstants; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; @@ -29,11 +33,17 @@ public class MemoryControlArea extends Composite { private MemoryPresentation fPresentation; private int fIndex = 0; - private IFormattedMemoryRetrieval fInput = null; - private IFormattedMemoryBlock fMemoryBlock = null; + private ICMemoryManager fMemoryManager = null; private Text fAddressText; private MemoryText fMemoryText; + + private int fFormat = ICMemoryManager.MEMORY_FORMAT_HEX; + private int fWordSize = ICMemoryManager.MEMORY_SIZE_BYTE; + private int fNumberOfRows = 40; + private int fNumberOfColumns = 16; + private char fPaddingChar = '.'; + /** * Constructor for MemoryControlArea. * @param parent @@ -50,7 +60,7 @@ public class MemoryControlArea extends Composite GridData.GRAB_VERTICAL ); setLayout( layout ); setLayoutData( gridData ); - fIndex = index; + setIndex( index ); fPresentation = createPresentation(); fAddressText = createAddressText( this ); fMemoryText = createMemoryText( this, style, fPresentation ); @@ -104,7 +114,23 @@ public class MemoryControlArea extends Composite protected void handleAddressEnter() { -// String address = fAddressText.getText().trim(); + if ( getMemoryManager() != null ) + { + String address = fAddressText.getText().trim(); + try + { + removeBlock(); + if ( address.length() > 0 ) + { + createBlock( address ); + } + } + catch( DebugException e ) + { + CDebugUIPlugin.errorDialog( "Unable to get memory block.", e.getStatus() ); + } + refresh(); + } } public void propertyChange( PropertyChangeEvent event ) @@ -140,19 +166,35 @@ public class MemoryControlArea extends Composite } } - public void setInput( IFormattedMemoryRetrieval input ) + public void setInput( Object input ) { - fInput = input; -// fMemoryBlock = CDebugUIPlugin.getDefault().getBlock( fInput, fIndex ); - fPresentation.setMemoryBlock( fMemoryBlock ); - refresh(); + setMemoryManager( ( input instanceof ICMemoryManager ) ? (ICMemoryManager)input : null ); + getPresentation().setMemoryBlock( getMemoryBlock() ); + setAddressTextState(); + refresh(); } private void refresh() { - fAddressText.setText( fPresentation.getStartAddress() ); + fAddressText.setText( ( getPresentation() != null ) ? getPresentation().getAddressExpression() : "" ); fMemoryText.refresh(); } + + protected void setMemoryManager( ICMemoryManager mm ) + { + fMemoryManager = mm; + } + + protected ICMemoryManager getMemoryManager() + { + return fMemoryManager; + } + + protected IFormattedMemoryBlock getMemoryBlock() + { + return ( getMemoryManager() != null ) ? getMemoryManager().getBlock( getIndex() ) : null; + } + /* private void updatePresentation( PropertyChangeEvent event ) { @@ -178,4 +220,99 @@ public class MemoryControlArea extends Composite } } */ + + protected int getIndex() + { + return fIndex; + } + + protected void setIndex( int index ) + { + fIndex = index; + } + + private void createBlock( String address ) throws DebugException + { + if ( getMemoryManager() != null ) + { + getMemoryManager().setBlockAt( getIndex(), + CDebugModel.createFormattedMemoryBlock( (IDebugTarget)getMemoryManager().getAdapter( IDebugTarget.class ), + address, + getFormat(), + getWordSize(), + getNumberOfRows(), + getNumberOfColumns(), + getPaddingChar() ) ); + getPresentation().setMemoryBlock( getMemoryBlock() ); + } + } + + private void removeBlock() throws DebugException + { + if ( getMemoryManager() != null ) + { + getMemoryManager().removeBlock( getIndex() ); + getPresentation().setMemoryBlock( null ); + } + } + + public int getFormat() + { + return fFormat; + } + + public int getNumberOfColumns() + { + return fNumberOfColumns; + } + + public int getNumberOfRows() + { + return fNumberOfRows; + } + + public char getPaddingChar() + { + return fPaddingChar; + } + + public int getWordSize() + { + return fWordSize; + } + + public void setFormat(int format) + { + fFormat = format; + } + + public void setNumberOfColumns( int numberOfColumns ) + { + fNumberOfColumns = numberOfColumns; + } + + public void setNumberOfRows( int numberOfRows ) + { + fNumberOfRows = numberOfRows; + } + + public void setPaddingChar( char paddingChar ) + { + fPaddingChar = paddingChar; + } + + public void setWordSize( int wordSize ) + { + fWordSize = wordSize; + } + + private void enableAddressText( boolean enable ) + { + fAddressText.setEnabled( enable ); + } + + protected void setAddressTextState() + { + enableAddressText( getMemoryManager() != null ); + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java index 73c63a8c0d1..f61d710cafc 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java @@ -63,7 +63,7 @@ public class MemoryPresentation public String getText() { fAddressZones.clear(); - IFormattedMemoryBlockRow[] rows = fBlock.getRows(); + IFormattedMemoryBlockRow[] rows = ( getMemoryBlock() != null ) ? getMemoryBlock().getRows() : new IFormattedMemoryBlockRow[0]; String text = new String(); for ( int i = 0; i < rows.length; ++i ) { @@ -113,6 +113,11 @@ public class MemoryPresentation return ( fBlock != null ) ? getAddressString( fBlock.getStartAddress() ) : ""; } + public String getAddressExpression() + { + return ( fBlock != null ) ? fBlock.getAddressExpression() : ""; + } + private String getInterval( int length ) { char[] chars = new char[length]; diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java index 2ae6d99ba9c..240e192e280 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java @@ -5,6 +5,7 @@ */ package org.eclipse.cdt.debug.internal.ui.views.memory; +import org.eclipse.cdt.debug.core.ICMemoryManager; import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandlerView; @@ -12,7 +13,6 @@ import org.eclipse.cdt.debug.internal.ui.views.IDebugExceptionHandler; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IMemoryBlockRetrieval; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.action.IMenuManager; @@ -64,6 +64,8 @@ public class MemoryView extends AbstractDebugEventHandlerView */ protected void createActions() { + // set initial content here, as viewer has to be set + setInitialContent(); } /* (non-Javadoc) @@ -94,6 +96,10 @@ public class MemoryView extends AbstractDebugEventHandlerView */ public void selectionChanged( IWorkbenchPart part, ISelection selection ) { + if ( selection instanceof IStructuredSelection ) + { + setViewerInput( (IStructuredSelection)selection ); + } } /* (non-Javadoc) @@ -126,28 +132,23 @@ public class MemoryView extends AbstractDebugEventHandlerView protected void setViewerInput( IStructuredSelection ssel ) { - IMemoryBlockRetrieval memoryBlockRetrieval = null; - if ( ssel.size() == 1 ) + ICMemoryManager mm = null; + if ( ssel != null && ssel.size() == 1 ) { Object input = ssel.getFirstElement(); if ( input instanceof IDebugElement ) { - memoryBlockRetrieval = (IMemoryBlockRetrieval)((IDebugElement)input).getDebugTarget(); + mm = (ICMemoryManager)((IDebugElement)input).getDebugTarget().getAdapter( ICMemoryManager.class ); } } Object current = getViewer().getInput(); - if ( current == null && memoryBlockRetrieval == null ) - { - return; - } - - if ( current != null && current.equals( memoryBlockRetrieval ) ) + if ( current != null && current.equals( mm ) ) { return; } showViewer(); - getViewer().setInput( memoryBlockRetrieval ); + getViewer().setInput( mm ); } private IContentProvider createContentProvider() @@ -174,4 +175,21 @@ public class MemoryView extends AbstractDebugEventHandlerView { return new MemoryViewEventHandler( this ); } + + /** + * Initializes the viewer input on creation + */ + protected void setInitialContent() + { + ISelection selection = + getSite().getPage().getSelection( IDebugUIConstants.ID_DEBUG_VIEW ); + if ( selection instanceof IStructuredSelection && !selection.isEmpty() ) + { + setViewerInput( (IStructuredSelection)selection ); + } + else + { + setViewerInput( null ); + } + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java index f1329d8e9ab..9aac4a6a48b 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java @@ -5,7 +5,7 @@ */ package org.eclipse.cdt.debug.internal.ui.views.memory; -import org.eclipse.cdt.debug.core.IFormattedMemoryRetrieval; +import org.eclipse.cdt.debug.core.ICMemoryManager; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ContentViewer; import org.eclipse.jface.viewers.ISelection; @@ -64,7 +64,7 @@ public class MemoryViewer extends ContentViewer tabItem.setControl( fMemoryControlAreas[i] ); } fTabFolder.setSelection( 0 ); - } + } return fControl; } @@ -100,10 +100,7 @@ public class MemoryViewer extends ContentViewer protected void inputChanged( Object input, Object oldInput ) { - if ( input instanceof IFormattedMemoryRetrieval ) - { - for ( int i = 0; i < fMemoryControlAreas.length; ++i ) - fMemoryControlAreas[i].setInput( (IFormattedMemoryRetrieval)input ); - } + for ( int i = 0; i < fMemoryControlAreas.length; ++i ) + fMemoryControlAreas[i].setInput( (ICMemoryManager)input ); } }