Ejemplo n.º 1
0
        SourcecodeSegment SetIP(bool simulate, string filename, int line, int column)
        {
            process.AssertPaused();

            SourcecodeSegment segment = SourcecodeSegment.Resolve(this.MethodInfo.DebugModule, filename, null, line, column);

            if (segment != null && segment.CorFunction.GetToken() == this.MethodInfo.MetadataToken)
            {
                try {
                    if (simulate)
                    {
                        CorILFrame.CanSetIP((uint)segment.ILStart);
                    }
                    else
                    {
                        // Invalidates all frames and chains for the current thread
                        CorILFrame.SetIP((uint)segment.ILStart);
                        process.NotifyResumed(DebuggeeStateAction.Keep);
                        process.NotifyPaused(PausedReason.SetIP);
                        process.RaisePausedEvents();
                    }
                } catch {
                    return(null);
                }
                return(segment);
            }
            return(null);
        }
Ejemplo n.º 2
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.º 3
0
        internal ICorDebugFrame GetFrameAt(FrameID frameID)
        {
            process.AssertPaused();

            ICorDebugChainEnum corChainEnum = CorThread.EnumerateChains();

            if (frameID.ChainIndex >= corChainEnum.Count)
            {
                throw new ArgumentException("Chain index too big", "chainIndex");
            }
            corChainEnum.Skip(corChainEnum.Count - frameID.ChainIndex - 1);

            ICorDebugChain corChain = corChainEnum.Next();

            if (corChain.IsManaged == 0)
            {
                throw new ArgumentException("Chain is not managed", "chainIndex");
            }

            ICorDebugFrameEnum corFrameEnum = corChain.EnumerateFrames();

            if (frameID.FrameIndex >= corFrameEnum.Count)
            {
                throw new ArgumentException("Frame index too big", "frameIndex");
            }
            corFrameEnum.Skip(corFrameEnum.Count - frameID.FrameIndex - 1);

            return(corFrameEnum.Next());
        }
Ejemplo n.º 4
0
        /// <exception cref="GetValueException">Can not evaluate because no thread is selected</exception>
        static ICorDebugEval CreateCorEval(Process process)
        {
            process.AssertPaused();

            Thread targetThread = process.SelectedThread;

            if (targetThread == null)
            {
                throw new GetValueException("Can not evaluate because no thread is selected");
            }
            if (targetThread.IsMostRecentStackFrameNative)
            {
                throw new GetValueException("Can not evaluate because native frame is on top of stack");
            }
            if (!targetThread.IsAtSafePoint)
            {
                throw new GetValueException("Can not evaluate because thread is not at a safe point");
            }
            if (targetThread.Suspended)
            {
                throw new GetValueException("Can not evaluate on suspended thread");
            }

            return(targetThread.CorThread.CreateEval());
        }
Ejemplo n.º 5
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.º 6
0
        SourcecodeSegment SetIP(bool simulate, string filename, int line, int column)
        {
            process.AssertPaused();

            SourcecodeSegment suggestion = new SourcecodeSegment(filename, line, column, column);
            ICorDebugFunction corFunction;
            int ilOffset;

            if (!suggestion.GetFunctionAndOffset(this.Module, false, out corFunction, out ilOffset))
            {
                return(null);
            }
            else
            {
                if (corFunction.Token != methodProps.Token)
                {
                    return(null);
                }
                else
                {
                    try {
                        if (simulate)
                        {
                            CorILFrame.CanSetIP((uint)ilOffset);
                        }
                        else
                        {
                            // invalidates all frames and chains for the current thread
                            CorILFrame.SetIP((uint)ilOffset);
                            process.NotifyPaused(new PauseSession(PausedReason.SetIP));
                            process.Pause(false);
                        }
                    } catch {
                        return(null);
                    }
                    return(GetSegmentForOffet((uint)ilOffset));
                }
            }
        }
Ejemplo n.º 7
0
        internal StackFrame GetStackFrameAt(uint chainIndex, uint frameIndex)
        {
            process.AssertPaused();

            ICorDebugChainEnum corChainEnum = CorThread.EnumerateChains();

            if (chainIndex >= corChainEnum.Count)
            {
                throw new DebuggerException("The requested chain index is too big");
            }
            corChainEnum.Skip(corChainEnum.Count - chainIndex - 1);
            ICorDebugChain corChain = corChainEnum.Next();

            if (corChain.IsManaged == 0)
            {
                throw new DebuggerException("The requested chain is not managed");
            }

            ICorDebugFrameEnum corFrameEnum = corChain.EnumerateFrames();

            if (frameIndex >= corFrameEnum.Count)
            {
                throw new DebuggerException("The requested frame index is too big");
            }
            corFrameEnum.Skip(corFrameEnum.Count - frameIndex - 1);
            ICorDebugFrame corFrame = corFrameEnum.Next();

            if (!corFrame.Is <ICorDebugILFrame>())
            {
                throw new DebuggerException("The rquested frame is not IL frame");
            }

            StackFrame stackFrame = new StackFrame(this, corFrame.CastTo <ICorDebugILFrame>(), chainIndex, frameIndex);

            return(stackFrame);
        }
Ejemplo n.º 8
0
	    /// <exception cref="GetValueException">Can not evaluate because no thread is selected</exception>
	    static ICorDebugEval CreateCorEval(Process process)
		{
			process.AssertPaused();
			
			Thread targetThread = process.SelectedThread;
			
			if (targetThread == null) {
				throw new GetValueException("Can not evaluate because no thread is selected");
			}
			if (targetThread.IsMostRecentStackFrameNative) {
				throw new GetValueException("Can not evaluate because native frame is on top of stack");
			}
			if (!targetThread.IsAtSafePoint) {
				throw new GetValueException("Can not evaluate because thread is not at a safe point");
			}
			if (targetThread.Suspended) {
				throw new GetValueException("Can not evaluate on suspended thread");
			}
			
			return targetThread.CorThread.CreateEval();
		}