Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/mi/MISession.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/mi/MISession.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/mi/MISession.java	(revision 982)
@@ -437,5 +437,5 @@
 		if (gdbStackFrame != null) {
 			GDBThread gdbThread = (GDBThread) gdbStackFrame.getThread();
-			if (!gdbThread.getCurrentGDBStackFrame().equals(gdbStackFrame)) {
+			if (!gdbStackFrame.equals(gdbThread.getCurrentGDBStackFrame())) {
 				writeLog("not posting command");
 				return;
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/mi/command/CommandFactory.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/mi/command/CommandFactory.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/mi/command/CommandFactory.java	(revision 982)
@@ -199,5 +199,5 @@
 
 	/**
-	 * Creates the -stack-list-frame command with params
+	 * Creates the -stack-list-frames command with params
 	 * @param lowFrame
 	 * @param highFrame
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/GDBDebugTarget.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/GDBDebugTarget.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/GDBDebugTarget.java	(revision 982)
@@ -73,5 +73,4 @@
 import org.modelica.mdt.debug.gdb.core.mi.output.MIFrame;
 import org.modelica.mdt.debug.gdb.core.mi.output.MIInfo;
-import org.modelica.mdt.debug.gdb.core.model.stack.GDBStackFrame;
 import org.modelica.mdt.debug.gdb.core.model.thread.GDBThread;
 import org.modelica.mdt.debug.gdb.core.model.thread.GDBThread.ExecuteCommand;
@@ -94,5 +93,6 @@
 	// terminated state
 	private boolean fTerminated = false;
-	private ArrayList<GDBThread> fThreads;	
+	private ArrayList<GDBThread> fThreads;
+	final private Object fLock = new Object();
 	/**
 	 * Constructs a new debug target in the given launch for the associated GDB
@@ -616,8 +616,4 @@
 		if (MDTDebugCorePlugin.DEBUG) fMISession.writeLog("MIFunctionFinishedEvent caught in gdb debug target");
 		if (skipSteppedInFrames(miEvent)) {
-			GDBStackFrame gdbStackFrame = ((GDBThread)getThread()).getFrame(((MIFunctionFinishedEvent)miEvent).getFrame());
-			if (gdbStackFrame != null) {
-				((GDBThread)getThread()).setCurrentGDBStackFrame(gdbStackFrame);
-			}
 			((GDBThread)getThread()).setRefreshStackFrames(true);
 			((GDBThread)getThread()).suspended(DebugEvent.STEP_RETURN);
@@ -636,8 +632,4 @@
 		if (MDTDebugCorePlugin.DEBUG) fMISession.writeLog("MISteppingRangeEvent caught in gdb debug target");
 		if (skipSteppedInFrames(miEvent)) {
-			GDBStackFrame gdbStackFrame = ((GDBThread)getThread()).getFrame(((MISteppingRangeEvent)miEvent).getFrame());
-			if (gdbStackFrame != null) {
-				((GDBThread)getThread()).setCurrentGDBStackFrame(gdbStackFrame);
-			}
 			((GDBThread)getThread()).setRefreshStackFrames(true);
 			((GDBThread)getThread()).suspended(DebugEvent.STEP_END);
@@ -671,8 +663,4 @@
 			
 			if (signalEvent.getName().equals(GDBHelper.SIGTRAP) || signalEvent.getName().equals(GDBHelper.SIGINT)) {
-				GDBStackFrame gdbStackFrame = ((GDBThread)getThread()).getFrame((signalEvent.getFrame()));
-				if (gdbStackFrame != null) {
-					((GDBThread)getThread()).setCurrentGDBStackFrame(gdbStackFrame);
-				}
 				((GDBThread)getThread()).setRefreshStackFrames(true);
 				((GDBThread)getThread()).interrupted(DebugEvent.STEP_END);
@@ -744,4 +732,5 @@
 				execCmd = factory.createMIExecStep();
 			}
+			execCmd.setQuiet(true);
 			fMISession.postCommand(execCmd, null);
 			MIInfo info = execCmd.getMIInfo();
@@ -763,3 +752,10 @@
 		return fMISession;
 	}
+
+	/**
+	 * @return the fLock
+	 */
+	public Object getLock() {
+		return fLock;
+	}
 }
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/stack/GDBStackFrame.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/stack/GDBStackFrame.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/stack/GDBStackFrame.java	(revision 982)
@@ -205,9 +205,11 @@
 	 */
 	public IVariable[] getVariables() throws DebugException {
-		if (isDisposed() || !((GDBThread)getThread()).getCurrentGDBStackFrame().equals(this)) {
-			return new IVariable[0];
-		}
-		computeVariables();
-		return (IVariable[])fGDBVariables.toArray(new IVariable[fGDBVariables.size()]);
+		synchronized (getGDBDebugTarget().getLock()) {
+			if (isDisposed() || !(this.equals(((GDBThread)getThread()).getCurrentGDBStackFrame()))) {
+				return new IVariable[0];
+			}
+			computeVariables();
+			return (IVariable[])fGDBVariables.toArray(new IVariable[fGDBVariables.size()]);
+		}
 	}
 	/**
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/thread/GDBThread.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/thread/GDBThread.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/thread/GDBThread.java	(revision 982)
@@ -115,4 +115,5 @@
 	public GDBThread(GDBDebugTarget target) {
 		super(target);
+		fGDBStackFrames = new ArrayList<GDBStackFrame>();
 	}
 
@@ -133,8 +134,4 @@
 	private synchronized MIFrame[] getStackFrames(int lowFrame, int highFrame) {
 		// TODO Auto-generated method stub
-		// if fGDBStackFrames is null then initialize it
-		if (fGDBStackFrames == null) {
-			fGDBStackFrames = new ArrayList<GDBStackFrame>();
-		}
 		try {
 			// get the list of frames from GDB
@@ -189,63 +186,74 @@
 	protected synchronized void computeStackFrames() {
 		// TODO Auto-generated method stub
-		if (isSuspended()) {
-			if (isRefreshStackFrames()) {
-				try {
-					// get the stack depth
-					int depth = getStackInfoDepth();
-					if (depth >= getMaxStackDepth())
-						depth = getMaxStackDepth() - 1;
-					// get the stack frames from GDB
-					MIFrame[] frames = getStackFrames(0, depth - 1);
-					// Safety precaution in case getting the stack frames failed to get us as many as it said
-					depth = frames.length;
-					
-					if (fGDBStackFrames.isEmpty()) {
-						if (frames.length > 0) {
-							addStackFrames(frames, 0, frames.length, false);
-						}
-					} else {
-						int diff = depth - getLastStackDepth();
-						int offset = (diff > 0) ? frames.length - diff : 0;
-						int length = (diff > 0) ? diff : -diff;
-						if (offset < 0 || !compareStackFrames(frames, fGDBStackFrames, offset, length)) {
-							// replace all frames
-							disposeStackFrames(0, fGDBStackFrames.size());
-							addStackFrames(frames, 0, frames.length, false);						
-						}
-						if (diff < 0) {
-							// stepping out of the last frame
-							disposeStackFrames(0, getLastStackDepth() - depth);
+		synchronized (getGDBDebugTarget().getLock()) {
+			if (isSuspended()) {
+				if (isRefreshStackFrames()) {
+					try {
+						// get the stack depth
+						int depth = getStackInfoDepth();
+						if (depth >= getMaxStackDepth())
+							depth = getMaxStackDepth() - 1;
+						// get the stack frames from GDB
+						MIFrame[] frames = getStackFrames(0, depth - 1);
+						// Safety precaution in case getting the stack frames failed to get us as many as it said
+						depth = frames.length;
+						
+						if (fGDBStackFrames.isEmpty()) {
 							if (frames.length > 0) {
-								updateStackFrames(frames, 0, fGDBStackFrames, fGDBStackFrames.size());
-								if (fGDBStackFrames.size() < frames.length) {
-									addStackFrames(frames, fGDBStackFrames.size(),
-											frames.length - fGDBStackFrames.size(), true);
+								addStackFrames(frames, 0, frames.length, false);
+							}
+						} else {
+							int diff = depth - getLastStackDepth();
+							int offset = (diff > 0) ? frames.length - diff : 0;
+							int length = (diff > 0) ? diff : -diff;
+							if (offset < 0 || !compareStackFrames(frames, fGDBStackFrames, offset, length)) {
+								// replace all frames
+								disposeStackFrames(0, fGDBStackFrames.size());
+								addStackFrames(frames, 0, frames.length, false);						
+							}
+							if (diff < 0) {
+								// stepping out of the last frame
+	//							disposeStackFrames(0, getLastStackDepth() - depth);
+	//							if (frames.length > 0) {
+	//								updateStackFrames(frames, 0, fGDBStackFrames, fGDBStackFrames.size());
+	//								if (fGDBStackFrames.size() < frames.length) {
+	//									addStackFrames(frames, fGDBStackFrames.size(),
+	//											frames.length - fGDBStackFrames.size(), true);
+	//								}
+	//							}
+								// replace all frames
+								disposeStackFrames(0, fGDBStackFrames.size());
+								addStackFrames(frames, 0, frames.length, false);
+							}
+							else if (diff > 0) {
+								// stepping into a new frame
+//								disposeStackFrames(frames.length - depth + getLastStackDepth(),
+//										depth - getLastStackDepth());
+//								addStackFrames(frames, 0, depth - getLastStackDepth(), false);
+//								updateStackFrames(frames, depth - getLastStackDepth(),
+//										fGDBStackFrames, frames.length - depth + getLastStackDepth());
+								// replace all frames
+								disposeStackFrames(0, fGDBStackFrames.size());
+								addStackFrames(frames, 0, frames.length, false);
+							}
+							else { // diff == 0
+								if (depth != 0) {
+									// we are in the same frame
+									//updateStackFrames(frames, 0, fGDBStackFrames, frames.length);
+									// replace all frames
+									disposeStackFrames(0, fGDBStackFrames.size());
+									addStackFrames(frames, 0, frames.length, false);
 								}
 							}
 						}
-						else if (diff > 0) {
-							// stepping into a new frame
-							disposeStackFrames(frames.length - depth + getLastStackDepth(),
-									depth - getLastStackDepth());
-							addStackFrames(frames, 0, depth - getLastStackDepth(), false);
-							updateStackFrames(frames, depth - getLastStackDepth(),
-									fGDBStackFrames, frames.length - depth + getLastStackDepth());
+						if (fGDBStackFrames.size() > 0) {
+							setCurrentGDBStackFrame(fGDBStackFrames.get(0));
 						}
-						else { // diff == 0
-							if (depth != 0) {
-								// we are in the same frame
-								updateStackFrames(frames, 0, fGDBStackFrames, frames.length);
-							}
-						}
+						setLastStackDepth(depth);
+						setRefreshStackFrames(false);
+					} catch (Exception e) {
+						// TODO: handle exception
+						MDTDebugCorePlugin.log(null, e);
 					}
-					if (fGDBStackFrames.size() > 0) {
-						setCurrentGDBStackFrame(fGDBStackFrames.get(0));
-					}
-					setLastStackDepth(depth);
-					setRefreshStackFrames(false);
-				} catch (Exception e) {
-					// TODO: handle exception
-					MDTDebugCorePlugin.log(null, e);
 				}
 			}
@@ -486,22 +494,24 @@
 	 */
 	public void resume() throws DebugException {
-		setRunning(true);
-		setSuspended(false);
-		setStepping(false);
-		resumed(DebugEvent.CLIENT_REQUEST);
-		// clear the stack frames completely
-		disposeStackFrames();
-		// send gdb the -exec-continue commmand
-		try {
-			MIExecContinue execContinueCmd = getGDBDebugTarget().getMISession().getCommandFactory().createMIExecContinue();
-			execContinueCmd.setQuiet(true);
-			getGDBDebugTarget().getMISession().postCommand(execContinueCmd, null);
-			if (execContinueCmd.getMIInfo() == null) {
-				throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
-						MDTDebugCorePlugin.getResourceString("GDBThread.resume.ExecContinue.NoAnswer"), null));
-			}
-		} catch (Exception e) {
-			// TODO Auto-generated catch block
-			MDTDebugCorePlugin.log(null, e);
+		synchronized (getGDBDebugTarget().getLock()) {
+			setRunning(true);
+			setSuspended(false);
+			setStepping(false);
+			resumed(DebugEvent.CLIENT_REQUEST);
+			// clear the stack frames completely
+			disposeStackFrames();
+			// send gdb the -exec-continue commmand
+			try {
+				MIExecContinue execContinueCmd = getGDBDebugTarget().getMISession().getCommandFactory().createMIExecContinue();
+				execContinueCmd.setQuiet(true);
+				getGDBDebugTarget().getMISession().postCommand(execContinueCmd, null);
+				if (execContinueCmd.getMIInfo() == null) {
+					throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
+							MDTDebugCorePlugin.getResourceString("GDBThread.resume.ExecContinue.NoAnswer"), null));
+				}
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				MDTDebugCorePlugin.log(null, e);
+			}
 		}
 	}
