Skip to main content

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

Implementing the memory view support.

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/ChangeLog,v
retrieving revision 1.19
diff -u -r1.19 ChangeLog
--- ChangeLog 17 Oct 2002 14:29:21 -0000 1.19
+++ ChangeLog 17 Oct 2002 23:11:16 -0000
@@ -1,3 +1,12 @@
+2002-10-15 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
Index: src/org/eclipse/cdt/debug/core/CDebugModel.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugModel.java,v
retrieving revision 1.32
diff -u -r1.32 CDebugModel.java
--- src/org/eclipse/cdt/debug/core/CDebugModel.java 15 Oct 2002 21:42:17 -0000 1.32
+++ src/org/eclipse/cdt/debug/core/CDebugModel.java 17 Oct 2002 23:11:16 -0000
@@ -294,7 +294,7 @@
 
  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 static IFormattedMemoryBlock createFormattedMemoryBlock( IDebugTarget target,
-                 long startAddress,
+                 String startAddress,
                     int format,
                     int wordSize,
                     int numberOfRows,
@@ -375,6 +375,7 @@
                     .createMemoryBlock( startAddress, wordSize * numberOfRows * numberOfColumns );
     return new CFormattedMemoryBlock( (CDebugTarget)target,
               cdiMemoryBlock,
+              startAddress,
               format,
               wordSize,
               numberOfRows,
@@ -394,7 +395,7 @@
  }
 
  public static IFormattedMemoryBlock createFormattedMemoryBlock( IDebugTarget target,
-                 long startAddress,
+                 String startAddress,
                     int format,
                     int wordSize,
                     int numberOfRows,
@@ -409,6 +410,7 @@
                     .createMemoryBlock( startAddress, wordSize * numberOfRows * numberOfColumns );
     return new CFormattedMemoryBlock( (CDebugTarget)target,
               cdiMemoryBlock,
+              startAddress,
               format,
               wordSize,
               numberOfRows,
Index: src/org/eclipse/cdt/debug/core/ICMemoryManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICMemoryManager.java,v
retrieving revision 1.1
diff -u -r1.1 ICMemoryManager.java
--- src/org/eclipse/cdt/debug/core/ICMemoryManager.java 15 Oct 2002 21:42:17 -0000 1.1
+++ src/org/eclipse/cdt/debug/core/ICMemoryManager.java 17 Oct 2002 23:11:16 -0000
@@ -7,7 +7,6 @@
 
 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 @@
  */
 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();
 }
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.2
diff -u -r1.2 IFormattedMemoryBlock.java
--- src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java 15 Oct 2002 21:42:17 -0000 1.2
+++ src/org/eclipse/cdt/debug/core/IFormattedMemoryBlock.java 17 Oct 2002 23:11:16 -0000
@@ -18,6 +18,13 @@
 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.
   *
   * @return The format of the memory words of this block
@@ -79,4 +86,5 @@
        int numberOfRows,
        int numberOfColumns,
        char paddingChar ) throws DebugException;
+ void dispose();
 }
Index: src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java,v
retrieving revision 1.3
diff -u -r1.3 CDebugUtils.java
--- src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java 10 Oct 2002 15:29:50 -0000 1.3
+++ src/org/eclipse/cdt/debug/internal/core/CDebugUtils.java 17 Oct 2002 23:11:17 -0000
@@ -77,4 +77,31 @@
   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;
+ }
 }
Index: src/org/eclipse/cdt/debug/internal/core/CMemoryManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CMemoryManager.java,v
retrieving revision 1.1
diff -u -r1.1 CMemoryManager.java
--- src/org/eclipse/cdt/debug/internal/core/CMemoryManager.java 15 Oct 2002 21:42:17 -0000 1.1
+++ src/org/eclipse/cdt/debug/internal/core/CMemoryManager.java 17 Oct 2002 23:11:17 -0000
@@ -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 @@
  */
 public class CMemoryManager implements ICMemoryManager
 {
- private List fBlocks;
+ private IFormattedMemoryBlock[] fBlocks = new IFormattedMemoryBlock[4];
  private CDebugTarget fDebugTarget;
 
  /**
@@ -29,45 +28,43 @@
   */
  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)
