PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Debugger/Debugger.Core/Stepper.cs

http://github.com/icsharpcode/ILSpy
C# | 140 lines | 110 code | 27 blank | 3 comment | 7 complexity | 7571c2fce49331f8720a555b274b05f3 MD5 | raw file
  1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
  3
  4using System;
  5using Debugger.Interop.CorDebug;
  6
  7namespace Debugger
  8{
  9	enum StepperOperation {StepIn, StepOver, StepOut};
 10	
 11	class Stepper
 12	{
 13		StackFrame stackFrame;
 14		StepperOperation operation;
 15		int[] stepRanges;
 16		string name;
 17		
 18		ICorDebugStepper corStepper;
 19		
 20		bool ignore;
 21		
 22		public event EventHandler<StepperEventArgs> StepComplete;
 23		
 24		public ICorDebugStepper CorStepper {
 25			get { return corStepper; }
 26		}
 27		
 28		public Process Process {
 29			get { return stackFrame.Process; }
 30		}
 31		
 32		public StackFrame StackFrame {
 33			get { return stackFrame; }
 34		}
 35		
 36		public StepperOperation Operation {
 37			get { return operation; }
 38		}
 39		
 40		public int[] StepRanges {
 41			get { return stepRanges; }
 42		}
 43		
 44		public string Name {
 45			get { return name; }
 46		}
 47		
 48		public bool Ignore {
 49			get { return ignore; }
 50			set { ignore = value; }
 51		}
 52		
 53		private Stepper(StackFrame stackFrame, StepperOperation operation, int[] stepRanges, string name, bool justMyCode)
 54		{
 55			this.stackFrame = stackFrame;
 56			this.operation = operation;
 57			this.stepRanges = stepRanges;
 58			this.name = name;
 59			
 60			this.corStepper = stackFrame.CorILFrame.CreateStepper();
 61			this.ignore = false;
 62			this.StackFrame.Process.Steppers.Add(this);
 63			
 64			if (justMyCode) {
 65				corStepper.SetUnmappedStopMask(CorDebugUnmappedStop.STOP_NONE);
 66				((ICorDebugStepper2)corStepper).SetJMC(1);
 67			}
 68		}
 69		
 70		protected internal virtual void OnStepComplete(CorDebugStepReason reason) {
 71			this.corStepper = null;
 72			if (StepComplete != null) {
 73				StepComplete(this, new StepperEventArgs(this, reason));
 74			}
 75		}
 76		
 77		internal bool IsCorStepper(ICorDebugStepper corStepper)
 78		{
 79			return this.corStepper == corStepper;
 80		}
 81		
 82		internal bool IsInStepRanges(int offset)
 83		{
 84			for(int i = 0; i < stepRanges.Length / 2; i++) {
 85				if (stepRanges[2*i] <= offset && offset < stepRanges[2*i + 1]) {
 86					return true;
 87				}
 88			}
 89			return false;
 90		}
 91		
 92		public static Stepper StepOut(StackFrame stackFrame, string name)
 93		{
 94			// JMC off - Needed for multiple events. See docs\Stepping.txt
 95			Stepper stepper = new Stepper(stackFrame, StepperOperation.StepOut, null, name, false);
 96			stepper.corStepper.StepOut();
 97			return stepper;
 98		}
 99		
100		public static Stepper StepIn(StackFrame stackFrame, int[] stepRanges, string name)
101		{
102			Stepper stepper = new Stepper(stackFrame, StepperOperation.StepIn, stepRanges, name, stackFrame.Process.Options.EnableJustMyCode);
103			stepper.corStepper.StepRange(true /* step in */, stepRanges);
104			return stepper;
105		}
106		
107		public static Stepper StepOver(StackFrame stackFrame, int[] stepRanges, string name)
108		{
109			Stepper stepper = new Stepper(stackFrame, StepperOperation.StepOver, stepRanges, name, stackFrame.Process.Options.EnableJustMyCode);
110			stepper.corStepper.StepRange(false /* step over */, stepRanges);
111			return stepper;
112		}
113		
114		public override string ToString()
115		{
116			return string.Format("{0} from {1} name=\"{2}\"", this.Operation, this.StackFrame.ToString(), this.Name);
117		}
118	}
119	
120	[Serializable]
121	class StepperEventArgs: ProcessEventArgs
122	{
123		Stepper stepper;
124		CorDebugStepReason reason;
125		
126		public Stepper Stepper {
127			get { return stepper; }
128		}
129		
130		public CorDebugStepReason Reason {
131			get { return reason; }
132		}
133		
134		public StepperEventArgs(Stepper stepper, CorDebugStepReason reason): base(stepper.Process)
135		{
136			this.stepper = stepper;
137			this.reason = reason;
138		}
139	}
140}