mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
Monitor created with memory-space and address bypassed the address factory, thus allowing an out of range memory monitor to be created.
This commit is contained in:
parent
009b2c6396
commit
41132eeef2
1 changed files with 30 additions and 24 deletions
|
@ -31,7 +31,6 @@ import org.eclipse.cdt.debug.internal.core.model.CExpression;
|
||||||
import org.eclipse.cdt.debug.internal.core.model.CMemoryBlockExtension;
|
import org.eclipse.cdt.debug.internal.core.model.CMemoryBlockExtension;
|
||||||
import org.eclipse.cdt.debug.internal.core.model.CStackFrame;
|
import org.eclipse.cdt.debug.internal.core.model.CStackFrame;
|
||||||
import org.eclipse.cdt.debug.internal.core.model.CThread;
|
import org.eclipse.cdt.debug.internal.core.model.CThread;
|
||||||
import org.eclipse.cdt.internal.core.Messages;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
@ -136,6 +135,29 @@ public class CMemoryBlockRetrievalExtension extends PlatformObject implements IM
|
||||||
abort( InternalDebugCoreMessages.getString( "CMemoryBlockRetrievalExtension.3" ), null ); //$NON-NLS-1$
|
abort( InternalDebugCoreMessages.getString( "CMemoryBlockRetrievalExtension.3" ), null ); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a simple literal address (e.g., "0x1000") to a BigInteger value
|
||||||
|
* using the debug target's address factory.
|
||||||
|
*
|
||||||
|
* We throw a NumberFormatException if the string is not a valid literal
|
||||||
|
* address. If the backend implements the new&improved factory interface,
|
||||||
|
* we'll throw a NumberFormatException if the string is a literal address
|
||||||
|
* but is outside of the valid range. Old address factories will simply
|
||||||
|
* truncate the value.
|
||||||
|
*
|
||||||
|
* @param expression
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private BigInteger evaluateLiteralAddress(String addr) {
|
||||||
|
IAddressFactory addrFactory = getDebugTarget().getAddressFactory();
|
||||||
|
if (addrFactory instanceof IAddressFactory2) {
|
||||||
|
return ((IAddressFactory2)addrFactory).createAddress(addr, false).getValue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return addrFactory.createAddress(addr).getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createMemoryBlocks( String[] expressions, String[] memorySpaceIDs ) {
|
private void createMemoryBlocks( String[] expressions, String[] memorySpaceIDs ) {
|
||||||
ArrayList list = new ArrayList( expressions.length );
|
ArrayList list = new ArrayList( expressions.length );
|
||||||
for ( int i = 0; i < expressions.length; ++i ) {
|
for ( int i = 0; i < expressions.length; ++i ) {
|
||||||
|
@ -228,26 +250,11 @@ public class CMemoryBlockRetrievalExtension extends PlatformObject implements IM
|
||||||
|
|
||||||
// See if the expression is a simple numeric value; if it is, we can avoid some costly
|
// See if the expression is a simple numeric value; if it is, we can avoid some costly
|
||||||
// processing (calling the backend to resolve the expression)
|
// processing (calling the backend to resolve the expression)
|
||||||
// Use IAddressFactory2 if possible to ensure we abort if the address
|
|
||||||
// is outside the factory's valid range
|
|
||||||
try {
|
try {
|
||||||
IAddressFactory addrFactory = ((CDebugTarget)target).getAddressFactory();
|
return new CMemoryBlockExtension((CDebugTarget)target, expression, evaluateLiteralAddress(expression));
|
||||||
String hexstr = null;
|
} catch (NumberFormatException nfexc) {}
|
||||||
if (addrFactory instanceof IAddressFactory2) {
|
|
||||||
hexstr = ((IAddressFactory2)addrFactory).createAddress(expression, false).toString(16);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hexstr = addrFactory.createAddress(expression).toString(16);
|
|
||||||
}
|
|
||||||
return new CMemoryBlockExtension((CDebugTarget)target, expression, new BigInteger(hexstr, 16));
|
|
||||||
} catch (NumberFormatException nfexc) {
|
|
||||||
if (nfexc.getMessage().equals(Messages.Addr_valueOutOfRange)) {
|
|
||||||
throw nfexc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// OK, expression is not a simple, absolute numeric value; keep trucking and try to resolve as expression
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// OK, expression is not a simple literal address; keep trucking and try to resolve as expression
|
||||||
CStackFrame frame = getStackFrame( debugElement );
|
CStackFrame frame = getStackFrame( debugElement );
|
||||||
if ( frame != null ) {
|
if ( frame != null ) {
|
||||||
// We need to provide a better way for retrieving the address of expression
|
// We need to provide a better way for retrieving the address of expression
|
||||||
|
@ -278,7 +285,7 @@ public class CMemoryBlockRetrievalExtension extends PlatformObject implements IM
|
||||||
msg = e.getMessage();
|
msg = e.getMessage();
|
||||||
}
|
}
|
||||||
catch( NumberFormatException e ) {
|
catch( NumberFormatException e ) {
|
||||||
msg = MessageFormat.format( InternalDebugCoreMessages.getString( "CMemoryBlockRetrievalExtension.0" ), (Object[])new String[] { expression, address } ); //$NON-NLS-1$
|
msg = MessageFormat.format( InternalDebugCoreMessages.getString( "CMemoryBlockRetrievalExtension.0" ), (Object[])new String[] { expression } ); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (exp != null) {
|
if (exp != null) {
|
||||||
|
@ -327,8 +334,7 @@ public class CMemoryBlockRetrievalExtension extends PlatformObject implements IM
|
||||||
IDebugTarget target = debugElement.getDebugTarget();
|
IDebugTarget target = debugElement.getDebugTarget();
|
||||||
if ( target instanceof CDebugTarget ) {
|
if ( target instanceof CDebugTarget ) {
|
||||||
if ( address != null ) {
|
if ( address != null ) {
|
||||||
BigInteger addr = ( address.startsWith( "0x" ) ) ? new BigInteger( address.substring( 2 ), 16 ) : new BigInteger( address ); //$NON-NLS-1$
|
return new CMemoryBlockExtension((CDebugTarget)target, evaluateLiteralAddress(address), memorySpaceID);
|
||||||
return new CMemoryBlockExtension( (CDebugTarget)target, addr, memorySpaceID );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue