Ejemplo n.º 1
0
		Eval(Process process, string description, ICorDebugEval corEval)
		{
			this.process = process;
			this.description = description;
			this.corEval = corEval;
			this.state = EvalState.Evaluating;
		}
Ejemplo n.º 2
0
        private void SetEvalState(ExcelReference caller, EvalState evalState, CallArguments args, AsyncCallInfo asyncCallInfo)
        {
            evalStates_[caller] = evalState;
            switch (evalState)
            {
            case EvalState.ObservableCreated:
            case EvalState.Scheduled:
            case EvalState.ForcingFormulaUpdate:
                MarkAsCalculating(caller, asyncCallInfo);
                LogState();
                break;

            case EvalState.ObservableFinished:
                RemoveFromCalculating(caller);
                AddCalculatedFunc(caller, args);

                if (IsEvaluatingBatchSeemsToBeFinished)
                {
                    UpdateLastFinished();
                }

                LogState();
                break;
            }
        }
Ejemplo n.º 3
0
 Eval(Process process, string description, ICorDebugEval corEval)
 {
     this.process     = process;
     this.description = description;
     this.corEval     = corEval;
     this.state       = EvalState.Evaluating;
 }
Ejemplo n.º 4
0
    private void _endTask()
    {
        if (evalState == EvalState.IN_SESSION)
        {
            if (_repetition < MaxRepetitions)
            {
                evalState = EvalState.PAUSE;
                print("END TASK");

                _send_endMsgToBonsai();
                _log.writeLine(condition, task, _repetition, DateTime.Now - _lastTimeStamp);
            }
            else
            {
                evalState = EvalState.NONE;

                _send_endMsgToBonsai();
                _log.writeLine(condition, task, _repetition, DateTime.Now - _lastTimeStamp);

                _log.flush();

                print("END SESSION");
            }
        }
    }
Ejemplo n.º 5
0
 /// <exception cref="DebuggerException">Evaluation can not be stopped</exception>
 /// <exception cref="GetValueException">Process exited</exception>
 Value WaitForResult()
 {
     // Note that aborting is not supported for suspended threads
     try {
         process.WaitForPause(TimeSpan.FromMilliseconds(500));
         if (!Evaluated)
         {
             process.TraceMessage("Aborting eval: " + Description);
             this.CorEval.Abort();
             process.WaitForPause(TimeSpan.FromMilliseconds(2500));
             if (!Evaluated)
             {
                 process.TraceMessage("Rude aborting eval: " + Description);
                 this.CorEval2.RudeAbort();
                 process.WaitForPause(TimeSpan.FromMilliseconds(5000));
                 if (!Evaluated)
                 {
                     throw new DebuggerException("Evaluation can not be stopped");
                 }
             }
             // Note that this sets Evaluated to true
             state = EvalState.EvaluatedTimeOut;
         }
         process.AssertPaused();
         return(this.Result);
     } catch (ProcessExitedException) {
         throw new GetValueException("Process exited");
     }
 }
Ejemplo n.º 6
0
        /// <returns>True if setup was successful</returns>
        internal bool SetupEvaluation(Thread targetThread)
        {
            process.AssertPaused();

            try {
                if (targetThread.IsLastFunctionNative)
                {
                    throw new EvalSetupException("Can not evaluate because native frame is on top of stack");
                }
                if (!targetThread.IsAtSafePoint)
                {
                    throw new EvalSetupException("Can not evaluate because thread is not at a safe point");
                }

                // TODO: What if this thread is not suitable?
                corEval = targetThread.CorThread.CreateEval();

                try {
                    evaluationInvoker(corEval);
                } catch (COMException e) {
                    if ((uint)e.ErrorCode == 0x80131C26)
                    {
                        throw new EvalSetupException("Can not evaluate in optimized code");
                    }
                    else if ((uint)e.ErrorCode == 0x80131C28)
                    {
                        throw new EvalSetupException("Object is in wrong AppDomain");
                    }
                    else if ((uint)e.ErrorCode == 0x8013130A)
                    {
                        // Happens on getting of Sytem.Threading.Thread.ManagedThreadId; See SD2-1116
                        throw new EvalSetupException("Function does not have IL code");
                    }
                    else
                    {
                        throw;
                    }
                }

                state = EvalState.Evaluating;
                return(true);
            } catch (EvalSetupException e) {
                state    = EvalState.EvaluatedError;
                errorMsg = e.Message;
                return(false);
            }
        }
