1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

Implementing the memory view support.

This commit is contained in:
Mikhail Khodjaiants 2002-10-17 23:17:02 +00:00
parent 0bd52b9a1d
commit f3214e2438
12 changed files with 467 additions and 67 deletions

View file

@ -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 2002-10-16 Alain Magloire
In the memory manager a string should be allowed to In the memory manager a string should be allowed to

View file

@ -294,7 +294,7 @@ public class CDebugModel
public static ICWatchpoint watchpointExists( IResource resource, boolean write, boolean read, String expression ) throws CoreException public static ICWatchpoint watchpointExists( IResource resource, boolean write, boolean read, String expression ) throws CoreException
{ {
String modelId = getPluginIdentifier(); String modelId = getPluginIdentifier();
String markerType = CWatchpoint.getMarkerType(); String markerType = CWatchpoint.getMarkerType();
IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
IBreakpoint[] breakpoints = manager.getBreakpoints( modelId ); IBreakpoint[] breakpoints = manager.getBreakpoints( modelId );
@ -359,7 +359,7 @@ public class CDebugModel
} }
public static IFormattedMemoryBlock createFormattedMemoryBlock( IDebugTarget target, public static IFormattedMemoryBlock createFormattedMemoryBlock( IDebugTarget target,
long startAddress, String startAddress,
int format, int format,
int wordSize, int wordSize,
int numberOfRows, int numberOfRows,
@ -375,6 +375,7 @@ public class CDebugModel
.createMemoryBlock( startAddress, wordSize * numberOfRows * numberOfColumns ); .createMemoryBlock( startAddress, wordSize * numberOfRows * numberOfColumns );
return new CFormattedMemoryBlock( (CDebugTarget)target, return new CFormattedMemoryBlock( (CDebugTarget)target,
cdiMemoryBlock, cdiMemoryBlock,
startAddress,
format, format,
wordSize, wordSize,
numberOfRows, numberOfRows,
@ -394,7 +395,7 @@ public class CDebugModel
} }
public static IFormattedMemoryBlock createFormattedMemoryBlock( IDebugTarget target, public static IFormattedMemoryBlock createFormattedMemoryBlock( IDebugTarget target,
long startAddress, String startAddress,
int format, int format,
int wordSize, int wordSize,
int numberOfRows, int numberOfRows,
@ -409,6 +410,7 @@ public class CDebugModel
.createMemoryBlock( startAddress, wordSize * numberOfRows * numberOfColumns ); .createMemoryBlock( startAddress, wordSize * numberOfRows * numberOfColumns );
return new CFormattedMemoryBlock( (CDebugTarget)target, return new CFormattedMemoryBlock( (CDebugTarget)target,
cdiMemoryBlock, cdiMemoryBlock,
startAddress,
format, format,
wordSize, wordSize,
numberOfRows, numberOfRows,

View file

@ -7,7 +7,6 @@ package org.eclipse.cdt.debug.core;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IMemoryBlock;
/** /**
* Enter type comment. * Enter type comment.
@ -16,13 +15,37 @@ import org.eclipse.debug.core.model.IMemoryBlock;
*/ */
public interface ICMemoryManager extends IAdaptable 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; void removeAllBlocks() throws DebugException;
IMemoryBlock getBlock( int index ); IFormattedMemoryBlock getBlock( int index );
IMemoryBlock[] getBlocks(); IFormattedMemoryBlock[] getBlocks();
} }

View file

@ -17,6 +17,13 @@ import org.eclipse.debug.core.model.IMemoryBlock;
*/ */
public interface IFormattedMemoryBlock extends 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. * Returns the format of the memory words of this block.
* *
@ -79,4 +86,5 @@ public interface IFormattedMemoryBlock extends IMemoryBlock
int numberOfRows, int numberOfRows,
int numberOfColumns, int numberOfColumns,
char paddingChar ) throws DebugException; char paddingChar ) throws DebugException;
void dispose();
} }

View file

@ -77,4 +77,31 @@ public class CDebugUtils
sb.append( addressString ); sb.append( addressString );
return sb.toString(); 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;
}
} }

View file

