diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory.java index 2039226e2a8..620ab12edef 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBMemory.java @@ -344,7 +344,17 @@ public class GDBMemory extends MIMemory implements IGDBMemory2 { return fIsBigEndian; } - protected void readAddressSize(IMemoryDMContext memContext, final DataRequestMonitor drm) { + /** + * Address size is determined by space, in octets, used to store an address value (e.g. a pointer) on a target system. + * + *

NOTE: Implementation requires addressable memory size to be known

+ * @param memContext + * @param drm + * + * @see IGDBMemory#getAddressSize(org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryDMContext) + * @see GDBMemory#readAddressableSize(org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryDMContext, DataRequestMonitor) + */ + protected void readAddressSize(final IMemoryDMContext memContext, final DataRequestMonitor drm) { IExpressions exprService = getServicesTracker().getService(IExpressions.class); IExpressionDMContext exprContext = exprService.createExpression(memContext, "sizeof (void*)"); //$NON-NLS-1$ CommandFactory commandFactory = fCommandControl.getCommandFactory(); @@ -354,7 +364,10 @@ public class GDBMemory extends MIMemory implements IGDBMemory2 { @Override protected void handleSuccess() { try { - drm.setData(Integer.decode(getData().getValue())); + // 'sizeof' returns number of bytes (aka 'chars'). + // Multiply with byte size in octets to get storage required to hold a pointer. + Integer ptrBytes = Integer.decode(getData().getValue()); + drm.setData(ptrBytes * getAddressableSize(memContext)); } catch(NumberFormatException e) { drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, String.format("Invalid address size: %s", getData().getValue()))); //$NON-NLS-1$ diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBMemory.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBMemory.java index e28107beed1..7f5aca6300f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBMemory.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/IGDBMemory.java @@ -27,7 +27,7 @@ public interface IGDBMemory extends IMemory { public void initializeMemoryData(IMemoryDMContext ctx, RequestMonitor rm); /** - * Returns the address size (in bytes) of the memory specified by the given context. + * Returns the address size (in octets) of the memory specified by the given context. */ public int getAddressSize(IMemoryDMContext context);