Ejemplo n.º 7
0
 /// <exception cref="DebuggerException">Evaluation can not be stopped</exception>
 /// <exception cref="GetValueException">Process exited</exception>
 private Value WaitForResult()
 {
     // Note that aborting is not supported for suspended threads
     try
     {
         process.WaitForPause(TimeSpan.FromMilliseconds(500));
         if (!Evaluated)
         {
             process.TraceMessage("Aborting eval: " + Description);
             this.CorEval.Abort();
             process.WaitForPause(TimeSpan.FromMilliseconds(2500));
             if (!Evaluated)
             {
                 process.TraceMessage("Rude aborting eval: " + Description);
                 this.CorEval2.RudeAbort();
                 process.WaitForPause(TimeSpan.FromMilliseconds(5000));
                 if (!Evaluated)
                 {
                     if (Variables.Langue == "en")
                     {
                         throw new DebuggerException(VelerSoftware.SZC.Properties.Resources.Eval_Not_Stopped_EN);
                     }
                     else
                     {
                         throw new DebuggerException(VelerSoftware.SZC.Properties.Resources.Eval_Not_Stopped);
                     }
                 }
             }
             // Note that this sets Evaluated to true
             state = EvalState.EvaluatedTimeOut;
         }
         process.AssertPaused();
         return(this.Result);
     }
     catch (ProcessExitedException)
     {
         if (Variables.Langue == "en")
         {
             throw new GetValueException(VelerSoftware.SZC.Properties.Resources.Eval_Process_Exited_EN);
         }
         else
         {
             throw new GetValueException(VelerSoftware.SZC.Properties.Resources.Eval_Process_Exited);
         }
     }
 }
Ejemplo n.º 8
0
    void Start()
    {
        Application.runInBackground = true;
        _repetition = 0;
        lag         = LAG.NONE;
        evalState   = EvalState.NONE;

        _resultsFolder = Application.dataPath + "/Results";
        if (!Directory.Exists(_resultsFolder))
        {
            Directory.CreateDirectory(_resultsFolder);
            Debug.Log("Folder created: " + _resultsFolder);
        }
        else
        {
            print("Folder exists: " + _resultsFolder);
        }
    }
Ejemplo n.º 9
0
    private void _startTask()
    {
        if (evalState != EvalState.IN_SESSION && _repetition < MaxRepetitions)
        {
            print("START");
            _repetition += 1;
            evalState    = EvalState.IN_SESSION;

            if (_repetition == 1)
            {
                _resultsFile = _resultsFolder + Path.DirectorySeparatorChar + "Results_" + condition + "_" + task + "_" + DateTime.Now.ToString(@"hh\:mm\:ss") + ".txt";
                _log         = new Log(_resultsFile);
            }

            _send_startMsgToBonsai();
            _lastTimeStamp = DateTime.Now;
        }
    }
Ejemplo n.º 10
0
 internal void NotifyEvaluationComplete(bool successful)
 {
     // Eval result should be ICorDebugHandleValue so it should survive Continue()
     if (state == EvalState.EvaluatedTimeOut)
     {
         return;
     }
     if (corEval.Result == null)
     {
         state = EvalState.EvaluatedNoResult;
     }
     else
     {
         if (successful)
         {
             state = EvalState.EvaluatedSuccessfully;
         }
         else
         {
             state = EvalState.EvaluatedException;
         }
         result = new Value(process, new EmptyExpression(), corEval.Result);
     }
 }
Ejemplo n.º 11
0
        internal void NotifyEvaluationComplete(bool successful)
        {
            // Eval result should be ICorDebugHandleValue so it should survive Continue()

            if (corEval.Result == null)
            {
                state = EvalState.EvaluatedNoResult;
            }
            else
            {
                if (successful)
                {
                    state = EvalState.EvaluatedSuccessfully;
                }
                else
                {
                    state = EvalState.EvaluatedException;
                }
                result = new Value(process,
                                   new IExpirable[] {},
                                   new IMutable[] {},
                                   delegate { return(corEval.Result); });
            }
        }
Ejemplo n.º 12
0
 internal void NotifyEvaluationComplete(bool successful)
 {
     // Eval result should be ICorDebugHandleValue so it should survive Continue()
     if (state == EvalState.EvaluatedTimeOut)
     {
         return;
     }
     if (corEval.GetResult() == null)
     {
         state = EvalState.EvaluatedNoResult;
     }
     else
     {
         if (successful)
         {
             state = EvalState.EvaluatedSuccessfully;
         }
         else
         {
             state = EvalState.EvaluatedException;
         }
         result = new Value(AppDomain, corEval.GetResult());
     }
 }
