Пример #1
0
        public StackFrameNode(StackFrame stackFrame)
        {
            this.stackFrame = stackFrame;

            this.Name = stackFrame.MethodInfo.Name;
            this.ChildNodes = LazyGetChildNodes();
        }
Пример #2
0
        void StepIntoUnknownFrame(StackFrame frame)
        {
            string debuggeeVersion = frame.MethodInfo.DebugModule.Process.DebuggeeVersion.Substring(1, 3);             // should retrieve 2.0, 3.0, 4.0
            var    debugType       = (DebugType)frame.MethodInfo.DeclaringType;
            int    token           = frame.MethodInfo.MetadataToken;
            int    ilOffset        = frame.IP;
            string fullName        = debugType.FullNameWithoutGenericArguments;

            if (DebugInformation.LoadedAssemblies == null)
            {
                throw new NullReferenceException("No DebugData assemblies!");
            }
            else
            {
                // search for type in the current assembly list
                TypeDefinition typeDef       = null;
                TypeDefinition nestedTypeDef = null;

                foreach (var assembly in DebugInformation.LoadedAssemblies)
                {
                    if ((assembly.FullName.StartsWith("System") || assembly.FullName.StartsWith("Microsoft") || assembly.FullName.StartsWith("mscorlib")) &&
                        !assembly.Name.Version.ToString().StartsWith(debuggeeVersion))
                    {
                        continue;
                    }

                    foreach (var module in assembly.Modules)
                    {
                        var localType = module.GetType(fullName);
                        if (localType != null)
                        {
                            if (localType.DeclaringType == null)
                            {
                                typeDef = localType;
                            }
                            else
                            {
                                nestedTypeDef = localType;
                                typeDef       = localType.DeclaringType;
                            }
                            break;
                        }
                    }
                    if (typeDef != null)
                    {
                        break;
                    }
                }

                if (typeDef != null)
                {
                    TypeDefinition type = nestedTypeDef ?? typeDef;
                    DebugInformation.DebugStepInformation = Tuple.Create(token, ilOffset, type.GetMemberByToken(token));
                }
                else
                {
                    Debug.Assert(typeDef != null, "No type was found!");
                }
            }
        }
Пример #3
0
        // Stepping:

        SourceCodeMapping GetCurrentCodeMapping(out StackFrame frame, out bool isMatch)
        {
            isMatch = false;
            frame   = debuggedProcess.SelectedThread.MostRecentStackFrame;
            int key = frame.MethodInfo.MetadataToken;

            // get the mapped instruction from the current line marker or the next one
            if (DebugInformation.CodeMappings == null || !DebugInformation.CodeMappings.ContainsKey(key))
            {
                return(null);
            }

            return(DebugInformation.CodeMappings[key].GetInstructionByTokenAndOffset(frame.IP, out isMatch));
        }
        void JumpToDecompiledCode(Debugger.StackFrame frame)
        {
            if (frame == null)
            {
                LoggingService.Error("No stack frame!");
                return;
            }

            if (debuggerDecompilerService == null)
            {
                LoggingService.Warn("No IDebuggerDecompilerService found!");
                return;
            }

            // check for options - if these options are enabled, debugging decompiled code should not continue
            if (!debuggedProcess.Options.DecompileCodeWithoutSymbols)
            {
                LoggingService.Info("Decompiled code debugging is disabled!");
                return;
            }
            DebuggerService.RemoveCurrentLineMarker();
            // get external data
            int typeToken   = frame.MethodInfo.DeclaringType.MetadataToken;
            int methodToken = frame.MethodInfo.MetadataToken;
            int ilOffset    = frame.IP;

            int[] ilRanges  = null;
            int   line      = -1;
            bool  isMatch   = false;
            var   debugType = (DebugType)frame.MethodInfo.DeclaringType;

            debuggerDecompilerService.DebugStepInformation = Tuple.Create(methodToken, ilOffset);

            if (debuggerDecompilerService.GetILAndLineNumber(typeToken, methodToken, ilOffset, out ilRanges, out line, out isMatch))
            {
                // update marker & navigate to line
                NavigationService.NavigateTo(debugType.DebugModule.FullPath,
                                             debugType.FullNameWithoutGenericArguments,
                                             IDStringProvider.GetIDString(frame.MethodInfo),
                                             line);
            }
            else
            {
                // no line => do decompilation
                NavigationService.NavigateTo(debugType.DebugModule.FullPath,
                                             debugType.FullNameWithoutGenericArguments,
                                             IDStringProvider.GetIDString(frame.MethodInfo));
            }
        }
