1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-21 07:55:24 +02:00

Bug 432254 - Add memory monitor does not check for address out of range

Change-Id: I5fee242d73f8e24ac7dfb637bb79b49f6988cd69
Signed-off-by: Teodor Madan <teodor.madan@freescale.com>
Reviewed-on: https://git.eclipse.org/r/24627
Tested-by: Hudson CI
This commit is contained in:
Teodor Madan 2014-04-08 14:12:21 +03:00
parent 48298d3923
commit 882369b295
3 changed files with 24 additions and 1 deletions

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryDMContext;
import org.eclipse.cdt.dsf.debug.service.IMemorySpaces;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.cdt.dsf.gdb.internal.memory.GdbMemoryBlock.MemorySpaceDMContext;
import org.eclipse.cdt.dsf.gdb.service.IGDBMemory;
import org.eclipse.cdt.dsf.gdb.service.IGDBMemory2;
import org.eclipse.cdt.dsf.service.DsfServices;
import org.eclipse.cdt.dsf.service.DsfSession;
@ -49,6 +50,8 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.ibm.icu.text.MessageFormat;
/**
* A specialization of the DSF memory block retrieval implementation supporting
* memory spaces. The memory space support is provisional, thus this class is
@ -173,6 +176,14 @@ public class GdbMemoryBlockRetrieval extends DsfMemoryBlockRetrieval implements
}
}
// check for block address exceeding maximum allowed address value
int addressSize = getAddressSize(memoryDmc, memorySpaceID);
BigInteger endAddress = BigInteger.ONE.shiftLeft(addressSize*8).subtract(BigInteger.ONE);
if (endAddress.compareTo(blockAddress) < 0) {
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1,
MessageFormat.format(Messages.Err_ExceedsMaxAddress, expression, endAddress.toString(16)), null));
}
/*
* At this point, we only resolved the requested memory block
* start address and we have no idea of the block's length.
@ -403,6 +414,16 @@ public class GdbMemoryBlockRetrieval extends DsfMemoryBlockRetrieval implements
return super.getAddressableSize();
}
private int getAddressSize(IMemoryDMContext aContext, String memorySpaceID) {
IGDBMemory memoryService = (IGDBMemory)getServiceTracker().getService();
if (memoryService != null && aContext != null) {
IMemoryDMContext context = resolveMemSpaceContext(aContext, memorySpaceID);
return memoryService.getAddressSize(context);
}
return super.getAddressSize();
}
private IMemoryDMContext resolveMemSpaceContext(IMemoryDMContext aContext, String aMemorySpaceID) {
IMemoryDMContext context = aContext;
if (aMemorySpaceID != null && aMemorySpaceID.length() > 0) {

View file

@ -21,6 +21,7 @@ public class Messages extends NLS {
NLS.initializeMessages("org.eclipse.cdt.dsf.gdb.internal.memory.messages", Messages.class); //$NON-NLS-1$
}
public static String Err_ExceedsMaxAddress;
public static String Err_MemoryServiceNotAvailable;
public static String Err_MemoryReadFailed;
public static String Err_MemoryWriteFailed;

View file

@ -9,6 +9,7 @@
# Freescale Semiconductor - initial API and implementation
###############################################################################
Err_ExceedsMaxAddress=Expression value {0} exceeds maximum address 0x{1}
Err_MemoryServiceNotAvailable=The required DSF memory service is not available.
Err_MemoryReadFailed=Error reading memory block
Err_MemoryWriteFailed=Error writing memory block