@@ -102,5 +99,39 @@
  
  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];
  }
 }
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.1
diff -u -r1.1 CFormattedMemoryBlock.java
--- src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java 15 Oct 2002 21:42:17 -0000 1.1
+++ src/org/eclipse/cdt/debug/internal/core/model/CFormattedMemoryBlock.java 17 Oct 2002 23:11:17 -0000
@@ -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 @@
  */
 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 CFormattedMemoryBlock( CDebugTarget target,
           ICDIMemoryBlock cdiMemoryBlock,
+          String addressExpression,
           int format,
             int wordSize,
             int numberOfRows,
@@ -38,6 +87,7 @@
  {
   super( target );
   fCDIMemoryBlock = cdiMemoryBlock;
+  fAddressExpression = addressExpression;
   fFormat = format;
   fWordSize = wordSize;
   fNumberOfRows = numberOfRows;
@@ -52,6 +102,7 @@
   */
  public CFormattedMemoryBlock( CDebugTarget target,
           ICDIMemoryBlock cdiMemoryBlock,
+          String addressExpression,
           int format,
             int wordSize,
             int numberOfRows,
@@ -60,12 +111,13 @@
  {
   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 int getFormat()
  {
-  return 0;
+  return fFormat;
  }
 
  /* (non-Javadoc)
@@ -81,7 +133,7 @@
   */
  public int getWordSize()
  {
-  return 0;
+  return fWordSize;
  }
 
  /* (non-Javadoc)
@@ -89,7 +141,7 @@
   */
  public int getNumberOfRows()
  {
-  return 0;
+  return fNumberOfRows;
  }
 
  /* (non-Javadoc)
@@ -97,7 +149,7 @@
   */
  public int getNumberOfColumns()
  {
-  return 0;
+  return fNumberOfColumns;
  }
 
  /* (non-Javadoc)
@@ -105,7 +157,7 @@
   */
  public boolean displayASCII()
  {
-  return false;
+  return fDisplayAscii;
  }
 
  /* (non-Javadoc)
@@ -113,7 +165,28 @@
   */
  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 long getStartAddress()
  {
+  if ( fCDIMemoryBlock != null )
+  {
+   return fCDIMemoryBlock.getStartAddress();
+  }
   return 0;
  }
 
@@ -182,6 +259,10 @@
   */
  public long getLength()
  {
+  if ( fCDIMemoryBlock != null )
+  {
+   return fCDIMemoryBlock.getLength();
+  }
   return 0;
  }
 
@@ -190,7 +271,18 @@
   */
  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 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 = "" 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();
+ }
 }
 
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/ChangeLog,v
retrieving revision 1.4
diff -u -r1.4 ChangeLog
--- ChangeLog 15 Oct 2002 21:36:03 -0000 1.4
+++ ChangeLog 17 Oct 2002 23:15:47 -0000
@@ -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.
Index: src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java,v
retrieving revision 1.4
diff -u -r1.4 MemoryControlArea.java
--- src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java 15 Oct 2002 21:36:03 -0000 1.4
+++ src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryControlArea.java 17 Oct 2002 23:15:48 -0000
@@ -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 @@
 {
  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 @@
             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 @@
 
  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 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 @@
   }
  }
 */
+
+ 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 );
+ }
 }
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.1
diff -u -r1.1 MemoryPresentation.java
--- src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java 6 Aug 2002 19:00:46 -0000 1.1
+++ src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryPresentation.java 17 Oct 2002 23:15:48 -0000
@@ -63,7 +63,7 @@
  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 )
   {
@@ -111,6 +111,11 @@
  public String getStartAddress()
  {
   return ( fBlock != null ) ? getAddressString( fBlock.getStartAddress() ) : "";
+ }
+
+ public String getAddressExpression()
+ {
+  return ( fBlock != null ) ? fBlock.getAddressExpression() : "";
  }
 
  private String getInterval( int length )
Index: src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java,v
retrieving revision 1.3
diff -u -r1.3 MemoryView.java
--- src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java 16 Sep 2002 21:32:14 -0000 1.3
+++ src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryView.java 17 Oct 2002 23:15:48 -0000
@@ -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.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 @@
   */
  protected void createActions()
  {
+  // set initial content here, as viewer has to be set
+  setInitialContent();
  }
 
  /* (non-Javadoc)
@@ -94,6 +96,10 @@
   */
  public void selectionChanged( IWorkbenchPart part, ISelection selection )
  {
+  if ( selection instanceof IStructuredSelection )
+  {
+   setViewerInput( (IStructuredSelection)selection );
+  }
  }
 
  /* (non-Javadoc)
@@ -126,28 +132,23 @@
 
  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 @@
  {
   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 );
+  }
+ }
 }
Index: src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java,v
retrieving revision 1.2
diff -u -r1.2 MemoryViewer.java
--- src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java 8 Oct 2002 20:35:59 -0000 1.2
+++ src/org/eclipse/cdt/debug/internal/ui/views/memory/MemoryViewer.java 17 Oct 2002 23:15:47 -0000
@@ -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 @@
     tabItem.setControl( fMemoryControlAreas[i] );   
    }
    fTabFolder.setSelection( 0 );    
-  }  
+  }
   return fControl;
  }
 
@@ -100,10 +100,7 @@
  
  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 );
  }
 }


Back to the top