Пример #5
0
		private Stepper(StackFrame stackFrame, StepperOperation operation, int[] stepRanges, string name, bool justMyCode)
		{
			this.stackFrame = stackFrame;
			this.operation = operation;
			this.stepRanges = stepRanges;
			this.name = name;
			
			this.corStepper = stackFrame.CorILFrame.CreateStepper();
			this.ignore = false;
			this.StackFrame.Process.Steppers.Add(this);
			
			if (justMyCode) {
				corStepper.SetUnmappedStopMask(CorDebugUnmappedStop.STOP_NONE);
				((ICorDebugStepper2)corStepper).SetJMC(1);
			}
		}
Пример #6
0
        void StepIntoUnknownFrame(StackFrame frame)
        {
            var debugType = (DebugType)frame.MethodInfo.DeclaringType;
            var key       = frame.MethodInfo.ToMethodKey();
            var ip        = frame.IP;

            var debugModule = debugType.DebugModule;

            DebugInformation.MustJumpToReference = false;
            if (!string.IsNullOrEmpty(debugModule.FullPath))
            {
                var loadedMod = MainWindow.Instance.LoadAssembly(debugModule.AssemblyFullPath, debugModule.FullPath).ModuleDefinition as ModuleDefMD;
                if (loadedMod != null)
                {
                    DebugInformation.DebugStepInformation = Tuple.Create(key, ip.IsInvalid ? int.MaxValue : ip.Offset, loadedMod.ResolveToken(key.Token) as IMemberRef);
                    DebugInformation.MustJumpToReference  = true;
                }
            }
            if (!DebugInformation.MustJumpToReference)
            {
                DebugInformation.DebugStepInformation = null;
                Debug.Fail("No type was found!");
            }
        }
Пример #7
0
		static string GetFullName(StackFrame frame, bool hasSymbols)
		{
			StringBuilder name = new StringBuilder(64);
			if (DebuggingOptions.Instance.ShowModuleNames) {
				name.Append(frame.MethodInfo.ToString());
				name.Append('!');
			}
			name.Append(frame.MethodInfo.DeclaringType.FullName);
			name.Append('.');
			name.Append(frame.MethodInfo.Name);
			if (DebuggingOptions.Instance.ShowArgumentNames || DebuggingOptions.Instance.ShowArgumentValues) {
				name.Append('(');
				for (int i = 0; i < frame.MethodInfo.Parameters.Count; i++) {
					if (DebuggingOptions.Instance.ShowArgumentNames) {
						name.Append(frame.MethodInfo.Parameters[i].Name);
						if (DebuggingOptions.Instance.ShowArgumentValues) {
							name.Append('=');
						}
					}
					if (DebuggingOptions.Instance.ShowArgumentValues) {
						try {
							name.Append(frame.GetArgumentValue(i, hasSymbols).AsString(100));
						} catch (GetValueException) {
							name.Append(ResourceService.GetString("Global.NA"));
						}
					}
					if (i < frame.ArgumentCount - 1) {
						name.Append(", ");
					}
				}
				name.Append(')');
			}
			if (DebuggingOptions.Instance.ShowLineNumbers) {
				if (frame.NextStatement != null) {
					name.Append(':');
					name.Append(frame.NextStatement.StartLine.ToString());
				}
			}
			return name.ToString();
		}
