Object to represent one stack frame.
Object to represent one stack frame.
Inheritance: DebugFrame
Exemplo n.º 1
0
		/// <summary>Interrupts script execution.</summary>
		/// <remarks>Interrupts script execution.</remarks>
		private void Interrupted(Context cx, Dim.StackFrame frame, Exception scriptException)
		{
			Dim.ContextData contextData = frame.ContextData();
			bool eventThreadFlag = callback.IsGuiEventThread();
			contextData.eventThreadFlag = eventThreadFlag;
			bool recursiveEventThreadCall = false;
			lock (eventThreadMonitor)
			{
				if (eventThreadFlag)
				{
					if (interruptedContextData != null)
					{
						recursiveEventThreadCall = true;
						goto interruptedCheck_break;
					}
				}
				else
				{
					while (interruptedContextData != null)
					{
						try
						{
							System.Threading.Monitor.Wait(eventThreadMonitor);
						}
						catch (Exception)
						{
							return;
						}
					}
				}
				interruptedContextData = contextData;
			}
interruptedCheck_break: ;
			if (recursiveEventThreadCall)
			{
				// XXX: For now the following is commented out as on Linux
				// too deep recursion of dispatchNextGuiEvent causes GUI lockout.
				// Note: it can make GUI unresponsive if long-running script
				// will be called on GUI thread while processing another interrupt
				if (false)
				{
					// Run event dispatch until gui sets a flag to exit the initial
					// call to interrupted.
					while (this.returnValue == -1)
					{
						try
						{
							callback.DispatchNextGuiEvent();
						}
						catch (Exception)
						{
						}
					}
				}
				return;
			}
			if (interruptedContextData == null)
			{
				Kit.CodeBug();
			}
			try
			{
				do
				{
					int frameCount = contextData.FrameCount();
					this.frameIndex = frameCount - 1;
					string threadTitle = Sharpen.Thread.CurrentThread().ToString();
					string alertMessage;
					if (scriptException == null)
					{
						alertMessage = null;
					}
					else
					{
						alertMessage = scriptException.ToString();
					}
					int returnValue = -1;
					if (!eventThreadFlag)
					{
						lock (monitor)
						{
							if (insideInterruptLoop)
							{
								Kit.CodeBug();
							}
							this.insideInterruptLoop = true;
							this.evalRequest = null;
							this.returnValue = -1;
							callback.EnterInterrupt(frame, threadTitle, alertMessage);
							try
							{
								for (; ; )
								{
									try
									{
										System.Threading.Monitor.Wait(monitor);
									}
									catch (Exception)
									{
										Sharpen.Thread.CurrentThread().Interrupt();
										break;
									}
									if (evalRequest != null)
									{
										this.evalResult = null;
										try
										{
											evalResult = Do_eval(cx, evalFrame, evalRequest);
										}
										finally
										{
											evalRequest = null;
											evalFrame = null;
											System.Threading.Monitor.Pulse(monitor);
										}
										continue;
									}
									if (this.returnValue != -1)
									{
										returnValue = this.returnValue;
										break;
									}
								}
							}
							finally
							{
								insideInterruptLoop = false;
							}
						}
					}
					else
					{
						this.returnValue = -1;
						callback.EnterInterrupt(frame, threadTitle, alertMessage);
						while (this.returnValue == -1)
						{
							try
							{
								callback.DispatchNextGuiEvent();
							}
							catch (Exception)
							{
							}
						}
						returnValue = this.returnValue;
					}
					switch (returnValue)
					{
						case STEP_OVER:
						{
							contextData.breakNextLine = true;
							contextData.stopAtFrameDepth = contextData.FrameCount();
							break;
						}

						case STEP_INTO:
						{
							contextData.breakNextLine = true;
							contextData.stopAtFrameDepth = -1;
							break;
						}

						case STEP_OUT:
						{
							if (contextData.FrameCount() > 1)
							{
								contextData.breakNextLine = true;
								contextData.stopAtFrameDepth = contextData.FrameCount() - 1;
							}
							break;
						}
					}
				}
				while (false);
			}
			finally
			{
				lock (eventThreadMonitor)
				{
					interruptedContextData = null;
					System.Threading.Monitor.PulseAll(eventThreadMonitor);
				}
			}
		}
Exemplo n.º 2
0
		/// <summary>Evaluates the given script.</summary>
		/// <remarks>Evaluates the given script.</remarks>
		public virtual string Eval(string expr)
		{
			string result = "undefined";
			if (expr == null)
			{
				return result;
			}
			Dim.ContextData contextData = CurrentContextData();
			if (contextData == null || frameIndex >= contextData.FrameCount())
			{
				return result;
			}
			Dim.StackFrame frame = contextData.GetFrame(frameIndex);
			if (contextData.eventThreadFlag)
			{
				Context cx = Context.GetCurrentContext();
				result = Do_eval(cx, frame, expr);
			}
			else
			{
				lock (monitor)
				{
					if (insideInterruptLoop)
					{
						evalRequest = expr;
						evalFrame = frame;
						System.Threading.Monitor.Pulse(monitor);
						do
						{
							try
							{
								System.Threading.Monitor.Wait(monitor);
							}
							catch (Exception)
							{
								Sharpen.Thread.CurrentThread().Interrupt();
								break;
							}
						}
						while (evalRequest != null);
						result = evalResult;
					}
				}
			}
			return result;
		}