From 59129f335e9acbabffeaefdccfb6b59d5e4908f4 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Mon, 16 Feb 2009 20:05:24 +0000 Subject: [PATCH] [225921] Prevent a step-return for GDB when in main() --- .../cdt/dsf/gdb/service/GDBRunControl.java | 41 +++++++++++++++++++ .../dsf/gdb/service/GDBRunControl_7_0.java | 41 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl.java index 609940e1207..9cbd4bfac21 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl.java @@ -30,6 +30,7 @@ import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.mi.service.IMIExecutionDMContext; import org.eclipse.cdt.dsf.mi.service.IMIProcesses; import org.eclipse.cdt.dsf.mi.service.MIRunControl; +import org.eclipse.cdt.dsf.mi.service.MIStack; import org.eclipse.cdt.dsf.mi.service.command.events.MIEvent; import org.eclipse.cdt.dsf.mi.service.command.events.MIThreadExitEvent; import org.eclipse.cdt.dsf.service.DsfSession; @@ -150,5 +151,45 @@ public class GDBRunControl extends MIRunControl { } } + @Override + public void canStep(final IExecutionDMContext context, StepType stepType, final DataRequestMonitor rm) { + if (context instanceof IContainerDMContext) { + rm.setData(false); + rm.done(); + return; + } + + if (stepType == StepType.STEP_RETURN) { + // A step return will always be done in the top stack frame. + // If the top stack frame is the only stack frame, it does not make sense + // to do a step return since GDB will reject it. + + // Until bug 256798 is fixed, the service tracker could be null + if (getServicesTracker() == null) { + // service is shutdown + rm.setData(false); + rm.done(); + return; + } + MIStack stackService = getServicesTracker().getService(MIStack.class); + if (stackService != null) { + // Check that the stack is at least two deep. + stackService.getStackDepth(context, 2, new DataRequestMonitor(getExecutor(), rm) { + @Override + public void handleCompleted() { + if (isSuccess() && getData() == 1) { + rm.setData(false); + rm.done(); + } else { + canResume(context, rm); + } + } + }); + return; + } + } + + canResume(context, rm); + } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java index aedfbaf8455..42720207982 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBRunControl_7_0.java @@ -131,6 +131,47 @@ public class GDBRunControl_7_0 extends MIRunControl implements IReverseRunContro }); } + @Override + public void canStep(final IExecutionDMContext context, StepType stepType, final DataRequestMonitor rm) { + if (context instanceof IContainerDMContext) { + rm.setData(false); + rm.done(); + return; + } + + if (stepType == StepType.STEP_RETURN) { + // A step return will always be done in the top stack frame. + // If the top stack frame is the only stack frame, it does not make sense + // to do a step return since GDB will reject it. + + // Until bug 256798 is fixed, the service tracker could be null + if (getServicesTracker() == null) { + // service is shutdown + rm.setData(false); + rm.done(); + return; + } + MIStack stackService = getServicesTracker().getService(MIStack.class); + if (stackService != null) { + // Check that the stack is at least two deep. + stackService.getStackDepth(context, 2, new DataRequestMonitor(getExecutor(), rm) { + @Override + public void handleCompleted() { + if (isSuccess() && getData() == 1) { + rm.setData(false); + rm.done(); + } else { + canResume(context, rm); + } + } + }); + return; + } + } + + canResume(context, rm); + } + /** @since 2.0 */ public void canReverseResume(IExecutionDMContext context, DataRequestMonitor rm) { rm.setData(fReverseModeEnabled && doCanResume(context));