Пример #8
0
		CallStackItem CreateItem(StackFrame frame, ref bool previousItemIsExternalMethod)
		{
			bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods;
			var symSource = WindowsDebugger.PdbSymbolSource;
			bool hasSymbols = symSource.Handles(frame.MethodInfo)
				&& !symSource.IsCompilerGenerated(frame.MethodInfo)
				&& frame.NextStatement != null && !string.IsNullOrWhiteSpace(frame.NextStatement.Filename);
			if (showExternalMethods || hasSymbols) {
				// Show the method in the list
				previousItemIsExternalMethod = false;
				return new CallStackItem() {
					Frame = frame,
					ImageSource = SD.ResourceService.GetImageSource("Icons.16x16.Method"),
					Name = GetFullName(frame, hasSymbols),
					HasSymbols = hasSymbols,
				};
			} else {
				// Show [External methods] in the list
				if (previousItemIsExternalMethod)
					return null;
				previousItemIsExternalMethod = true;
				return new CallStackItem() {
					Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods"),
					HasSymbols = false
				};
			}
		}
Пример #9
0
		public static Value Evaluate(INode code, StackFrame context, object data = null)
		{
			if (context == null) throw new ArgumentNullException("context");
			if (context.IsInvalid) throw new DebuggerException("The context is no longer valid");
			
			TypedValue val = new ExpressionEvaluator(context).Evaluate(code, false, data);
			if (val == null)
				return null;
			return val.Value;
		}
Пример #10
0
		/// <summary> Evaluate given expression.  If you have expression tree already, use overloads of this method.</summary>
		/// <returns> Returned value or null for statements </returns>
		public static Value Evaluate(string code, SupportedLanguage language, StackFrame context, object data = null)
		{
			return Evaluate(Parse(code, language), context, data);
		}
Пример #11
0
		ExpressionEvaluator(StackFrame context)
		{
			this.context = context;
		}
Пример #12
0
		void ShowDotCompletion(StackFrame frame, string currentText)
		{
			var binding = DebuggerDotCompletion.PrepareDotCompletion(currentText, new DebuggerCompletionContext(frame));
			if (binding == null) return;
			binding.HandleKeyPressed(console.TextEditor, '.');
			SD.ParserService.ParseFileAsync(new ICSharpCode.Core.FileName(frame.NextStatement.Filename)).FireAndForget();
		}
Пример #13
0
        void StepIntoUnknownFrame(StackFrame frame)
        {
            var debugType = (DebugType)frame.MethodInfo.DeclaringType;
            var key = frame.MethodInfo.ToMethodKey();
            var ip = frame.IP;

            var debugModule = debugType.DebugModule;
            DebugInformation.MustJumpToReference = false;
            if (!string.IsNullOrEmpty(debugModule.FullPath)) {
                var loadedMod = MainWindow.Instance.LoadAssembly(debugModule.AssemblyFullPath, debugModule.FullPath).ModuleDefinition as ModuleDefMD;
                if (loadedMod != null) {
                    DebugInformation.DebugStepInformation = Tuple.Create(key, ip.IsInvalid ? int.MaxValue : ip.Offset, loadedMod.ResolveToken(key.Token) as IMemberRef);
                    DebugInformation.MustJumpToReference = true;
                }
            }
            if (!DebugInformation.MustJumpToReference) {
                DebugInformation.DebugStepInformation = null;
                Debug.Fail("No type was found!");
            }
        }
