From 839905a802e6d6562b08cfb9ec5d0513764c1ccd Mon Sep 17 00:00:00 2001 From: Teodor Madan Date: Fri, 11 Apr 2014 15:01:32 +0300 Subject: [PATCH] Bug 432597 - GDB Memory services should report address size in octets Change-Id: Ifaa39b5fbd1237408cd38284682e1cb25345e6bc Signed-off-by: Teodor Madan Reviewed-on: https://git.eclipse.org/r/24849 Tested-by: Hudson CI Reviewed-by: Marc Khouzam --- .../eclipse/cdt/dsf/gdb/service/GDBMemory.java | 17 +++++++++++++++-- .../eclipse/cdt/dsf/gdb/service/IGDBMemory.java | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) 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);