@ -5,14 +5,13 @@
*/ */
package org.eclipse.cdt.debug.internal.core; package org.eclipse.cdt.debug.internal.core;
import java.util.ArrayList; import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.debug.core.ICMemoryManager; 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.cdt.debug.internal.core.model.CDebugTarget;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IMemoryBlock;
/** /**
* Enter type comment. * Enter type comment.
@ -21,7 +20,7 @@ import org.eclipse.debug.core.model.IMemoryBlock;
*/ */
public class CMemoryManager implements ICMemoryManager public class CMemoryManager implements ICMemoryManager
{ {
private List fBlocks; private IFormattedMemoryBlock[] fBlocks = new IFormattedMemoryBlock[4];
private CDebugTarget fDebugTarget; private CDebugTarget fDebugTarget;
/** /**
@ -29,45 +28,43 @@ public class CMemoryManager implements ICMemoryManager
*/ */
public CMemoryManager( CDebugTarget target ) public CMemoryManager( CDebugTarget target )
{ {
fBlocks = new ArrayList( 4 ); Arrays.fill( fBlocks, null );
setDebugTarget( target ); setDebugTarget( target );
} }
/* (non-Javadoc) /* (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 public synchronized void removeBlock( IFormattedMemoryBlock memoryBlock ) throws DebugException
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICMemoryManager#removeBlock(IMemoryBlock)
*/
public void removeBlock( IMemoryBlock memoryBlock ) throws DebugException
{ {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICMemoryManager#removeAllBlocks() * @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) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICMemoryManager#getBlock(int) * @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) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICMemoryManager#getBlocks() * @see org.eclipse.cdt.debug.core.ICMemoryManager#getBlocks()
*/ */
public IMemoryBlock[] getBlocks() public IFormattedMemoryBlock[] getBlocks()
{ {
return null; return fBlocks;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -103,4 +100,38 @@ public class CMemoryManager implements ICMemoryManager
public void dispose() 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];
}
} }

View file

@ -5,9 +5,14 @@
*/ */
package org.eclipse.cdt.debug.internal.core.model; 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.IFormattedMemoryBlock;
import org.eclipse.cdt.debug.core.IFormattedMemoryBlockRow; 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.core.cdi.model.ICDIMemoryBlock;
import org.eclipse.cdt.debug.internal.core.CDebugUtils;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
/** /**
@ -17,13 +22,56 @@ import org.eclipse.debug.core.DebugException;
*/ */
public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMemoryBlock 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 ICDIMemoryBlock fCDIMemoryBlock;
private int fFormat; private int fFormat;
private int fWordSize; private int fWordSize;
private int fNumberOfRows; private int fNumberOfRows;
private int fNumberOfColumns; private int fNumberOfColumns;
private boolean fDisplayAscii = true; private boolean fDisplayAscii = true;
private char fPaddingChar = 0; private char fPaddingChar = '.';
private List fRows = null;
/** /**
* Constructor for CFormattedMemoryBlock. * Constructor for CFormattedMemoryBlock.
@ -31,6 +79,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public CFormattedMemoryBlock( CDebugTarget target, public CFormattedMemoryBlock( CDebugTarget target,
ICDIMemoryBlock cdiMemoryBlock, ICDIMemoryBlock cdiMemoryBlock,
String addressExpression,
int format, int format,
int wordSize, int wordSize,
int numberOfRows, int numberOfRows,
@ -38,6 +87,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
{ {
super( target ); super( target );
fCDIMemoryBlock = cdiMemoryBlock; fCDIMemoryBlock = cdiMemoryBlock;
fAddressExpression = addressExpression;
fFormat = format; fFormat = format;
fWordSize = wordSize; fWordSize = wordSize;
fNumberOfRows = numberOfRows; fNumberOfRows = numberOfRows;
@ -52,6 +102,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public CFormattedMemoryBlock( CDebugTarget target, public CFormattedMemoryBlock( CDebugTarget target,
ICDIMemoryBlock cdiMemoryBlock, ICDIMemoryBlock cdiMemoryBlock,
String addressExpression,
int format, int format,
int wordSize, int wordSize,
int numberOfRows, int numberOfRows,
@ -60,12 +111,13 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
{ {
super( target ); super( target );
fCDIMemoryBlock = cdiMemoryBlock; fCDIMemoryBlock = cdiMemoryBlock;
fAddressExpression = addressExpression;
fFormat = format; fFormat = format;
fWordSize = wordSize; fWordSize = wordSize;
fNumberOfRows = numberOfRows; fNumberOfRows = numberOfRows;
fNumberOfColumns = numberOfColumns; fNumberOfColumns = numberOfColumns;
fDisplayAscii = true; fDisplayAscii = true;
fPaddingChar = paddingChar; fPaddingChar = paddingChar;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -73,7 +125,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public int getFormat() public int getFormat()
{ {
return 0; return fFormat;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -81,7 +133,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public int getWordSize() public int getWordSize()
{ {
return 0; return fWordSize;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -89,7 +141,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public int getNumberOfRows() public int getNumberOfRows()
{ {
return 0; return fNumberOfRows;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -97,7 +149,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public int getNumberOfColumns() public int getNumberOfColumns()
{ {
return 0; return fNumberOfColumns;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -105,7 +157,7 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public boolean displayASCII() public boolean displayASCII()
{ {
return false; return fDisplayAscii;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -113,7 +165,28 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public IFormattedMemoryBlockRow[] getRows() 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) /* (non-Javadoc)
@ -174,6 +247,10 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public long getStartAddress() public long getStartAddress()
{ {
if ( fCDIMemoryBlock != null )
{
return fCDIMemoryBlock.getStartAddress();
}
return 0; return 0;
} }
@ -182,6 +259,10 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public long getLength() public long getLength()
{ {
if ( fCDIMemoryBlock != null )
{
return fCDIMemoryBlock.getLength();
}
return 0; return 0;
} }
@ -190,7 +271,18 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public byte[] getBytes() throws DebugException 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) /* (non-Javadoc)
@ -213,7 +305,51 @@ public class CFormattedMemoryBlock extends CDebugElement implements IFormattedMe
*/ */
public char getPaddingCharacter() 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();
}
} }