Пример #14
0
		internal StackFrame GetStackFrameAt(uint chainIndex, uint frameIndex)
		{
			process.AssertPaused();
			
			ICorDebugChainEnum corChainEnum = CorThread.EnumerateChains();
			if (chainIndex >= corChainEnum.GetCount()) throw new DebuggerException("The requested chain index is too big");
			corChainEnum.Skip(corChainEnum.GetCount() - 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.GetCount()) throw new DebuggerException("The requested frame index is too big");
			corFrameEnum.Skip(corFrameEnum.GetCount() - 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, (ICorDebugILFrame)corFrame, chainIndex, frameIndex);
			
			return stackFrame;
		}
Пример #15
0
        // Stepping:
        SourceCodeMapping GetCurrentCodeMapping(Dictionary<MethodKey, MemberMapping> cm, out StackFrame frame, out bool isMatch, out bool methodExists)
        {
            isMatch = false;
            methodExists = false;
            frame = debuggedProcess.SelectedThread.MostRecentStackFrame;
            var key = frame.MethodInfo.ToMethodKey();

            // get the mapped instruction from the current line marker or the next one
            if (cm == null || !cm.ContainsKey(key))
                return null;
            methodExists = true;

            var ip = frame.IP;
            if (ip.IsInvalid)
                return null;

            return cm[key].GetInstructionByOffset((uint)ip.Offset, out isMatch);
        }
Пример #16
0
		public static Stepper StepOver(StackFrame stackFrame, int[] stepRanges, string name)
		{
			Stepper stepper = new Stepper(stackFrame, StepperOperation.StepOver, stepRanges, name, stackFrame.Process.Options.EnableJustMyCode);
			stepper.corStepper.StepRange(false /* step over */, stepRanges);
			return stepper;
		}
Пример #17
0
        // Stepping:

        SourceCodeMapping GetCurrentCodeMapping(Dictionary <MethodKey, MemberMapping> cm, out StackFrame frame, out bool isMatch, out bool methodExists)
        {
            isMatch      = false;
            methodExists = false;
            frame        = debuggedProcess.SelectedThread.MostRecentStackFrame;
            var key = frame.MethodInfo.ToMethodKey();

            // get the mapped instruction from the current line marker or the next one
            if (cm == null || !cm.ContainsKey(key))
            {
                return(null);
            }
            methodExists = true;

            var ip = frame.IP;

            if (ip.IsInvalid)
            {
                return(null);
            }

            return(cm[key].GetInstructionByOffset((uint)ip.Offset, out isMatch));
        }
Пример #18
0
		internal static string GetFullName(StackFrame frame)
		{
			bool showArgumentNames = DebuggingOptions.Instance.ShowArgumentNames;
			bool showArgumentValues = DebuggingOptions.Instance.ShowArgumentValues;
			bool showLineNumber = DebuggingOptions.Instance.ShowLineNumbers;
			bool showModuleNames = DebuggingOptions.Instance.ShowModuleNames;
			
			StringBuilder name = new StringBuilder();
			name.Append(frame.MethodInfo.DeclaringType.FullName);
			name.Append('.');
			name.Append(frame.MethodInfo.Name);
			if (showArgumentNames || showArgumentValues) {
				name.Append("(");
				for (int i = 0; i < frame.ArgumentCount; i++) {
					string parameterName = null;
					string argValue = null;
					if (showArgumentNames) {
						try {
							parameterName = frame.MethodInfo.GetParameters()[i].Name;
						} catch { }
						if (parameterName == "") parameterName = null;
					}
					if (showArgumentValues) {
						try {
							argValue = frame.GetArgumentValue(i).AsString(100);
						} catch { }
					}
					if (parameterName != null && argValue != null) {
						name.Append(parameterName);
						name.Append("=");
						name.Append(argValue);
					}
					if (parameterName != null && argValue == null) {
						name.Append(parameterName);
					}
					if (parameterName == null && argValue != null) {
						name.Append(argValue);
					}
					if (parameterName == null && argValue == null) {
						name.Append(ResourceService.GetString("Global.NA"));
					}
					if (i < frame.ArgumentCount - 1) {
						name.Append(", ");
					}
				}
				name.Append(")");
			}
			
			return name.ToString();
		}
