IEnumerable<TreeNode> LazyGetChildNodes() { foreach(DebugParameterInfo par in stackFrame.MethodInfo.GetParameters()) { string imageName; var image = ExpressionNode.GetImageForParameter(out imageName); var expression = new ExpressionNode(image, par.Name, par.GetExpression()); expression.ImageName = imageName; yield return expression; } if (this.stackFrame.HasSymbols) { foreach(DebugLocalVariableInfo locVar in stackFrame.MethodInfo.GetLocalVariables(this.StackFrame.IP)) { string imageName; var image = ExpressionNode.GetImageForLocalVariable(out imageName); var expression = new ExpressionNode(image, locVar.Name, locVar.GetExpression()); expression.ImageName = imageName; yield return expression; } } else { WindowsDebugger debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; if (debugger.debuggerDecompilerService != null) { int typeToken = this.stackFrame.MethodInfo.DeclaringType.MetadataToken; int methodToken = this.stackFrame.MethodInfo.MetadataToken; foreach (var localVar in debugger.debuggerDecompilerService.GetLocalVariables(typeToken, methodToken)) { string imageName; var image = ExpressionNode.GetImageForLocalVariable(out imageName); var expression = new ExpressionNode(image, localVar, ExpressionEvaluator.ParseExpression(localVar, SupportedLanguage.CSharp)); expression.ImageName = imageName; yield return expression; } } } if (stackFrame.Thread.CurrentException != null) { yield return new ExpressionNode(null, "__exception", new IdentifierExpression("__exception")); } }
IEnumerable<TreeNode> LazyGetChildNodes() { foreach(DebugParameterInfo par in stackFrame.MethodInfo.GetParameters()) { string imageName; var image = ExpressionNode.GetImageForParameter(out imageName); var expression = new ExpressionNode(image, par.Name, par.GetExpression()); expression.ImageName = imageName; yield return expression; } foreach(DebugLocalVariableInfo locVar in stackFrame.MethodInfo.GetLocalVariables(this.StackFrame.IP)) { string imageName; var image = ExpressionNode.GetImageForLocalVariable(out imageName); var expression = new ExpressionNode(image, locVar.Name, locVar.GetExpression()); expression.ImageName = imageName; yield return expression; } if (stackFrame.Thread.CurrentException != null) { yield return new ExpressionNode(null, "__exception", new IdentifierExpression("__exception")); } }
public ITreeNode GetNode(string variable, string currentImageName = null) { try { var expression = GetExpression(variable); string imageName; IImage image; if (string.IsNullOrEmpty(currentImageName)) { image = ExpressionNode.GetImageForLocalVariable(out imageName); } else { image = new ResourceServiceImage(currentImageName); imageName = currentImageName; } ExpressionNode expressionNode = new ExpressionNode(image, variable, expression); expressionNode.ImageName = imageName; return expressionNode; } catch (GetValueException) { return null; } }
/// <summary> /// Gets the tooltip control that shows the value of given variable. /// Return null if no tooltip is available. /// </summary> public object GetTooltipControl(Location logicalPosition, string variableName) { try { var tooltipExpression = GetExpression(variableName); string imageName; var image = ExpressionNode.GetImageForLocalVariable(out imageName); ExpressionNode expressionNode = new ExpressionNode(image, variableName, tooltipExpression); expressionNode.ImageName = imageName; return new DebuggerTooltipControl(logicalPosition, expressionNode) { ShowPins = !IsInExternalCode }; } catch (GetValueException) { return null; } }
public override void RefreshPad() { if (debuggedProcess == null || debuggedProcess.IsRunning) return; using(new PrintTimes("Watch Pad refresh")) { try { Utils.DoEvents(debuggedProcess); List<TreeNode> nodes = new List<TreeNode>(); foreach (var node in watchList.WatchItems) { try { LoggingService.Info("Evaluating: " + (string.IsNullOrEmpty(node.Name) ? "is null or empty!" : node.Name)); var nodExpression = debugger.GetExpression(node.Name); //Value val = ExpressionEvaluator.Evaluate(nod.Name, nod.Language, debuggedProcess.SelectedStackFrame); ExpressionNode valNode = new ExpressionNode(null, node.Name, nodExpression); nodes.Add(valNode); } catch (GetValueException) { string error = String.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.Watch.InvalidExpression}"), node.Name); ErrorInfoNode infoNode = new ErrorInfoNode(node.Name, error); nodes.Add(infoNode); } } // rebuild list watchList.WatchItems.Clear(); foreach (var node in nodes) watchList.WatchItems.Add(node); } catch(AbortedBecauseDebuggeeResumedException) { } catch(Exception ex) { if (debuggedProcess == null || debuggedProcess.HasExited) { // Process unexpectedly exited } else { MessageService.ShowException(ex); } } } }
TreeNodeWrapper UpdateNode(TreeNodeWrapper node) { try { LoggingService.Info("Evaluating: " + (string.IsNullOrEmpty(node.Node.Name) ? "is null or empty!" : node.Node.Name)); var nodExpression = debugger.GetExpression(node.Node.Name); //Value val = ExpressionEvaluator.Evaluate(nod.Name, nod.Language, debuggedProcess.SelectedStackFrame); ExpressionNode valNode = new ExpressionNode(null, null, node.Node.Name, nodExpression); return valNode.ToSharpTreeNode(); } catch (GetValueException) { string error = String.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.Watch.InvalidExpression}"), node.Node.Name); ErrorInfoNode infoNode = new ErrorInfoNode(node.Node.Name, error); return infoNode.ToSharpTreeNode(); } }
/// <summary> /// Gets the tooltip control that shows the value of given variable. /// Return null if no tooltip is available. /// </summary> public object GetTooltipControl(Location logicalPosition, string variableName) { try { var tooltipExpression = GetExpression(variableName); string imageName; var image = ExpressionNode.GetImageForLocalVariable(out imageName); ExpressionNode expressionNode = new ExpressionNode(null, image, variableName, tooltipExpression); expressionNode.ImageName = imageName; return new DebuggerTooltipControl(logicalPosition, expressionNode) { ShowPins = debuggedProcess.GetCurrentExecutingFrame().HasSymbols }; } catch (System.Exception ex) { LoggingService.Error("Error on GetTooltipControl: " + ex.Message); return null; } }
public static IEnumerable<TreeNode> LazyGetMembersOfObject(TreeNode parent, Expression expression, MemberInfo[] members) { List<TreeNode> nodes = new List<TreeNode>(); foreach(MemberInfo memberInfo in members) { string imageName; var image = ExpressionNode.GetImageForMember((IDebugMemberInfo)memberInfo, out imageName); var exp = new ExpressionNode(parent, image, memberInfo.Name, expression.AppendMemberReference((IDebugMemberInfo)memberInfo)); exp.ImageName = imageName; nodes.Add(exp); } nodes.Sort(); return nodes; }
public static IEnumerable<TreeNode> LazyGetItemsOfIList(TreeNode parent, Expression targetObject) { // Add a cast, so that we are sure the expression has an indexer. // (The expression can be e.g. of type 'object' but its value is a List. // Without the cast, evaluating "expr[i]" would fail, because object does not have an indexer). targetObject = targetObject.CastToIList(); int count = 0; GetValueException error = null; try { count = targetObject.GetIListCount(); } catch (GetValueException e) { // Cannot yield a value in the body of a catch clause (CS1631) error = e; } if (error != null) { yield return new TreeNode(null, "(error)", error.Message, null, null, null); } else if (count == 0) { yield return new TreeNode(null, "(empty)", null, null, null, null); } else { for(int i = 0; i < count; i++) { string imageName; var image = ExpressionNode.GetImageForArrayIndexer(out imageName); var itemNode = new ExpressionNode(parent, image, "[" + i + "]", targetObject.AppendIndexer(i)); itemNode.ImageName = imageName; yield return itemNode; } } }
IEnumerable<TreeNode> LazyGetChildren() { // The whole array is small - just add all elements as childs if (bounds.TotalElementCount <= MaxElementCount) { foreach(int[] indices in bounds.Indices) { string imageName; var image = ExpressionNode.GetImageForArrayIndexer(out imageName); var expression = new ExpressionNode(this, image, GetName(indices), arrayTarget.AppendIndexer(indices)); expression.ImageName = imageName; yield return expression; } yield break; } // Find a dimension of size at least 2 int splitDimensionIndex = bounds.Count - 1; for(int i = 0; i < bounds.Count; i++) { if (bounds[i].Count > 1) { splitDimensionIndex = i; break; } } ArrayDimension splitDim = bounds[splitDimensionIndex]; // Split the dimension int elementsPerSegment = 1; while (splitDim.Count > elementsPerSegment * MaxElementCount) { elementsPerSegment *= MaxElementCount; } for(int i = splitDim.LowerBound; i <= splitDim.UpperBound; i += elementsPerSegment) { List<ArrayDimension> newDims = new List<ArrayDimension>(bounds); newDims[splitDimensionIndex] = new ArrayDimension(i, Math.Min(i + elementsPerSegment - 1, splitDim.UpperBound)); yield return new ArrayRangeNode(this, arrayTarget, new ArrayDimensions(newDims), originalBounds); } yield break; }
public static IEnumerable<TreeNode> LazyGetItemsOfIList(Expression targetObject) { // This is needed for expanding IEnumerable<T> targetObject = new CastExpression( new TypeReference(typeof(IList).FullName), targetObject, CastType.Cast ); int count = 0; GetValueException error = null; try { count = GetIListCount(targetObject); } catch (GetValueException e) { // Cannot yield a value in the body of a catch clause (CS1631) error = e; } if (error != null) { yield return new TreeNode(null, "(error)", error.Message, null, null); } else if (count == 0) { yield return new TreeNode(null, "(empty)", null, null, null); } else { for(int i = 0; i < count; i++) { string imageName; var image = ExpressionNode.GetImageForArrayIndexer(out imageName); var expression = new ExpressionNode(image, "[" + i + "]", targetObject.AppendIndexer(i)); expression.ImageName = imageName; yield return expression; } } }