Ejemplo n.º 13
0
        Eval(Thread evalThread, string description, EvalStarter evalStarter)
        {
            if (evalThread == null)
            {
                throw new DebuggerException("No evaluation thread was provided");
            }

            this.appDomain   = evalThread.AppDomain;
            this.process     = appDomain.Process;
            this.description = description;
            this.state       = EvalState.Evaluating;
            this.thread      = evalThread;

            if (evalThread.Suspended)
            {
                throw new GetValueException("Can not evaluate because thread is suspended");
            }
            if (evalThread.IsInNativeCode)
            {
                throw new GetValueException("Can not evaluate because thread is in native code");
            }
            if (!evalThread.IsAtSafePoint)
            {
                throw new GetValueException("Can not evaluate because thread is not at safe point");
            }

            this.corEval = evalThread.CorThread.CreateEval();

            try {
                evalStarter(this);
            } catch (COMException e) {
                if ((uint)e.ErrorCode == 0x80131C26)
                {
                    throw new GetValueException("Can not evaluate in optimized code");
                }
                else if ((uint)e.ErrorCode == 0x80131C28)
                {
                    throw new GetValueException("Object is in wrong AppDomain");
                }
                else if ((uint)e.ErrorCode == 0x8013130A)
                {
                    // Happens on getting of Sytem.Threading.Thread.ManagedThreadId; See SD2-1116
                    throw new GetValueException("Function does not have IL code");
                }
                else if ((uint)e.ErrorCode == 0x80131C23)
                {
                    // The operation failed because it is a GC unsafe point. (Exception from HRESULT: 0x80131C23)
                    // This can probably happen when we break and the thread is in native code
                    throw new GetValueException("Thread is in GC unsafe point");
                }
                else if ((uint)e.ErrorCode == 0x80131C22)
                {
                    // The operation is illegal because of a stack overflow.
                    throw new GetValueException("Can not evaluate after stack overflow");
                }
                else if ((uint)e.ErrorCode == 0x80131313)
                {
                    // Func eval cannot work. Bad starting point.
                    // Reproduction circumstancess are unknown
                    throw new GetValueException("Func eval cannot work. Bad starting point.");
                }
                else
                {
                                        #if DEBUG
                    throw;                     // Expose for more diagnostics
                                        #else
                    throw new GetValueException(e.Message);
                                        #endif
                }
            }

            appDomain.Process.activeEvals.Add(this);

            appDomain.Process.AsyncContinue(DebuggeeStateAction.Keep, evalThread);
        }
Ejemplo n.º 14
0
        Eval(AppDomain appDomain, string description, EvalStarter evalStarter)
        {
            this.appDomain   = appDomain;
            this.process     = appDomain.Process;
            this.description = description;
            this.state       = EvalState.Evaluating;
            this.thread      = GetEvaluationThread(appDomain);
            this.corEval     = thread.CorThread.CreateEval();

            try {
                evalStarter(this);
            } catch (COMException e) {
                if ((uint)e.ErrorCode == 0x80131C26)
                {
                    throw new GetValueException("Can not evaluate in optimized code");
                }
                else if ((uint)e.ErrorCode == 0x80131C28)
                {
                    throw new GetValueException("Object is in wrong AppDomain");
                }
                else if ((uint)e.ErrorCode == 0x8013130A)
                {
                    // Happens on getting of Sytem.Threading.Thread.ManagedThreadId; See SD2-1116
                    throw new GetValueException("Function does not have IL code");
                }
                else if ((uint)e.ErrorCode == 0x80131C23)
                {
                    // The operation failed because it is a GC unsafe point. (Exception from HRESULT: 0x80131C23)
                    // This can probably happen when we break and the thread is in native code
                    throw new GetValueException("Thread is in GC unsafe point");
                }
                else if ((uint)e.ErrorCode == 0x80131C22)
                {
                    // The operation is illegal because of a stack overflow.
                    throw new GetValueException("Can not evaluate after stack overflow");
                }
                else if ((uint)e.ErrorCode == 0x80131313)
                {
                    // Func eval cannot work. Bad starting point.
                    // Reproduction circumstancess are unknown
                    throw new GetValueException("Func eval cannot work. Bad starting point.");
                }
                else
                {
                                        #if DEBUG
                    throw;                             // Expose for more diagnostics
                                        #else
                    throw new GetValueException(e.Message);
                                        #endif
                }
            }

            appDomain.Process.ActiveEvals.Add(this);

            if (appDomain.Process.Options.SuspendOtherThreads)
            {
                appDomain.Process.AsyncContinue(DebuggeeStateAction.Keep, new Thread[] { thread }, CorDebugThreadState.THREAD_SUSPEND);
            }
            else
            {
                appDomain.Process.AsyncContinue(DebuggeeStateAction.Keep, this.Process.UnsuspendedThreads, CorDebugThreadState.THREAD_RUN);
            }
        }