Пример #19
0
		void StepIntoUnknownFrame(StackFrame frame)
		{
			string debuggeeVersion = frame.MethodInfo.DebugModule.Process.DebuggeeVersion.Substring(1, 3); // should retrieve 2.0, 3.0, 4.0
			var debugType = (DebugType)frame.MethodInfo.DeclaringType;
			int token = frame.MethodInfo.MetadataToken;
			int ilOffset = frame.IP;
			string fullName = debugType.FullNameWithoutGenericArguments;
			
			DebugInformation.LoadedAssemblies =  MainWindow.Instance.CurrentAssemblyList.GetAssemblies().Select(a => a.AssemblyDefinition);
			
			if (DebugInformation.LoadedAssemblies == null)
				throw new NullReferenceException("No DebugData assemblies!");
			else {
				// search for type in the current assembly list
				TypeDefinition typeDef = null;
				TypeDefinition nestedTypeDef = null;
				
				foreach (var assembly in DebugInformation.LoadedAssemblies) {
					if ((assembly.FullName.StartsWith("System") || assembly.FullName.StartsWith("Microsoft") || assembly.FullName.StartsWith("mscorlib")) &&
					    !assembly.Name.Version.ToString().StartsWith(debuggeeVersion))
						continue;
					
					foreach (var module in assembly.Modules) {
						var localType = module.GetType(fullName);
						if (localType != null) {
							if (localType.DeclaringType == null) {
								typeDef = localType;
							} else {
								nestedTypeDef = localType;
								typeDef = localType.DeclaringType;
							}
							break;
						}
					}
					if (typeDef != null)
						break;
				}
				
				if (typeDef != null) {
					TypeDefinition type = nestedTypeDef ?? typeDef;
					DebugInformation.DebugStepInformation = Tuple.Create(token, ilOffset, type.GetMemberByToken(token));
				} else {
					Debug.Assert(typeDef != null, "No type was found!");
				}
			}
		}
Пример #20
0
		public static Stepper StepOut(StackFrame stackFrame, string name)
		{
			// JMC off - Needed for multiple events. See docs\Stepping.txt
			Stepper stepper = new Stepper(stackFrame, StepperOperation.StepOut, null, name, false);
			stepper.corStepper.StepOut();
			return stepper;
		}
Пример #21
0
		CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool previousItemIsExternalMethod)
		{
			CallStackItem item;
			
			// line number
			string lineNumber = string.Empty;
			if (DebuggingOptions.Instance.ShowLineNumbers) {
				if (frame.NextStatement != null)
					lineNumber = frame.NextStatement.StartLine.ToString();
			}
			
			// show modules names
			string moduleName = string.Empty;
			if (DebuggingOptions.Instance.ShowModuleNames) {
				moduleName = frame.MethodInfo.DebugModule.ToString();
			}
			
			if (frame.HasSymbols || showExternalMethods) {
				// Show the method in the list
				
				item = new CallStackItem() {
					Name = GetFullName(frame), Language = "", Line = lineNumber, ModuleName = moduleName
				};
				previousItemIsExternalMethod = false;
				item.Frame = frame;
			} else {
				// Show [External methods] in the list
				if (previousItemIsExternalMethod) return null;
				item = new CallStackItem() {
					Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods"),
					Language = ""
				};
				previousItemIsExternalMethod = true;
			}
			
			return item;
		}