@@ -511,26 +521,28 @@
 	 */
 	public void start() throws CoreException {
-		setRunning(true);
-		setSuspended(false);
-		setStepping(false);
-		try {
-			MISession miSession = getGDBDebugTarget().getMISession();
-			CommandFactory factory = miSession.getCommandFactory();
-			// send -exec-run
-			MIExecRun execRunCmd = factory.createMIExecRun(new String[0]);
-			miSession.postCommand(execRunCmd, null);
-			if (execRunCmd.getMIInfo() == null) {
-				throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
-						MDTDebugCorePlugin.getResourceString("GDBThread.start.ExecRun.NoAnswer"), null));
-			}
-			// if run is ok then change the stdout buffer policy
-			MIDataEvaluateExpression changeStdStreamBufferCmd = factory.createMIChangeStdStreamBuffer();
-			// we don't care about the time and output of this command
-			miSession.postCommand(changeStdStreamBufferCmd, -1, null);
-		} catch (MIException e) {
-			// TODO Auto-generated catch block
-			MDTDebugCorePlugin.log(e.getMessage() + e.getLogMessage(), e);
-		}
-		getGDBDebugTarget().getMISession().getGDBInferior().update();
+		synchronized (getGDBDebugTarget().getLock()) {
+			setRunning(true);
+			setSuspended(false);
+			setStepping(false);
+			try {
+				MISession miSession = getGDBDebugTarget().getMISession();
+				CommandFactory factory = miSession.getCommandFactory();
+				// send -exec-run
+				MIExecRun execRunCmd = factory.createMIExecRun(new String[0]);
+				miSession.postCommand(execRunCmd, null);
+				if (execRunCmd.getMIInfo() == null) {
+					throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
+							MDTDebugCorePlugin.getResourceString("GDBThread.start.ExecRun.NoAnswer"), null));
+				}
+				// if run is ok then change the stdout buffer policy
+				MIDataEvaluateExpression changeStdStreamBufferCmd = factory.createMIChangeStdStreamBuffer();
+				// we don't care about the time and output of this command
+				miSession.postCommand(changeStdStreamBufferCmd, -1, null);
+			} catch (MIException e) {
+				// TODO Auto-generated catch block
+				MDTDebugCorePlugin.log(e.getMessage() + e.getLogMessage(), e);
+			}
+			getGDBDebugTarget().getMISession().getGDBInferior().update();
+		}
 	}
 	/* (non-Javadoc)
@@ -538,22 +550,23 @@
 	 */
 	public void suspend() throws DebugException {
-		// on windows -exec-interrupt is not supported
-		try {
-			int result = getGDBDebugTarget().getMISession().interruptInferior(getGDBDebugTarget());
-			if (result != 0) {
-				MDTDebugCorePlugin.log(null, new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0, 
-						"Unable to interrupt the running program.", null)));
-			}
-		} catch (CoreException e) {
-			// TODO Auto-generated catch block
-			MDTDebugCorePlugin.log(null, e);
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			MDTDebugCorePlugin.log(null, e);
-		} catch (InterruptedException e) {
-			// TODO Auto-generated catch block
-			MDTDebugCorePlugin.log(null, e);
-		}
-		suspended(DebugEvent.CLIENT_REQUEST);
+		synchronized (getGDBDebugTarget().getLock()) {
+			try {
+				int result = getGDBDebugTarget().getMISession().interruptInferior(getGDBDebugTarget());
+				if (result != 0) {
+					MDTDebugCorePlugin.log(null, new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0, 
+							"Unable to interrupt the running program.", null)));
+				}
+			} catch (CoreException e) {
+				// TODO Auto-generated catch block
+				MDTDebugCorePlugin.log(null, e);
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				MDTDebugCorePlugin.log(null, e);
+			} catch (InterruptedException e) {
+				// TODO Auto-generated catch block
+				MDTDebugCorePlugin.log(null, e);
+			}
+			suspended(DebugEvent.CLIENT_REQUEST);
+		}
 	}
 	/* (non-Javadoc)
@@ -589,22 +602,29 @@
 	 */
 	public void stepInto() throws DebugException {
-		setRunning(true);
-		setSuspended(false);
-		setStepping(false);
-		resumed(DebugEvent.STEP_INTO);
-		// send the -exec-step command
-		MISession miSession = getGDBDebugTarget().getMISession();
-		CommandFactory factory = miSession.getCommandFactory();
-		MIExecStep execStepCommand = factory.createMIExecStep();
-		try {
-			miSession.postCommand(execStepCommand, null);
-			setExecuteCommand(ExecuteCommand.EXECSTEP);
-			MIInfo info = execStepCommand.getMIInfo();
-			if (info == null) {
-				throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
-						MDTDebugCorePlugin.getResourceString("GDBThread.stepInto.ExecStep.NoAnswer"), null));
-			}
-		} catch (Exception e) {
-			MDTDebugCorePlugin.log(null, e);
+		synchronized (getGDBDebugTarget().getLock()) {
+			setRunning(true);
+			setSuspended(false);
+			setStepping(false);
+			resumed(DebugEvent.STEP_INTO);
+			/*
+			 * Adeel 2011-09-20 23:31 When we do step we put the current stack frame as null.
+			 * So other threads dont post commands to the inferior.
+			 */
+			fCurrentGDBStackFrame = null;
+			// send the -exec-step command
+			MISession miSession = getGDBDebugTarget().getMISession();
+			CommandFactory factory = miSession.getCommandFactory();
+			MIExecStep execStepCommand = factory.createMIExecStep();
+			try {
+				miSession.postCommand(execStepCommand, null);
+				setExecuteCommand(ExecuteCommand.EXECSTEP);
+				MIInfo info = execStepCommand.getMIInfo();
+				if (info == null) {
+					throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
+							MDTDebugCorePlugin.getResourceString("GDBThread.stepInto.ExecStep.NoAnswer"), null));
+				}
+			} catch (Exception e) {
+				MDTDebugCorePlugin.log(null, e);
+			}
 		}
 	}