Ejemplo n.º 15
0
		internal void NotifyEvaluationComplete(bool successful) 
		{
			// Eval result should be ICorDebugHandleValue so it should survive Continue()
			if (state == EvalState.EvaluatedTimeOut) {
				return;
			}
			if (corEval.Result == null) {
				state = EvalState.EvaluatedNoResult;
			} else {
				if (successful) {
					state = EvalState.EvaluatedSuccessfully;
				} else {
					state = EvalState.EvaluatedException;
				}
				result = new Value(process, new EmptyExpression(), corEval.Result);
			}
		}
Ejemplo n.º 16
0
		internal void NotifyEvaluationComplete(bool successful) 
		{
			// Eval result should be ICorDebugHandleValue so it should survive Continue()
			
			if (corEval.Result == null) {
				state = EvalState.EvaluatedNoResult;
			} else {
				if (successful) {
					state = EvalState.EvaluatedSuccessfully;
				} else {
					state = EvalState.EvaluatedException;
				}
				result = new Value(process,
				                   new IExpirable[] {},
				                   new IMutable[] {},
				                   delegate { return corEval.Result; });
			}
		}
Ejemplo n.º 17
0
		internal void NotifyEvaluationComplete(bool successful)
		{
			// Eval result should be ICorDebugHandleValue so it should survive Continue()
			if (state == EvalState.EvaluatedTimeOut) {
				return;
			}
			if (corEval.GetResult() == null) {
				state = EvalState.EvaluatedNoResult;
			} else {
				if (successful) {
					state = EvalState.EvaluatedSuccessfully;
				} else {
					state = EvalState.EvaluatedException;
				}
				result = new Value(AppDomain, corEval.GetResult());
			}
		}
Ejemplo n.º 18
0
		/// <exception cref="DebuggerException">Evaluation can not be stopped</exception>
		/// <exception cref="GetValueException">Process exited</exception>
		Value WaitForResult()
		{
			// Note that aborting is not supported for suspended threads
			try {
				process.WaitForPause(TimeSpan.FromMilliseconds(500));
				if (!Evaluated) {
					process.TraceMessage("Aborting eval: " + Description);
					this.CorEval.Abort();
					process.WaitForPause(TimeSpan.FromMilliseconds(2500));
					if (!Evaluated) {
						process.TraceMessage("Rude aborting eval: " + Description);
						this.CorEval2.RudeAbort();
						process.WaitForPause(TimeSpan.FromMilliseconds(5000));
						if (!Evaluated) {
							throw new DebuggerException("Evaluation can not be stopped");
						}
					}
					// Note that this sets Evaluated to true
					state = EvalState.EvaluatedTimeOut;
				}
				process.AssertPaused();
				return this.Result;
			} catch (ProcessExitedException) {
				throw new GetValueException("Process exited");
			}
		}
Ejemplo n.º 19
0
		Eval(AppDomain appDomain, string description, EvalStarter evalStarter)
		{
			this.appDomain = appDomain;
			this.process = appDomain.Process;
			this.description = description;
			this.state = EvalState.Evaluating;
			this.thread = GetEvaluationThread(appDomain);
			this.corEval = thread.CorThread.CreateEval();
			
			try {
				evalStarter(this);
			} catch (COMException e) {
				if ((uint)e.ErrorCode == 0x80131C26) {
					throw new GetValueException("Can not evaluate in optimized code");
				} else if ((uint)e.ErrorCode == 0x80131C28) {
					throw new GetValueException("Object is in wrong AppDomain");
				} else if ((uint)e.ErrorCode == 0x8013130A) {
					// Happens on getting of Sytem.Threading.Thread.ManagedThreadId; See SD2-1116
					throw new GetValueException("Function does not have IL code");
				} else if ((uint)e.ErrorCode == 0x80131C23) {
					// The operation failed because it is a GC unsafe point. (Exception from HRESULT: 0x80131C23)
					// This can probably happen when we break and the thread is in native code
					throw new GetValueException("Thread is in GC unsafe point");
				} else if ((uint)e.ErrorCode == 0x80131C22) {
					// The operation is illegal because of a stack overflow.
					throw new GetValueException("Can not evaluate after stack overflow");
				} else if ((uint)e.ErrorCode == 0x80131313) {
					// Func eval cannot work. Bad starting point.
					// Reproduction circumstancess are unknown
					throw new GetValueException("Func eval cannot work. Bad starting point.");
				} else {
					#if DEBUG
						throw; // Expose for more diagnostics
					#else
						throw new GetValueException(e.Message);
					#endif
				}
			}
			
			appDomain.Process.ActiveEvals.Add(this);
			
			if (appDomain.Process.Options.SuspendOtherThreads) {
				appDomain.Process.AsyncContinue(DebuggeeStateAction.Keep, new Thread[] { thread }, CorDebugThreadState.THREAD_SUSPEND);
			} else {
				appDomain.Process.AsyncContinue(DebuggeeStateAction.Keep, this.Process.UnsuspendedThreads, CorDebugThreadState.THREAD_RUN);
			}
		}