View file

@ -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 2002-10-15 Mikhail Khodjaiants
* CDebugUIPlugin.java: Moved the memory management functionality to the core. * CDebugUIPlugin.java: Moved the memory management functionality to the core.
* MemoryControlArea.java: Moved the memory management functionality to the core. * MemoryControlArea.java: Moved the memory management functionality to the core.

View file

@ -6,9 +6,13 @@
package org.eclipse.cdt.debug.internal.ui.views.memory; 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.IFormattedMemoryBlock;
import org.eclipse.cdt.debug.core.IFormattedMemoryRetrieval;
import org.eclipse.cdt.debug.internal.ui.preferences.ICDebugPreferenceConstants; 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.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyAdapter;
@ -29,11 +33,17 @@ public class MemoryControlArea extends Composite
{ {
private MemoryPresentation fPresentation; private MemoryPresentation fPresentation;
private int fIndex = 0; private int fIndex = 0;
private IFormattedMemoryRetrieval fInput = null; private ICMemoryManager fMemoryManager = null;
private IFormattedMemoryBlock fMemoryBlock = null;
private Text fAddressText; private Text fAddressText;
private MemoryText fMemoryText; 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. * Constructor for MemoryControlArea.
* @param parent * @param parent
@ -50,7 +60,7 @@ public class MemoryControlArea extends Composite
GridData.GRAB_VERTICAL ); GridData.GRAB_VERTICAL );
setLayout( layout ); setLayout( layout );
setLayoutData( gridData ); setLayoutData( gridData );
fIndex = index; setIndex( index );
fPresentation = createPresentation(); fPresentation = createPresentation();
fAddressText = createAddressText( this ); fAddressText = createAddressText( this );
fMemoryText = createMemoryText( this, style, fPresentation ); fMemoryText = createMemoryText( this, style, fPresentation );
@ -104,7 +114,23 @@ public class MemoryControlArea extends Composite
protected void handleAddressEnter() 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 ) 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; setMemoryManager( ( input instanceof ICMemoryManager ) ? (ICMemoryManager)input : null );
// fMemoryBlock = CDebugUIPlugin.getDefault().getBlock( fInput, fIndex ); getPresentation().setMemoryBlock( getMemoryBlock() );
fPresentation.setMemoryBlock( fMemoryBlock ); setAddressTextState();
refresh(); refresh();
} }
private void refresh() private void refresh()
{ {
fAddressText.setText( fPresentation.getStartAddress() ); fAddressText.setText( ( getPresentation() != null ) ? getPresentation().getAddressExpression() : "" );
fMemoryText.refresh(); 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 ) 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 );
}
} }

View file