@@ -613,21 +633,28 @@
 	 */
 	public void stepOver() throws DebugException {
-		setRunning(true);
-		setSuspended(false);
-		setStepping(false);
-		resumed(DebugEvent.STEP_OVER);
-		// send the -exec-next command
-		CommandFactory factory = getGDBDebugTarget().getMISession().getCommandFactory();
-		MIExecNext execNextCmd = factory.createMIExecNext();
-		try {
-			getGDBDebugTarget().getMISession().postCommand(execNextCmd, null);
-			setExecuteCommand(ExecuteCommand.EXECNEXT);
-			MIInfo info = execNextCmd.getMIInfo();
-			if (info == null) {
-				throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
-						MDTDebugCorePlugin.getResourceString("GDBThread.stepOver.ExecNext.NoAnswer"), null));
-			}
-		} catch (Exception e) {
-			MDTDebugCorePlugin.log(null, e);
+		synchronized (getGDBDebugTarget().getLock()) {
+			setRunning(true);
+			setSuspended(false);
+			setStepping(false);
+			resumed(DebugEvent.STEP_OVER);
+			/*
+			 * Adeel 2011-09-20 23:31 When we do step we put the current stack frame as null.
+			 * So other threads dont post commands to the inferior.
+			 */
+			fCurrentGDBStackFrame = null;
+			// send the -exec-next command
+			CommandFactory factory = getGDBDebugTarget().getMISession().getCommandFactory();
+			MIExecNext execNextCmd = factory.createMIExecNext();
+			try {
+				getGDBDebugTarget().getMISession().postCommand(execNextCmd, null);
+				setExecuteCommand(ExecuteCommand.EXECNEXT);
+				MIInfo info = execNextCmd.getMIInfo();
+				if (info == null) {
+					throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
+							MDTDebugCorePlugin.getResourceString("GDBThread.stepOver.ExecNext.NoAnswer"), null));
+				}
+			} catch (Exception e) {
+				MDTDebugCorePlugin.log(null, e);
+			}
 		}
 	}
