From cf5df1e48f5b77c48089345334b7da81d9b28061 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Mon, 8 Nov 2004 18:14:53 +0000 Subject: [PATCH] 2004-11-08 Alain Magloire Implement new Interface ICDIFunctionFinished. It returns the return value of the function. * cdi/org/eclipse/cdt/debug/mi/core/cdi/FunctionFinished.java * cdi/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java * mi/org/eclipse/cdt/debug/mi/core/event/MIFuncitonFinishedEvent.java --- debug/org.eclipse.cdt.debug.mi.core/ChangeLog | 7 ++ .../debug/mi/core/cdi/FunctionFinished.java | 73 +++++++++++++++++++ .../debug/mi/core/cdi/VariableManager.java | 33 +++++++-- .../mi/core/cdi/event/SuspendedEvent.java | 3 +- .../mi/core/cdi/model/type/VoidType.java | 3 + .../mi/core/cdi/model/type/VoidValue.java | 28 +++++++ .../cdt/debug/mi/core/CLIProcessor.java | 13 +++- .../cdt/debug/mi/core/SessionProcess.java | 4 +- .../core/event/MIFunctionFinishedEvent.java | 8 ++ 9 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/FunctionFinished.java create mode 100644 debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/VoidValue.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index 2e39a32fe0d..84bbef9b18f 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,10 @@ +2004-11-08 Alain Magloire + Implement new Interface ICDIFunctionFinished. + It returns the return value of the function. + * cdi/org/eclipse/cdt/debug/mi/core/cdi/FunctionFinished.java + * cdi/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java + * mi/org/eclipse/cdt/debug/mi/core/event/MIFuncitonFinishedEvent.java + 2004-11-07 Alain Magloire Support for MIInterpreterExec diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/FunctionFinished.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/FunctionFinished.java new file mode 100644 index 00000000000..e39c40370aa --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/FunctionFinished.java @@ -0,0 +1,73 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.debug.mi.core.cdi; + +import org.eclipse.cdt.debug.core.cdi.CDIException; +import org.eclipse.cdt.debug.core.cdi.ICDIFunctionFinished; +import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; +import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType; +import org.eclipse.cdt.debug.mi.core.cdi.model.LocalVariableDescriptor; +import org.eclipse.cdt.debug.mi.core.cdi.model.StackFrame; +import org.eclipse.cdt.debug.mi.core.cdi.model.Target; +import org.eclipse.cdt.debug.mi.core.cdi.model.Thread; +import org.eclipse.cdt.debug.mi.core.cdi.model.Variable; +import org.eclipse.cdt.debug.mi.core.event.MIFunctionFinishedEvent; + +/* + * FunctionFinished + */ +public class FunctionFinished extends EndSteppingRange implements ICDIFunctionFinished { + + MIFunctionFinishedEvent fMIEvent; + + /** + * @param session + */ + public FunctionFinished(Session session, MIFunctionFinishedEvent event) { + super(session); + fMIEvent = event; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.ICDIFunctionFinished#getReturnType() + */ + public ICDIType getReturnType() throws CDIException { + Session session = (Session)getSession(); + Target target = session.getTarget(fMIEvent.getMISession()); + Thread thread = (Thread)target.getCurrentThread(); + StackFrame frame = thread.getCurrentStackFrame(); + String rType = fMIEvent.getReturnType(); + if (rType == null || rType.length() == 0) { + throw new CDIException(CdiResources.getString("cdi.VariableManager.Unknown_type")); //$NON-NLS-1$ + } + SourceManager srcMgr = session.getSourceManager(); + return srcMgr.getType(frame, rType); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.cdi.ICDIFunctionFinished#getReturnValue() + */ + public ICDIValue getReturnValue() throws CDIException { + Session session = (Session)getSession(); + Target target = session.getTarget(fMIEvent.getMISession()); + Thread thread = (Thread)target.getCurrentThread(); + StackFrame frame = thread.getCurrentStackFrame(); + String gdbVariable = fMIEvent.getGDBResultVar(); + if (gdbVariable == null || gdbVariable.length() == 0) { + throw new CDIException(CdiResources.getString("cdi.VariableManager.Unknown_type")); //$NON-NLS-1$ + } + LocalVariableDescriptor varDesc = new LocalVariableDescriptor(target, thread, frame, gdbVariable, null, 0, 0); + VariableManager varMgr = session.getVariableManager(); + Variable var = varMgr.createVariable(varDesc); + return var.getValue(); + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java index bb922188919..324deb7bc80 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/VariableManager.java @@ -95,6 +95,10 @@ public class VariableManager extends Manager { Target target = ((Session)getSession()).getTarget(miSession); return getVariable(target, varName); } + /** + * Return the element that have the uniq varName. + * null is return if the element is not in the cache. + */ public Variable getVariable(Target target, String varName) { Variable[] vars = getVariables(target); for (int i = 0; i < vars.length; i++) { @@ -163,7 +167,6 @@ public class VariableManager extends Manager { */ public void checkType(StackFrame frame, String type) throws CDIException { if (type != null && type.length() > 0) { - Session session = (Session)getSession(); Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); @@ -203,6 +206,12 @@ public class VariableManager extends Manager { } } + /** + * Remove variable form the maintained cache list. + * @param miSession + * @param varName + * @return + */ public Variable removeVariableFromList(MISession miSession, String varName) { Target target = ((Session)getSession()).getTarget(miSession); List varList = getVariablesList(target); @@ -218,6 +227,14 @@ public class VariableManager extends Manager { return null; } + /** + * Encode the variableDescriptor as an array + * @param varDesc + * @param start + * @param length + * @return + * @throws CDIException + */ public VariableDescriptor getVariableDescriptorAsArray(VariableDescriptor varDesc, int start, int length) throws CDIException { Target target = (Target)varDesc.getTarget(); @@ -248,6 +265,13 @@ public class VariableManager extends Manager { return vo; } + /** + * Encode the variableDescriptor in a typecasting. + * @param varDesc + * @param type + * @return + * @throws CDIException + */ public VariableDescriptor getVariableDescriptorAsType(VariableDescriptor varDesc, String type) throws CDIException { // throw an exception if not a good type. Target target = (Target)varDesc.getTarget(); @@ -301,7 +325,7 @@ public class VariableManager extends Manager { return vo; } - public ICDIVariable createVariable(VariableDescriptor varDesc) throws CDIException { + public Variable createVariable(VariableDescriptor varDesc) throws CDIException { if (varDesc instanceof ArgumentDescriptor) { return createArgument((ArgumentDescriptor)varDesc); } else if (varDesc instanceof LocalVariableDescriptor) { @@ -326,7 +350,6 @@ public class VariableManager extends Manager { if (argument == null) { String name = argDesc.getQualifiedName(); StackFrame stack = (StackFrame)argDesc.getStackFrame(); - Session session = (Session) getSession(); Target target = (Target)argDesc.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); @@ -356,7 +379,6 @@ public class VariableManager extends Manager { public ICDIArgumentDescriptor[] getArgumentDescriptors(StackFrame frame) throws CDIException { List argObjects = new ArrayList(); - Session session = (Session) getSession(); Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); @@ -424,7 +446,6 @@ public class VariableManager extends Manager { } if (global == null) { String name = varDesc.getQualifiedName(); - Session session = (Session) getSession(); Target target = (Target)varDesc.getTarget(); try { MISession mi = target.getMISession(); @@ -447,7 +468,6 @@ public class VariableManager extends Manager { public ICDILocalVariableDescriptor[] getLocalVariableDescriptors(StackFrame frame) throws CDIException { List varObjects = new ArrayList(); - Session session = (Session) getSession(); Target target = (Target)frame.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); StackFrame currentFrame = currentThread.getCurrentStackFrame(); @@ -488,7 +508,6 @@ public class VariableManager extends Manager { } if (local == null) { String name = varDesc.getQualifiedName(); - Session session = (Session) getSession(); StackFrame stack = (StackFrame)varDesc.getStackFrame(); Target target = (Target)varDesc.getTarget(); Thread currentThread = (Thread)target.getCurrentThread(); diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java index ac2802bba0d..f8471b7a4e1 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/event/SuspendedEvent.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIObject; import org.eclipse.cdt.debug.mi.core.cdi.BreakpointHit; import org.eclipse.cdt.debug.mi.core.cdi.EndSteppingRange; import org.eclipse.cdt.debug.mi.core.cdi.ErrorInfo; +import org.eclipse.cdt.debug.mi.core.cdi.FunctionFinished; import org.eclipse.cdt.debug.mi.core.cdi.Session; import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryEvent; import org.eclipse.cdt.debug.mi.core.cdi.SignalReceived; @@ -60,7 +61,7 @@ public class SuspendedEvent implements ICDISuspendedEvent { } else if (event instanceof MILocationReachedEvent) { return new EndSteppingRange(session); } else if (event instanceof MIFunctionFinishedEvent) { - return new EndSteppingRange(session); + return new FunctionFinished(session, (MIFunctionFinishedEvent)event); } else if (event instanceof MIErrorEvent) { return new ErrorInfo(session, (MIErrorEvent)event); } else if (event instanceof MISharedLibEvent) { diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/VoidType.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/VoidType.java index 54b87abae06..71b6a1aa807 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/VoidType.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/VoidType.java @@ -18,6 +18,9 @@ import org.eclipse.cdt.debug.mi.core.cdi.model.StackFrame; */ public class VoidType extends Type implements ICDIVoidType { + public VoidType(StackFrame frame) { + this(frame, "void"); //$NON-NLS-1$ + } public VoidType(StackFrame frame, String typename) { super(frame, typename); } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/VoidValue.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/VoidValue.java new file mode 100644 index 00000000000..c5c10dbf81a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/model/type/VoidValue.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2002,2003,2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.debug.mi.core.cdi.model.type; + +import org.eclipse.cdt.debug.mi.core.cdi.model.Value; +import org.eclipse.cdt.debug.mi.core.cdi.model.Variable; + +/* + * VoidValue + */ +public class VoidValue extends Value { + + /** + * @param v + */ + public VoidValue(Variable v) { + super(v); + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/CLIProcessor.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/CLIProcessor.java index 5d9e2de9a61..23d9628b3e7 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/CLIProcessor.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/CLIProcessor.java @@ -82,7 +82,7 @@ public class CLIProcessor { } } - int getSteppingOperationKind(String operation) { + static int getSteppingOperationKind(String operation) { int type = -1; /* execution commands: n, next, s, step, si, stepi, u, until, finish, c, continue, fg */ @@ -112,6 +112,17 @@ public class CLIProcessor { return type; } + /** + * Return true if the operation is a stepping operation. + * + * @param operation + * @return + */ + public static boolean isSteppingOperation(String operation) { + int type = getSteppingOperationKind(operation); + return type != -1; + } + boolean isSettingBreakpoint(String operation) { boolean isbreak = false; /* breakpoints: b, break, hbreak, tbreak, rbreak, thbreak */ diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java index 27b77417dc0..437944758b5 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java @@ -78,7 +78,9 @@ public class SessionProcess extends Process { String str = buf.toString().trim(); buf.setLength(0); Command cmd = null; - if (session.useExecConsole() && str.length() > 0) { + // Do not use the interpreterexec for stepping operation + // the UI will fall out of step. + if (session.useExecConsole() && str.length() > 0 && !CLIProcessor.isSteppingOperation(str)) { cmd = new MIInterpreterExecConsole(str); } else { cmd = new CLICommand(str); diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/event/MIFunctionFinishedEvent.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/event/MIFunctionFinishedEvent.java index 0f8d7ed6c16..8e6adbba131 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/event/MIFunctionFinishedEvent.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/event/MIFunctionFinishedEvent.java @@ -26,6 +26,7 @@ public class MIFunctionFinishedEvent extends MIStoppedEvent { String gdbResult = ""; //$NON-NLS-1$ String returnValue = ""; //$NON-NLS-1$ + String returnType = ""; //$NON-NLS-1$ public MIFunctionFinishedEvent(MISession source, MIExecAsyncOutput async) { super(source, async); @@ -45,10 +46,15 @@ public class MIFunctionFinishedEvent extends MIStoppedEvent { return returnValue; } + public String getReturnType() { + return returnType; + } + public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("gdb-result-var=" + gdbResult + "\n"); //$NON-NLS-1$//$NON-NLS-2$ buffer.append("return-value=" + returnValue + "\n"); //$NON-NLS-1$//$NON-NLS-2$ + buffer.append("return-type=" + returnType + "\n"); //$NON-NLS-1$//$NON-NLS-2$ buffer.append("thread-id=").append(getThreadId()).append('\n'); //$NON-NLS-1$ MIFrame f = getFrame(); if (f != null) { @@ -80,6 +86,8 @@ public class MIFunctionFinishedEvent extends MIStoppedEvent { gdbResult = str; } else if (var.equals("return-value")) { //$NON-NLS-1$ returnValue = str; + } else if (var.equals("return-type")) { //$NON-NLS-1$ + returnType = str; } else if (var.equals("thread-id")) { //$NON-NLS-1$ try { int id = Integer.parseInt(str.trim());