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 9a592e0df5f..be77fa06dd1 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 @@ -1540,6 +1540,17 @@ public class MIVariableManager implements ICommandControl { else if (childVar.getRootToUpdate().isOutOfScope()) { childVar.deleteInGdb(); childVar = null; + } else { + childVar.hasCastToBaseClassWorkaround = childHasCastToBaseClassWorkaround; + if (fakeChild) { + // I don't think this should happen, but we put it just in case + addRealChildrenOfFake(childVar, exprDmc, realChildren, + arrayPosition, countingRm); + } else { + // This is a real child + realChildren[arrayPosition] = new ExpressionInfo[] { childVar.exprInfo }; + countingRm.done(); + } } } diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ExpressionTestApp.cc b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ExpressionTestApp.cc index c63193c5e51..8a4c0ee1673 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ExpressionTestApp.cc +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/data/launch/src/ExpressionTestApp.cc @@ -384,9 +384,15 @@ void testReturn() { testSimpleReturn(6); testComplexReturn(); - a = 0;; + a = 0; } - + +void testExistingChild() { + bar b; + int a = 10; + return; +} + int main() { printf("Running ExpressionTest App\n"); @@ -415,6 +421,7 @@ int main() { testRTTI(); testCasting(); testReturn(); + testExistingChild(); // For bug 320277 BaseTest b; b.test(); 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 eab5a0f1aaf..5e899771338 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 @@ -4104,6 +4104,80 @@ public class MIExpressionsTest extends BaseTestCase { assertEquals("b", result[0].getName()); } + /** + * This tests verifies that we can obtain a child even though + * is was already created directly. + */ + @Test + public void testExistingChild() throws Throwable { + SyncUtil.runToLocation("testExistingChild"); + MIStoppedEvent stoppedEvent = SyncUtil.step(1, StepType.STEP_OVER); + IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); + + final String PARENT_EXPR = "b"; + final String CHILD_EXPR = "((b).d)"; + + // Fetch the child directly + final IExpressionDMContext childDmc = SyncUtil.createExpression(frameDmc, CHILD_EXPR); + Query query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExpService.getFormattedExpressionValue( + fExpService.getFormattedValueContext(childDmc, IFormattedValues.NATURAL_FORMAT), + new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + rm.done(getData().getFormattedValue()); + } + }); + } + }; + + fSession.getExecutor().execute(query); + String value = query.get(500, TimeUnit.MILLISECONDS); + assertEquals("8", value); + + // Now fetch the child through its parent + final IExpressionDMContext parentDmc = SyncUtil.createExpression(frameDmc, PARENT_EXPR); + query = new Query() { + @Override + protected void execute(final DataRequestMonitor rm) { + fExpService.getSubExpressions( + parentDmc, + new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + if (getData().length != 2) { + rm.done(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, + "Wrong number for children. Expecting 2 but got " + getData().length, null)); + return; + } + + IExpressionDMContext firstChildContext = getData()[0]; + if (firstChildContext.getExpression().equals(CHILD_EXPR) == false) { + rm.done(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, + "Got wrong first child. Expected " + CHILD_EXPR + " but got " + firstChildContext.getExpression(), null)); + return; + } + fExpService.getFormattedExpressionValue( + fExpService.getFormattedValueContext(firstChildContext, IFormattedValues.NATURAL_FORMAT), + new ImmediateDataRequestMonitor(rm) { + @Override + protected void handleSuccess() { + rm.done(getData().getFormattedValue()); + } + }); + + } + }); + } + }; + + fSession.getExecutor().execute(query); + value = query.get(500, TimeUnit.MILLISECONDS); + assertEquals("8", value); + } + protected int getChildrenCount(final IExpressionDMContext parentDmc, final int expectedCount) throws Throwable { final AsyncCompletionWaitor wait = new AsyncCompletionWaitor();