@ -63,7 +63,7 @@ public class MemoryPresentation
public String getText() public String getText()
{ {
fAddressZones.clear(); fAddressZones.clear();
IFormattedMemoryBlockRow[] rows = fBlock.getRows(); IFormattedMemoryBlockRow[] rows = ( getMemoryBlock() != null ) ? getMemoryBlock().getRows() : new IFormattedMemoryBlockRow[0];
String text = new String(); String text = new String();
for ( int i = 0; i < rows.length; ++i ) for ( int i = 0; i < rows.length; ++i )
{ {
@ -113,6 +113,11 @@ public class MemoryPresentation
return ( fBlock != null ) ? getAddressString( fBlock.getStartAddress() ) : ""; return ( fBlock != null ) ? getAddressString( fBlock.getStartAddress() ) : "";
} }
public String getAddressExpression()
{
return ( fBlock != null ) ? fBlock.getAddressExpression() : "";
}
private String getInterval( int length ) private String getInterval( int length )
{ {
char[] chars = new char[length]; char[] chars = new char[length];

View file

@ -5,6 +5,7 @@
*/ */
package org.eclipse.cdt.debug.internal.ui.views.memory; 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.ICDebugHelpContextIds;
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler;
import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandlerView; 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.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IDebugElement; 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.IDebugModelPresentation;
import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
@ -64,6 +64,8 @@ public class MemoryView extends AbstractDebugEventHandlerView
*/ */
protected void createActions() protected void createActions()
{ {
// set initial content here, as viewer has to be set
setInitialContent();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -94,6 +96,10 @@ public class MemoryView extends AbstractDebugEventHandlerView
*/ */
public void selectionChanged( IWorkbenchPart part, ISelection selection ) public void selectionChanged( IWorkbenchPart part, ISelection selection )
{ {
if ( selection instanceof IStructuredSelection )
{
setViewerInput( (IStructuredSelection)selection );
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -126,28 +132,23 @@ public class MemoryView extends AbstractDebugEventHandlerView
protected void setViewerInput( IStructuredSelection ssel ) protected void setViewerInput( IStructuredSelection ssel )
{ {
IMemoryBlockRetrieval memoryBlockRetrieval = null; ICMemoryManager mm = null;
if ( ssel.size() == 1 ) if ( ssel != null && ssel.size() == 1 )
{ {
Object input = ssel.getFirstElement(); Object input = ssel.getFirstElement();
if ( input instanceof IDebugElement ) if ( input instanceof IDebugElement )
{ {
memoryBlockRetrieval = (IMemoryBlockRetrieval)((IDebugElement)input).getDebugTarget(); mm = (ICMemoryManager)((IDebugElement)input).getDebugTarget().getAdapter( ICMemoryManager.class );
} }
} }
Object current = getViewer().getInput(); Object current = getViewer().getInput();
if ( current == null && memoryBlockRetrieval == null ) if ( current != null && current.equals( mm ) )
{
return;
}
if ( current != null && current.equals( memoryBlockRetrieval ) )
{ {
return; return;
} }
showViewer(); showViewer();
getViewer().setInput( memoryBlockRetrieval ); getViewer().setInput( mm );
} }
private IContentProvider createContentProvider() private IContentProvider createContentProvider()
@ -174,4 +175,21 @@ public class MemoryView extends AbstractDebugEventHandlerView
{ {
return new MemoryViewEventHandler( this ); 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 );
}
}
} }

View file

@ -5,7 +5,7 @@
*/ */
package org.eclipse.cdt.debug.internal.ui.views.memory; 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.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ContentViewer; import org.eclipse.jface.viewers.ContentViewer;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
@ -64,7 +64,7 @@ public class MemoryViewer extends ContentViewer
tabItem.setControl( fMemoryControlAreas[i] ); tabItem.setControl( fMemoryControlAreas[i] );
} }
fTabFolder.setSelection( 0 ); fTabFolder.setSelection( 0 );
} }
return fControl; return fControl;
} }
@ -100,10 +100,7 @@ public class MemoryViewer extends ContentViewer
protected void inputChanged( Object input, Object oldInput ) protected void inputChanged( Object input, Object oldInput )
{ {
if ( input instanceof IFormattedMemoryRetrieval ) for ( int i = 0; i < fMemoryControlAreas.length; ++i )
{ fMemoryControlAreas[i].setInput( (ICMemoryManager)input );
for ( int i = 0; i < fMemoryControlAreas.length; ++i )
fMemoryControlAreas[i].setInput( (IFormattedMemoryRetrieval)input );
}
} }
} }