diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIExpressions.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIExpressions.java index 052fe764c3b..05d2439f69c 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIExpressions.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIExpressions.java @@ -325,7 +325,17 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3, // which refers to the full name, including parent structure. private final String relativeExpression; private final String exprType; - private final int numChildren; + + /** + * A hint at the number of children. + * In the case of C++ complex structures, this number will not be the + * actual number of children. This is because GDB considers + * 'private/protected/public' as an actual level of children, but + * we do not. This number is meant to be used to know if the expression + * has children at all. + */ + private final int numChildrenHint; + private final boolean editable; private final BasicType fBasicType; @@ -343,7 +353,7 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3, public ExpressionDMData(String expr, String type, int num, boolean edit, BasicType basicType) { relativeExpression = expr; exprType = type; - numChildren = num; + numChildrenHint = num; editable = edit; fBasicType = basicType; } @@ -381,8 +391,25 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3, return exprType; } + /** + * This method only returns a 'hint' to the number of children. + * In the case of C++ complex structures, this number will not be the + * actual number of children. This is because GDB considers + * 'private/protected/public' as an actual level of children, but + * we do not. + * + * This method can be used reliably to know if the expression + * does have children or not. However, for this particular use, + * the new {@link IExpressionDMDataExtension#hasChildren()} method should be used instead. + * + * To get the correct number of children of an expression, a call + * to {@link IExpressions#getSubExpressionCount} should be used. + * + * @deprecated + */ + @Deprecated public int getNumChildren() { - return numChildren; + return numChildrenHint; } public boolean isEditable() { @@ -393,14 +420,14 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3, * @since 3.1 */ public boolean hasChildren() { - return getNumChildren() > 0; + return numChildrenHint > 0; } @Override public boolean equals(Object other) { if (other instanceof ExpressionDMData) { ExpressionDMData otherData = (ExpressionDMData) other; - return (getNumChildren() == otherData.getNumChildren()) && + return (numChildrenHint == otherData.numChildrenHint) && (getTypeName() == null ? otherData.getTypeName() == null : getTypeName().equals(otherData.getTypeName())) && (getName() == null ? otherData.getName() == null : getName().equals(otherData.getName())); } @@ -410,12 +437,12 @@ public class MIExpressions extends AbstractDsfService implements IExpressions3, @Override public int hashCode() { return relativeExpression == null ? 0 : relativeExpression.hashCode() + - exprType == null ? 0 : exprType.hashCode() + numChildren; + exprType == null ? 0 : exprType.hashCode() + numChildrenHint; } @Override public String toString() { - return "relExpr=" + relativeExpression + ", type=" + exprType + ", numchildren=" + numChildren; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ + return "relExpr=" + relativeExpression + ", type=" + exprType + ", numchildren=" + numChildrenHint; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIVariableManager.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIVariableManager.java index 002f0210b40..68cad5a05c7 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIVariableManager.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIVariableManager.java @@ -1655,6 +1655,9 @@ public class MIVariableManager implements ICommandControl { drm.setData( new ExprMetaGetVarInfo( exprCtx.getRelativeExpression(), + // We only provide the hint here. It will be used for hasChildren() + // To obtain the correct number of children, the user should use + // IExpressions#getSubExpressionCount() getData().getNumChildrenHint(), getData().getType(), getData().getGDBType(), diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/ClassAccessor.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/ClassAccessor.java index b51fd9121f3..1cf70a3b3c6 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/ClassAccessor.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/ClassAccessor.java @@ -10,13 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service; -import java.util.Map; - import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; -import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMData; -import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMData.BasicType; -import org.eclipse.cdt.dsf.debug.service.IRegisters.IRegisterDMContext; -import org.eclipse.cdt.dsf.mi.service.MIExpressions.ExpressionDMData; import org.eclipse.cdt.dsf.mi.service.MIExpressions.MIExpressionDMC; public class ClassAccessor { @@ -51,69 +45,4 @@ public class ClassAccessor { return miExprDmc.getRelativeExpression(); } } - - public static class ExpressionDMDataAccessor { - private ExpressionDMData miExprData; - - public ExpressionDMDataAccessor(IExpressionDMData data) { - miExprData = (ExpressionDMData) data; - } - - public BasicType getBasicType() { - return miExprData.getBasicType(); - } - - public String getEncoding() { - return miExprData.getEncoding(); - } - - public Map getEnumerations() { - return miExprData.getEnumerations(); - } - - public String getName() { - return miExprData.getName(); - } - - public IRegisterDMContext getRegister() { - return miExprData.getRegister(); - } - - public String getStringValue() { - return miExprData.getStringValue(); - } - - public String getTypeId() { - return miExprData.getTypeId(); - } - - public String getTypeName() { - return miExprData.getTypeName(); - } - - public int getNumChildren() { - return miExprData.getNumChildren(); - } - - public boolean isEditable() { - return miExprData.isEditable(); - } - - @Override - public boolean equals(Object other) { - return miExprData.equals(other); - } - - @Override - public int hashCode() { - return miExprData.hashCode(); - - } - - @Override - public String toString() { - return miExprData.toString(); - - } - } } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java index 5959bb954af..f2ae924bb5a 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java @@ -22,18 +22,18 @@ import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.dsf.datamodel.IDMContext; import org.eclipse.cdt.dsf.debug.service.IExpressions; -import org.eclipse.cdt.dsf.debug.service.IFormattedValues; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionChangedDMEvent; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMData; +import org.eclipse.cdt.dsf.debug.service.IExpressions3.IExpressionDMDataExtension; +import org.eclipse.cdt.dsf.debug.service.IFormattedValues; import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext; import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData; import org.eclipse.cdt.dsf.debug.service.IRunControl.StepType; import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext; -import org.eclipse.cdt.dsf.mi.service.MIExpressions; -import org.eclipse.cdt.dsf.mi.service.ClassAccessor.ExpressionDMDataAccessor; import org.eclipse.cdt.dsf.mi.service.ClassAccessor.MIExpressionDMCAccessor; +import org.eclipse.cdt.dsf.mi.service.MIExpressions; import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent; import org.eclipse.cdt.dsf.service.DsfServiceEventHandler; import org.eclipse.cdt.dsf.service.DsfServicesTracker; @@ -341,13 +341,11 @@ public class MIExpressionsTest extends BaseTestCase { } /** - * This test makes sure we get the right number of children. + * This test makes sure we get can tell if an expression has children + * based on the expression data. */ @Test - public void testChildrenCountInExpressionData() throws Throwable { - // Next we test that we can retrieve children count while reading the - // value and vice-versa - + public void testHasChildrenInExpressionData() throws Throwable { SyncUtil.runToLocation("testChildren"); MIStoppedEvent stoppedEvent = SyncUtil.step(1, StepType.STEP_OVER); @@ -368,11 +366,18 @@ public class MIExpressionsTest extends BaseTestCase { if (!isSuccess()) { wait.waitFinished(getStatus()); } else { - ExpressionDMDataAccessor data = new ExpressionDMDataAccessor(getData()); - int count = data.getNumChildren(); - if (count != 5) { + if ((getData() instanceof IExpressionDMDataExtension) == false) { wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, - "Failed getting count for children. Got " + count + " instead of 5", null)); + "Did not a receive an IExpressionDMDataExtension", null)); + return; + } + + IExpressionDMDataExtension data = (IExpressionDMDataExtension)getData(); + + boolean hasChildren = data.hasChildren(); + if (!hasChildren) { + wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, + "No children were found, when we expected to find some", null)); } else { wait.waitFinished(); }