Example #1
0
 static void WriteText(IDbgTextWriter output, string text)
 {
     output.Write(DbgTextColor.Text, " ");
     output.Write(DbgTextColor.Punctuation, "(");
     output.Write(DbgTextColor.Text, text);
     output.Write(DbgTextColor.Punctuation, ")");
 }
        public override bool WriteName(IDbgTextWriter writer, DbgExceptionDefinition definition)
        {
            var fullName = definition.Id.Name;

            if (!string2.IsNullOrEmpty(fullName))
            {
                var nsParts   = fullName.Split(nsSeps);
                int pos       = 0;
                var partColor = DbgTextColor.Namespace;
                for (int i = 0; i < nsParts.Length - 1; i++)
                {
                    var ns  = nsParts[i];
                    var sep = fullName[pos + ns.Length];
                    if (sep == '+')
                    {
                        partColor = DbgTextColor.Type;
                    }
                    writer.Write(partColor, ns);
                    writer.Write(DbgTextColor.Operator, sep.ToString());
                    pos += ns.Length + 1;
                }
                writer.Write(DbgTextColor.Type, nsParts[nsParts.Length - 1]);
            }
            return(true);
        }
Example #3
0
        public void WriteConditions(IDbgTextWriter output, ExceptionVM vm)
        {
            var conditions = vm.Settings.Conditions;

            for (int i = 0; i < conditions.Count; i++)
            {
                if (i != 0)
                {
                    output.Write(DbgTextColor.Text, " ");
                    output.Write(DbgTextColor.Keyword, dnSpy_Debugger_Resources.Exception_Conditions_And);
                    output.Write(DbgTextColor.Text, " ");
                }
                var cond = conditions[i];
                switch (cond.ConditionType)
                {
                case DbgExceptionConditionType.ModuleNameEquals:
                    WriteQuotedString(output, dnSpy_Debugger_Resources.Exception_Conditions_ModuleNameEquals, cond.Condition);
                    break;

                case DbgExceptionConditionType.ModuleNameNotEquals:
                    WriteQuotedString(output, dnSpy_Debugger_Resources.Exception_Conditions_ModuleNameNotEquals, cond.Condition);
                    break;

                default:
                    WriteError(output);
                    break;
                }
            }
        }
        public override void WriteToolTip(IDbgTextWriter output, DbgCodeBreakpointCondition condition)
        {
            if (output is null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            var defaultColor = DbgTextColor.Text;

            output.Write(defaultColor, dnSpy_Debugger_Resources.Breakpoint_Condition_ConditionalExpression);
            output.Write(DbgTextColor.Text, " ");
            switch (condition.Kind)
            {
            case DbgCodeBreakpointConditionKind.IsTrue:
                WriteArgumentAndText(output, defaultColor, DbgTextColor.String, dnSpy_Debugger_Resources.Breakpoint_Condition_WhenConditionIsTrue2, condition.Condition);
                break;

            case DbgCodeBreakpointConditionKind.WhenChanged:
                WriteArgumentAndText(output, defaultColor, DbgTextColor.String, dnSpy_Debugger_Resources.Breakpoint_Condition_WhenConditionHasChanged2, condition.Condition);
                break;

            default:
                Debug.Fail($"Unknown kind: {condition.Kind}");
                break;
            }
        }
 public override bool TryFormat(DbgEvaluationContext context, IDbgTextWriter output, DbgStackFrameFormatterOptions options, DbgValueFormatterOptions valueOptions, CultureInfo cultureInfo, CancellationToken cancellationToken)
 {
     output.Write(DbgTextColor.Punctuation, "[");
     output.Write(DbgTextColor.Text, name);
     output.Write(DbgTextColor.Punctuation, "]");
     return(true);
 }
Example #6
0
 void WriteDescription(IDbgTextWriter writer, DbgExceptionDefinition definition)
 {
     if (definition.Description is null)
     {
         return;
     }
     writer.Write(DbgTextColor.Comment, "(");
     writer.Write(DbgTextColor.Comment, definition.Description);
     writer.Write(DbgTextColor.Comment, ")");
 }
 void WriteCurrentHitCountValue(IDbgTextWriter output, int?currentHitCount)
 {
     if (currentHitCount is not null)
     {
         output.Write(DbgTextColor.Comment, " ");
         output.Write(DbgTextColor.Punctuation, "(");
         WriteArgumentAndText(output, DbgTextColor.Number, dnSpy_Debugger_Resources.Breakpoint_HitCount_CurrentHitCountValue, currentHitCount.Value.ToString());
         output.Write(DbgTextColor.Punctuation, ")");
     }
 }
Example #8
0
 public override void FormatReturnValueName(DbgEvaluationContext context, IDbgTextWriter output, uint id)
 {
     if (id == 0)
     {
         output.Write(DbgTextColor.ReturnValueName, AliasConstants.ReturnValueName);
     }
     else
     {
         output.Write(DbgTextColor.ReturnValueName, AliasConstants.ReturnValueName + id.ToString());
     }
 }
Example #9
0
 void WriteILOffset(IDbgTextWriter output, uint offset)
 {
     // Offsets are always in hex
     if (offset <= ushort.MaxValue)
     {
         output.Write(DbgTextColor.Number, GetHexPrefix() + offset.ToString("X4"));
     }
     else
     {
         output.Write(DbgTextColor.Number, GetHexPrefix() + offset.ToString("X8"));
     }
 }
Example #10
0
        public void WriteType(IDbgTextWriter output, ValueNode vm)
        {
            vm.CachedExpectedType.WriteTo(output);
            var cachedActualType = vm.CachedActualType_OrDefaultInstance;

            // If it's default, expected type == actual type
            if (!cachedActualType.IsDefault)
            {
                output.Write(DbgTextColor.Text, " ");
                output.Write(DbgTextColor.Error, "{");
                cachedActualType.WriteTo(output);
                output.Write(DbgTextColor.Error, "}");
            }
        }
        protected override void FormatReturnValueMethodName(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgValueFormatterTypeOptions typeOptions, DbgValueFormatterOptions valueOptions, CultureInfo cultureInfo, DmdMethodBase method, DmdPropertyInfo property)
        {
            var typeFormatter = new Formatters.CSharp.CSharpTypeFormatter(output, typeOptions.ToTypeFormatterOptions(), null);

            typeFormatter.Format(method.DeclaringType, null);
            var valueFormatter = new Formatters.CSharp.CSharpPrimitiveValueFormatter(output, valueOptions.ToValueFormatterOptions(), cultureInfo);

            output.Write(DbgTextColor.Operator, ".");
            if ((object)property != null)
            {
                if (property.GetIndexParameters().Count != 0)
                {
                    output.Write(DbgTextColor.Keyword, Keyword_this);
                    WriteMethodParameterList(output, method, typeFormatter, GetAllMethodParameterTypes(property.GetMethodSignature()), IndexerParenOpen, IndexerParenClose);
                }
                else
                {
                    output.Write(MemberUtils.GetColor(property), Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(property.Name));
                }
                valueFormatter.WriteTokenComment(property.MetadataToken);
                output.Write(DbgTextColor.Operator, ".");
                output.Write(DbgTextColor.Keyword, "get");
                valueFormatter.WriteTokenComment(method.MetadataToken);
            }
            else
            {
                var methodColor = TypeFormatterUtils.GetColor(method, canBeModule: false);
                if (TypeFormatterUtils.TryGetMethodName(method.Name, out var containingMethodName, out var localFunctionName))
                {
                    output.Write(methodColor, Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(containingMethodName));
                    output.Write(DbgTextColor.Operator, ".");
                    output.Write(methodColor, Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(localFunctionName));
                    valueFormatter.WriteTokenComment(method.MetadataToken);
                    WriteGenericMethodArguments(output, method, typeFormatter);
                }
Example #12
0
        internal void WriteLabels(IDbgTextWriter output, CodeBreakpointVM vm)
        {
            bool needSep = false;

            foreach (var label in vm.CodeBreakpoint.Labels ?? emptyLabels)
            {
                if (needSep)
                {
                    output.Write(DbgTextColor.Text, LabelsSeparatorString);
                    output.Write(DbgTextColor.Text, " ");
                }
                needSep = true;
                output.Write(DbgTextColor.Text, label);
            }
        }
 public override void FormatArrayName(IDbgTextWriter output, int[] indexes)
 {
     Debug.Assert(indexes.Length > 0);
     output.Write(DbgTextColor.Punctuation, ARRAY_PAREN_OPEN);
     for (int i = 0; i < indexes.Length; i++)
     {
         if (i > 0)
         {
             output.Write(DbgTextColor.Punctuation, ",");
             output.Write(DbgTextColor.Text, " ");
         }
         output.Write(DbgTextColor.Number, indexes[i].ToString());
     }
     output.Write(DbgTextColor.Punctuation, ARRAY_PAREN_CLOSE);
 }
Example #14
0
        void DefaultWriteName(IDbgTextWriter output, DbgExceptionDefinition definition)
        {
            switch (definition.Id.Kind)
            {
            case DbgExceptionIdKind.DefaultId:
                if (exceptionSettingsService.Value.TryGetCategoryDefinition(definition.Id.Category, out var categoryDef))
                {
                    output.Write(DbgTextColor.Text, string.Format(dnSpy_Debugger_Resources.AllRemainingExceptionsNotInList, categoryDef.DisplayName));
                }
                else
                {
                    WriteError(output);
                }
                break;

            case DbgExceptionIdKind.Code:
                DbgExceptionCategoryDefinitionFlags flags;
                if (exceptionSettingsService.Value.TryGetCategoryDefinition(definition.Id.Category, out categoryDef))
                {
                    flags = categoryDef.Flags;
                }
                else
                {
                    flags = DbgExceptionCategoryDefinitionFlags.None;
                }
                if ((flags & DbgExceptionCategoryDefinitionFlags.DecimalCode) == 0)
                {
                    output.Write(DbgTextColor.Number, "0x" + definition.Id.Code.ToString("X8"));
                }
                else if ((flags & DbgExceptionCategoryDefinitionFlags.UnsignedCode) != 0)
                {
                    output.Write(DbgTextColor.Number, ((uint)definition.Id.Code).ToString());
                }
                else
                {
                    output.Write(DbgTextColor.Number, definition.Id.Code.ToString());
                }
                break;

            case DbgExceptionIdKind.Name:
                output.Write(DbgTextColor.Keyword, definition.Id.Name);
                break;

            default:
                WriteError(output);
                break;
            }
        }
        bool Format(DbgDotNetValue value, TypeState typeState, DisplayPart[] displayParts)
        {
            if (displayParts.Length == 0)
            {
                return(false);
            }

            var evaluator = evalInfo.Context.GetDebuggerDisplayAttributeEvaluator();

            foreach (var part in displayParts)
            {
                if ((part.Flags & DisplayPartFlags.EvaluateText) == 0)
                {
                    output.Write(DbgTextColor.DebuggerDisplayAttributeEval, part.Text);
                }
                else
                {
                    var eeState = typeState.GetExpressionEvaluatorState(evalInfo.Context.Language.ExpressionEvaluator, part.Text);
                    DbgDotNetEvalResult evalRes = default;
                    try {
                        var evalInfo2 = new DbgEvaluationInfo(typeState.TypeContext !, evalInfo.Frame, evalInfo.CancellationToken);
                        evalRes = evaluator.Evaluate(evalInfo2, value, part.Text, DbgEvaluationOptions.Expression, eeState);
                        if (evalRes.Error is not null)
                        {
                            output.Write(DbgTextColor.Error, "<<<");
                            output.Write(DbgTextColor.Error, evalRes.Error);
                            output.Write(DbgTextColor.Error, ">>>");
                        }
                        else
                        {
                            // Prevent recursive calls
                            var options = this.options | DbgValueFormatterOptions.NoDebuggerDisplay;
                            options &= ~DbgValueFormatterOptions.NoStringQuotes;
                            options  = PredefinedFormatSpecifiers.GetValueFormatterOptions(evalRes.FormatSpecifiers, options);
                            languageFormatter.FormatValue(evalInfo, output, evalRes.Value !, options, cultureInfo);
                        }
                    }
                    finally {
                        if (evalRes.Value != value)
                        {
                            evalRes.Value?.Dispose();
                        }
                    }
                }
            }

            return(true);
        }
        protected override void FormatReturnValueMethodName(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgValueFormatterTypeOptions typeOptions, DbgValueFormatterOptions valueOptions, CultureInfo?cultureInfo, DmdMethodBase method, DmdPropertyInfo?property)
        {
            var typeFormatter = new Formatters.VisualBasic.VisualBasicTypeFormatter(output, typeOptions.ToTypeFormatterOptions(), null);

            typeFormatter.Format(method.DeclaringType !, null);
            var valueFormatter = new Formatters.VisualBasic.VisualBasicPrimitiveValueFormatter(output, valueOptions.ToValueFormatterOptions(), cultureInfo);

            output.Write(DbgTextColor.Operator, ".");
            if (!(property is null))
            {
                output.Write(MemberUtils.GetColor(property), Formatters.VisualBasic.VisualBasicTypeFormatter.GetFormattedIdentifier(property.Name));
                valueFormatter.WriteTokenComment(property.MetadataToken);
                output.Write(DbgTextColor.Operator, ".");
                output.Write(DbgTextColor.Keyword, "Get");
                valueFormatter.WriteTokenComment(method.MetadataToken);
            }
        public override void Write(IDbgTextWriter output, DbgCodeBreakpointCondition?condition)
        {
            if (output is null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (condition is null)
            {
                output.Write(DbgTextColor.Text, dnSpy_Debugger_Resources.Breakpoint_Condition_NoCondition);
            }
            else
            {
                switch (condition.Value.Kind)
                {
                case DbgCodeBreakpointConditionKind.IsTrue:
                    WriteArgumentAndText(output, DbgTextColor.String, dnSpy_Debugger_Resources.Breakpoint_Condition_WhenConditionIsTrue, condition.Value.Condition);
                    break;

                case DbgCodeBreakpointConditionKind.WhenChanged:
                    WriteArgumentAndText(output, DbgTextColor.String, dnSpy_Debugger_Resources.Breakpoint_Condition_WhenConditionHasChanged, condition.Value.Condition);
                    break;

                default:
                    Debug.Fail($"Unknown kind: {condition.Value.Kind}");
                    break;
                }
            }
        }
        public override void Write(IDbgTextWriter output, DbgCodeBreakpointHitCount?hitCount, int?currentHitCount)
        {
            if (output is null)
            {
                throw new ArgumentNullException(nameof(output));
            }
            if (hitCount is null)
            {
                output.Write(DbgTextColor.Text, dnSpy_Debugger_Resources.Breakpoint_HitCount_NoHitCount);
            }
            else
            {
                switch (hitCount.Value.Kind)
                {
                case DbgCodeBreakpointHitCountKind.Equals:
                    WriteArgumentAndText(output, DbgTextColor.Number, dnSpy_Debugger_Resources.Breakpoint_HitCount_HitCountIsEqualTo, hitCount.Value.Count.ToString());
                    break;

                case DbgCodeBreakpointHitCountKind.MultipleOf:
                    WriteArgumentAndText(output, DbgTextColor.Number, dnSpy_Debugger_Resources.Breakpoint_HitCount_HitCountIsAMultipleOf, hitCount.Value.Count.ToString());
                    break;

                case DbgCodeBreakpointHitCountKind.GreaterThanOrEquals:
                    WriteArgumentAndText(output, DbgTextColor.Number, dnSpy_Debugger_Resources.Breakpoint_HitCount_HitCountIsGreaterThanOrEqualTo, hitCount.Value.Count.ToString());
                    break;

                default:
                    Debug.Fail($"Unknown kind: {hitCount.Value.Kind}");
                    break;
                }
            }
            WriteCurrentHitCountValue(output, currentHitCount);
        }
        protected override void FormatPropertyName(IDbgTextWriter output, DmdPropertyInfo property)
        {
            var name  = Formatters.VisualBasic.VisualBasicTypeFormatter.GetFormattedIdentifier(property.Name);
            var color = MemberUtils.GetColor(property);

            output.Write(color, name);
        }
        protected override void FormatFieldName(IDbgTextWriter output, DmdFieldInfo field)
        {
            var name  = Formatters.VisualBasic.VisualBasicTypeFormatter.GetFormattedIdentifier(field.Name);
            var color = MemberUtils.GetColor(field);

            output.Write(color, name);
        }
 void WriteInt32Decimal(IDbgTextWriter output, int?value)
 {
     if (value == null)
     {
         return;
     }
     output.Write(DbgTextColor.Number, value.Value.ToString());
 }
Example #22
0
 public void WriteExpander(IDbgTextWriter output, ValueNode vm)
 {
     if (vm.TreeNode.LazyLoading)
     {
         output.Write(DbgTextColor.Text, "+");
     }
     else if (vm.TreeNode.Children.Count == 0)
     {
         // VS prints nothing
     }
     else if (vm.TreeNode.IsExpanded)
     {
         output.Write(DbgTextColor.Text, "-");
     }
     else
     {
         output.Write(DbgTextColor.Text, "+");
     }
 }
Example #23
0
 public void WriteCategory(IDbgTextWriter output, ExceptionVM vm)
 {
     if (vm.Context.ExceptionSettingsService.TryGetCategoryDefinition(vm.Definition.Id.Category, out var def))
     {
         output.Write(DbgTextColor.Text, def.DisplayName);
     }
     else
     {
         WriteError(output);
     }
 }
Example #24
0
        public void WriteObjectId(IDbgTextWriter output, ValueNode vm)
        {
            Debug.Assert(!(ObjectIdService is null));
            if (ObjectIdService is null)
            {
                return;
            }
            var vmImpl = (ValueNodeImpl)vm;

            if (vmImpl.RawNode is DebuggerValueRawNode rawNode)
            {
                var language = Language;
                Debug.Assert(!(language is null));
                if (language is null)
                {
                    return;
                }
                var value = rawNode.DebuggerValueNode.Value;
                if (value is null)
                {
                    return;
                }
                var objectId = ObjectIdService.GetObjectId(value);
                if (!(objectId is null))
                {
                    output.Write(DbgTextColor.Text, " ");
                    output.Write(DbgTextColor.Punctuation, "{");
                    var evalInfo = vmImpl.Context.EvaluationInfo;
                    Debug.Assert(!(evalInfo is null));
                    if (evalInfo is null)
                    {
                        output.Write(DbgTextColor.Error, "???");
                    }
                    else
                    {
                        language.Formatter.FormatObjectIdName(evalInfo.Context, output, objectId.Id);
                    }
                    output.Write(DbgTextColor.Punctuation, "}");
                }
            }
        }
Example #25
0
 void WriteLocation(IDbgTextWriter output, DbgCodeBreakpoint breakpoint, ITextView textView, SnapshotSpan span)
 {
     foreach (var lz in dbgBreakpointGlyphFormatters)
     {
         if (lz.Value.WriteLocation(output, breakpoint, textView, span))
         {
             return;
         }
     }
     Debug.Fail("Missing BP location writer");
     output.Write(DbgTextColor.Error, "???");
 }
Example #26
0
        protected override void FormatReturnValueMethodName(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgValueFormatterTypeOptions typeOptions, DbgValueFormatterOptions valueOptions, CultureInfo?cultureInfo, DmdMethodBase method, DmdPropertyInfo?property)
        {
            var typeFormatter = new Formatters.VisualBasic.VisualBasicTypeFormatter(output, typeOptions.ToTypeFormatterOptions(), null);

            typeFormatter.Format(method.DeclaringType !, null);
            var valueFormatter = new Formatters.VisualBasic.VisualBasicPrimitiveValueFormatter(output, valueOptions.ToValueFormatterOptions(), cultureInfo);

            output.Write(DbgTextColor.Operator, ".");
            if (property is not null)
            {
                output.Write(MemberUtils.GetColor(property), Formatters.VisualBasic.VisualBasicTypeFormatter.GetFormattedIdentifier(property.Name));
                valueFormatter.WriteTokenComment(property.MetadataToken);
                output.Write(DbgTextColor.Operator, ".");
                output.Write(DbgTextColor.Keyword, "Get");
                valueFormatter.WriteTokenComment(method.MetadataToken);
            }
            else
            {
                var operatorInfo = Formatters.VisualBasic.Operators.TryGetOperatorInfo(method.Name);
                if (operatorInfo is not null && method is DmdMethodInfo methodInfo)
                {
                    for (int i = 0; i < operatorInfo.Length; i++)
                    {
                        if (i > 0)
                        {
                            output.Write(DbgTextColor.Text, " ");
                        }
                        var s = operatorInfo[i];
                        output.Write('A' <= s[0] && s[0] <= 'Z' ? DbgTextColor.Keyword : DbgTextColor.Operator, s);
                    }
                    WriteGenericMethodArguments(output, method, typeFormatter);
                }
        void WriteArgumentAndText(IDbgTextWriter output, DbgTextColor defaultColor, string formatString, Action callback)
        {
            const string pattern = "{0}";
            var          index   = formatString.IndexOf(pattern);

            if (index < 0)
            {
                output.Write(DbgTextColor.Error, "???");
            }
            else
            {
                if (index != 0)
                {
                    output.Write(defaultColor, formatString.Substring(0, index));
                }
                callback();
                if (index + pattern.Length != formatString.Length)
                {
                    output.Write(defaultColor, formatString.Substring(index + pattern.Length));
                }
            }
        }
 public override void Write(IDbgTextWriter output, DbgCodeBreakpointFilter?filter)
 {
     if (output is null)
     {
         throw new ArgumentNullException(nameof(output));
     }
     if (filter is null)
     {
         output.Write(DbgTextColor.Text, dnSpy_Debugger_Resources.Breakpoint_Filter_NoFilter);
     }
     else
     {
         dbgFilterExpressionEvaluatorService.Value.Write(output, filter.Value.Filter ?? string.Empty);
     }
 }
        public override bool FormatName(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgDotNetFormatter formatter, DbgValueFormatterOptions options, CultureInfo?cultureInfo)
        {
            var          formatString = dnSpy_Roslyn_Resources.LocalsWindow_MethodOrProperty_Returned;
            const string pattern      = "{0}";
            int          index        = formatString.IndexOf(pattern);

            Debug.Assert(index >= 0);
            if (index < 0)
            {
                formatString = "{0} returned";
                index        = formatString.IndexOf(pattern);
            }

            if (index != 0)
            {
                output.Write(DbgTextColor.Text, formatString.Substring(0, index));
            }
            owner.FormatReturnValueMethodName(evalInfo, output, options, cultureInfo, method);
            if (index + pattern.Length != formatString.Length)
            {
                output.Write(DbgTextColor.Text, formatString.Substring(index + pattern.Length));
            }
            return(true);
        }
Example #30
0
        protected override void FormatReturnValueMethodName(DbgEvaluationInfo evalInfo, IDbgTextWriter output, DbgValueFormatterTypeOptions typeOptions, DbgValueFormatterOptions valueOptions, CultureInfo?cultureInfo, DmdMethodBase method, DmdPropertyInfo?property)
        {
            var typeFormatter = new Formatters.CSharp.CSharpTypeFormatter(output, typeOptions.ToTypeFormatterOptions(), null);

            typeFormatter.Format(method.DeclaringType !, null);
            var valueFormatter = new Formatters.CSharp.CSharpPrimitiveValueFormatter(output, valueOptions.ToValueFormatterOptions(), cultureInfo);

            output.Write(DbgTextColor.Operator, ".");
            if (!(property is null))
            {
                if (property.GetIndexParameters().Count != 0)
                {
                    output.Write(DbgTextColor.Keyword, Keyword_this);
                    WriteMethodParameterList(output, method, typeFormatter, GetAllMethodParameterTypes(property.GetMethodSignature()), IndexerParenOpen, IndexerParenClose);
                }
                else
                {
                    output.Write(MemberUtils.GetColor(property), Formatters.CSharp.CSharpTypeFormatter.GetFormattedIdentifier(property.Name));
                }
                valueFormatter.WriteTokenComment(property.MetadataToken);
                output.Write(DbgTextColor.Operator, ".");
                output.Write(DbgTextColor.Keyword, "get");
                valueFormatter.WriteTokenComment(method.MetadataToken);
            }