Пример #22
0
        internal static string GetFullName(StackFrame frame)
        {
            // disabled by default, my be switched if options / context menu is added
            bool showArgumentNames = DebuggerSettings.Instance.ShowArguments;
            bool showArgumentValues = DebuggerSettings.Instance.ShowArgumentValues;

            StringBuilder name = new StringBuilder();
            name.Append(frame.MethodInfo.DeclaringType.FullName);
            name.Append('.');
            name.Append(frame.MethodInfo.Name);
            if (showArgumentNames || showArgumentValues) {
                name.Append("(");
                for (int i = 0; i < frame.ArgumentCount; i++) {
                    string parameterName = null;
                    string argValue = null;
                    if (showArgumentNames) {
                        try {
                            parameterName = frame.MethodInfo.GetParameters()[i].Name;
                        } catch { }
                        if (parameterName == "") parameterName = null;
                    }
                    if (showArgumentValues) {
                        try {
                            argValue = frame.GetArgumentValue(i).AsString(100);
                        } catch { }
                    }
                    if (parameterName != null && argValue != null) {
                        name.Append(parameterName);
                        name.Append("=");
                        name.Append(argValue);
                    }
                    if (parameterName != null && argValue == null) {
                        name.Append(parameterName);
                    }
                    if (parameterName == null && argValue != null) {
                        name.Append(argValue);
                    }
                    if (parameterName == null && argValue == null) {
                        name.Append("Global.NA");
                    }
                    if (i < frame.ArgumentCount - 1) {
                        name.Append(", ");
                    }
                }
                name.Append(")");
            }

            return name.ToString();
        }
Пример #23
0
		void ShowDotCompletion(StackFrame frame, string currentText)
		{
			var fileName = new ICSharpCode.Core.FileName(frame.NextStatement.Filename);
			var textLocation = new TextLocation(frame.NextStatement.StartLine, frame.NextStatement.StartColumn);
			var binding = DebuggerDotCompletion.PrepareDotCompletion(currentText, SD.ParserService.ResolveContext(fileName, textLocation));
			if (binding == null) return;
			binding.HandleKeyPressed(console.TextEditor, '.');
		}
Пример #24
0
		// Stepping:
		
		SourceCodeMapping GetCurrentCodeMapping(out StackFrame frame, out bool isMatch)
		{
			isMatch = false;
			frame = debuggedProcess.SelectedThread.MostRecentStackFrame;
			int key = frame.MethodInfo.MetadataToken;
			
			// get the mapped instruction from the current line marker or the next one
			if (!DebugInformation.CodeMappings.ContainsKey(key))
				return null;
			
			return DebugInformation.CodeMappings[key].GetInstructionByTokenAndOffset(key, frame.IP, out isMatch);
		}
Пример #25
0
		/// <summary> Evaluate given expression.  If you have expression tree already, use overloads of this method.</summary>
		/// <returns> Returned value or null for statements </returns>
		public static Value Evaluate(string code, SupportedLanguage language, StackFrame context)
		{
			return Evaluate(Parse(code, language), context);
		}
Пример #26
0
		void ShowDotCompletion(StackFrame frame, string currentText)
		{
			var seg = frame.NextStatement;
			if (seg == null)
				return;
			#warning reimplement this!
//			var expressionFinder = ParserService.GetExpressionFinder(seg.Filename);
//			var info = ParserService.GetParseInformation(seg.Filename);
//			
//			string text = ParserService.GetParseableFileContent(seg.Filename).Text;
//			
//			int currentOffset = TextEditor.Caret.Offset - console.CommandOffset - 1;
//			
//			var expr = expressionFinder.FindExpression(currentText, currentOffset);
//			
//			expr.Region = new DomRegion(seg.StartLine, seg.StartColumn, seg.EndLine, seg.EndColumn);
//			
//			var rr = resolver.Resolve(expr, info, text);
//			
//			if (rr != null) {
//				TextEditor.ShowCompletionWindow(new DotCodeCompletionItemProvider().GenerateCompletionListForResolveResult(rr, expr.Context));
//			}
		}
Пример #27
0
		void ShowDotCompletion(StackFrame frame, string currentText)
		{
			var binding = DebuggerDotCompletion.PrepareDotCompletion(currentText, frame);
			if (binding == null) return;
			binding.HandleKeyPressed(console.TextEditor, '.');
		}