From 99dd5a34ae60056d1b684c986ba4975c3fb04782 Mon Sep 17 00:00:00 2001 From: John Cortell Date: Mon, 3 May 2010 18:56:21 +0000 Subject: [PATCH] Bug 311380: Interrupting target can leave Debug view in awkward state --- .../eclipse/cdt/dsf/mi/service/MIStack.java | 47 +++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIStack.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIStack.java index ac72a824096..10063701ca9 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIStack.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIStack.java @@ -363,7 +363,7 @@ public class MIStack extends AbstractDsfService final MIFrameDMC miFrameDmc = (MIFrameDMC)frameDmc; - IMIExecutionDMContext execDmc = DMContexts.getAncestorOfType(frameDmc, IMIExecutionDMContext.class); + final IMIExecutionDMContext execDmc = DMContexts.getAncestorOfType(frameDmc, IMIExecutionDMContext.class); if (execDmc == null) { rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INVALID_HANDLE, "No execution context found in " + frameDmc, null)); //$NON-NLS-1$ rm.done(); @@ -453,6 +453,36 @@ public class MIStack extends AbstractDsfService rm.setData(new FrameDataFromMIStackFrameListInfo(getData(), idx)); rm.done(); } + + @Override + protected void handleError() { + // We're seeing gdb in some cases fail when it's + // being asked for the stack depth or stack + // frames, but the same command succeeds if + // the request is limited to one frame. So try + // again with a limit of 1. It's better to show + // just one frame than none at all + if (miFrameDmc.fLevel == 0) { + fMICommandCache.execute( + fCommandFactory.createMIStackListFrames(execDmc, 0, 0), + new DataRequestMonitor(getExecutor(), rm) { + @Override + protected void handleSuccess() { + // Find the index to the correct MI frame object. + int idx = findFrameIndex(getData().getMIFrames(), miFrameDmc.fLevel); + if (idx == -1) { + rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INVALID_HANDLE, "Invalid frame " + frameDmc, null)); //$NON-NLS-1$ + rm.done(); + return; + } + + // Create the data object. + rm.setData(new FrameDataFromMIStackFrameListInfo(getData(), idx)); + rm.done(); + } + }); + } + } }); } @@ -857,7 +887,7 @@ public class MIStack extends AbstractDsfService }); } - public void getStackDepth(IDMContext dmc, final int maxDepth, final DataRequestMonitor rm) { + public void getStackDepth(final IDMContext dmc, final int maxDepth, final DataRequestMonitor rm) { final IMIExecutionDMContext execDmc = DMContexts.getAncestorOfType(dmc, IMIExecutionDMContext.class); if (execDmc != null) { // Make sure the thread is stopped @@ -909,7 +939,18 @@ public class MIStack extends AbstractDsfService rm.setData(1); rm.done(); } else { - super.handleError(); + // We're seeing gdb in some cases fail when it's + // being asked for the stack depth or stack + // frames, but the same command succeeds if + // the request is limited to one frame. So try + // again with a limit of 1. It's better to show + // just one frame than none at all + if (maxDepth != 1) { + getStackDepth(dmc, 1, rm); + } + else { + super.handleError(); + } } } });