Ejemplo n.º 20
0
		Eval(Thread evalThread, string description, EvalStarter evalStarter)
		{
			if (evalThread == null)
				throw new DebuggerException("No evaluation thread was provided");
			
			this.appDomain = evalThread.AppDomain;
			this.process = appDomain.Process;
			this.description = description;
			this.state = EvalState.Evaluating;
			this.thread = evalThread;
			
			if (evalThread.Suspended)
				throw new GetValueException("Can not evaluate because thread is suspended");
			if (evalThread.IsInNativeCode)
				throw new GetValueException("Can not evaluate because thread is in native code");
			if (!evalThread.IsAtSafePoint)
				throw new GetValueException("Can not evaluate because thread is not at safe point");
			
			this.corEval = evalThread.CorThread.CreateEval();
			
			try {
				evalStarter(this);
			} catch (COMException e) {
				if ((uint)e.ErrorCode == 0x80131C26) {
					throw new GetValueException("Can not evaluate in optimized code");
				} else if ((uint)e.ErrorCode == 0x80131C28) {
					throw new GetValueException("Object is in wrong AppDomain");
				} else if ((uint)e.ErrorCode == 0x8013130A) {
					// Happens on getting of Sytem.Threading.Thread.ManagedThreadId; See SD2-1116
					throw new GetValueException("Function does not have IL code");
				} else if ((uint)e.ErrorCode == 0x80131C23) {
					// The operation failed because it is a GC unsafe point. (Exception from HRESULT: 0x80131C23)
					// This can probably happen when we break and the thread is in native code
					throw new GetValueException("Thread is in GC unsafe point");
				} else if ((uint)e.ErrorCode == 0x80131C22) {
					// The operation is illegal because of a stack overflow.
					throw new GetValueException("Can not evaluate after stack overflow");
				} else if ((uint)e.ErrorCode == 0x80131313) {
					// Func eval cannot work. Bad starting point.
					// Reproduction circumstancess are unknown
					throw new GetValueException("Func eval cannot work. Bad starting point.");
				} else {
					#if DEBUG
					throw; // Expose for more diagnostics
					#else
					throw new GetValueException(e.Message);
					#endif
				}
			}
			
			appDomain.Process.activeEvals.Add(this);
			
			appDomain.Process.AsyncContinue(DebuggeeStateAction.Keep, evalThread);
		}
Ejemplo n.º 21
0
		/// <returns>True if setup was successful</returns>
		internal bool SetupEvaluation(Thread targetThread)
		{
			process.AssertPaused();
			
			try {
				if (targetThread.IsLastFunctionNative) {
					throw new EvalSetupException("Can not evaluate because native frame is on top of stack");
				}
				if (!targetThread.IsAtSafePoint) {
					throw new EvalSetupException("Can not evaluate because thread is not at a safe point");
				}
				
				// TODO: What if this thread is not suitable?
				corEval = targetThread.CorThread.CreateEval();
				
				try {
					evaluationInvoker(corEval);
				} catch (COMException e) {
					if ((uint)e.ErrorCode == 0x80131C26) {
						throw new EvalSetupException("Can not evaluate in optimized code");
					} else if ((uint)e.ErrorCode == 0x80131C28) {
						throw new EvalSetupException("Object is in wrong AppDomain");
					} else if ((uint)e.ErrorCode == 0x8013130A) {
						// Happens on getting of Sytem.Threading.Thread.ManagedThreadId; See SD2-1116
						throw new EvalSetupException("Function does not have IL code");
					}else {
						throw;
					}
				}
				
				state = EvalState.Evaluating;
				return true;
			} catch (EvalSetupException e) {
				state = EvalState.EvaluatedError;
				errorMsg = e.Message;
				return false;
			}
		}