@@ -636,21 +663,23 @@
 	 */
 	public void stepReturn() throws DebugException {
-		setRunning(true);
-		setSuspended(false);
-		setStepping(false);
-		resumed(DebugEvent.STEP_RETURN);
-		// send the -exec-finish command
-		CommandFactory factory = getGDBDebugTarget().getMISession().getCommandFactory();
-		MIExecFinish execFinishCmd = factory.createMIExecFinish();
-		try {
-			getGDBDebugTarget().getMISession().postCommand(execFinishCmd, null);
-			setExecuteCommand(ExecuteCommand.EXECNEXT);
-			MIInfo info = execFinishCmd.getMIInfo();
-			if (info == null) {
-				throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
-						MDTDebugCorePlugin.getResourceString("GDBThread.stepReturn.ExecFinish.NoAnswer"), null));
-			}
-		} catch (Exception e) {
-			MDTDebugCorePlugin.log(null, e);
+		synchronized (getGDBDebugTarget().getLock()) {
+			setRunning(true);
+			setSuspended(false);
+			setStepping(false);
+			resumed(DebugEvent.STEP_RETURN);
+			// send the -exec-finish command
+			CommandFactory factory = getGDBDebugTarget().getMISession().getCommandFactory();
+			MIExecFinish execFinishCmd = factory.createMIExecFinish();
+			try {
+				getGDBDebugTarget().getMISession().postCommand(execFinishCmd, null);
+				setExecuteCommand(ExecuteCommand.EXECNEXT);
+				MIInfo info = execFinishCmd.getMIInfo();
+				if (info == null) {
+					throw new CoreException(new Status(IStatus.ERROR, IMDTConstants.ID_MDT_DEBUG_MODEL, 0,
+							MDTDebugCorePlugin.getResourceString("GDBThread.stepReturn.ExecFinish.NoAnswer"), null));
+				}
+			} catch (Exception e) {
+				MDTDebugCorePlugin.log(null, e);
+			}
 		}
 	}
@@ -671,9 +700,11 @@
 	 */
 	public void terminate() throws DebugException {
-		setTerminated(true);
-		setStepping(false);
-		setRunning(false);
-		// terminate the MI Session. It will exit the GDB as well.
-		getGDBDebugTarget().getMISession().getSessionProcess().destroy();
+		synchronized (getGDBDebugTarget().getLock()) {
+			setTerminated(true);
+			setStepping(false);
+			setRunning(false);
+			// terminate the MI Session. It will exit the GDB as well.
+			getGDBDebugTarget().getMISession().getSessionProcess().destroy();
+		}
 	}
 	
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBArrayValue.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBArrayValue.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBArrayValue.java	(revision 982)
@@ -74,5 +74,5 @@
 	public synchronized IVariable[] getVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return new IVariable[0];
 		}
@@ -109,5 +109,5 @@
 	public boolean hasVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
@@ -131,5 +131,5 @@
 	public boolean hasValueChanged() throws MIException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBCoreValue.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBCoreValue.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBCoreValue.java	(revision 982)
@@ -74,5 +74,5 @@
 	public boolean hasValueChanged() throws MIException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
@@ -106,5 +106,5 @@
 	public String getValueString() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return null;
 		}
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBListValue.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBListValue.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBListValue.java	(revision 982)
@@ -73,5 +73,5 @@
 	public synchronized IVariable[] getVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return new IVariable[0];
 		}
@@ -103,5 +103,5 @@
 	public boolean hasVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
@@ -125,5 +125,5 @@
 	public boolean hasValueChanged() throws MIException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBOptionValue.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBOptionValue.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBOptionValue.java	(revision 982)
@@ -71,5 +71,5 @@
 	public synchronized IVariable[] getVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return new IVariable[0];
 		}
@@ -104,5 +104,5 @@
 	public boolean hasVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
@@ -135,5 +135,5 @@
 	public boolean hasValueChanged() throws MIException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBRecordValue.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBRecordValue.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBRecordValue.java	(revision 982)
@@ -71,5 +71,5 @@
 	public synchronized IVariable[] getVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return new IVariable[0];
 		}
@@ -109,5 +109,5 @@
 	public boolean hasVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBTupleValue.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBTupleValue.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/value/GDBTupleValue.java	(revision 982)
@@ -76,5 +76,5 @@
 	public synchronized IVariable[] getVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return new IVariable[0];
 		}
@@ -111,5 +111,5 @@
 	public boolean hasVariables() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
@@ -137,5 +137,5 @@
 	public boolean hasValueChanged() throws MIException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBVariable().getGDBStackFrame())) {
+		if (isDisposed() || !getGDBVariable().getGDBStackFrame().equals(((GDBThread)getGDBVariable().getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return false;
 		}
Index: trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/variable/GDBCoreVariable.java
===================================================================
--- trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/variable/GDBCoreVariable.java	(revision 980)
+++ trunk/org.modelica.mdt.debug.core/src/org/modelica/mdt/debug/gdb/core/model/variable/GDBCoreVariable.java	(revision 982)
@@ -68,5 +68,5 @@
 	public synchronized IValue getValue() throws DebugException {
 		// TODO Auto-generated method stub
-		if (isDisposed() || !((GDBThread)getGDBStackFrame().getThread()).getCurrentGDBStackFrame().equals(getGDBStackFrame())) {
+		if (isDisposed() || !getGDBStackFrame().equals(((GDBThread)getGDBStackFrame().getThread()).getCurrentGDBStackFrame())) {
 			return new EmptyValue(this);
 		}
