Beispiel #1
0
        public override void WriteName(IDbgTextWriter output, DbgBreakpointLocationFormatterOptions options)
        {
            bool printedToken = false;

            if ((options & DbgBreakpointLocationFormatterOptions.Tokens) != 0)
            {
                WriteToken(output, location.Token);
                output.Write(DbgTextColor.Text, " ");
                printedToken = true;
            }

            var method = weakMethod?.Target as MethodDef ?? owner.GetDefinition <MethodDef>(location.Module, location.Token);

            if (method is null)
            {
                if (printedToken)
                {
                    output.Write(DbgTextColor.Error, "???");
                }
                else
                {
                    WriteToken(output, location.Token);
                }
            }
            else
            {
                if (weakMethod?.Target != method)
                {
                    weakMethod = new WeakReference(method);
                }
                owner.MethodDecompiler.Write(new DbgTextColorWriter(output), method, GetFormatterOptions(options));
            }

            switch (location.ILOffsetMapping)
            {
            case DbgILOffsetMapping.Exact:
            case DbgILOffsetMapping.Approximate:
                output.Write(DbgTextColor.Text, " ");
                output.Write(DbgTextColor.Operator, "+");
                output.Write(DbgTextColor.Text, " ");
                if (location.ILOffsetMapping == DbgILOffsetMapping.Approximate)
                {
                    output.Write(DbgTextColor.Operator, "~");
                }
                WriteILOffset(output, location.Offset);
                break;

            case DbgILOffsetMapping.Prolog:
                WriteText(output, "prolog");
                break;

            case DbgILOffsetMapping.Epilog:
                WriteText(output, "epilog");
                break;

            case DbgILOffsetMapping.Unknown:
            case DbgILOffsetMapping.NoInfo:
            case DbgILOffsetMapping.UnmappedAddress:
                WriteText(output, "???");
                break;

            default:
                Debug.Fail($"Unknown IL offset mapping: {location.ILOffsetMapping}");
                goto case DbgILOffsetMapping.Unknown;
            }

            output.Write(DbgTextColor.Text, " ");
            output.Write(DbgTextColor.Punctuation, "(");
            output.Write(DbgTextColor.Number, GetHexPrefix() + location.NativeAddress.Address.ToString("X8"));
            output.Write(DbgTextColor.Operator, "+");
            output.Write(DbgTextColor.Number,
                         (options & DbgBreakpointLocationFormatterOptions.Decimal) != 0 ?
                         location.NativeAddress.Offset.ToString() :
                         GetHexPrefix() + location.NativeAddress.Offset.ToString("X"));
            output.Write(DbgTextColor.Punctuation, ")");
        }
Beispiel #2
0
        public override void WriteName(ITextColorWriter output, DbgBreakpointLocationFormatterOptions options)
        {
            bool printedToken = false;

            if ((options & DbgBreakpointLocationFormatterOptions.Tokens) != 0)
            {
                WriteToken(output, location.Token);
                output.WriteSpace();
                printedToken = true;
            }

            var method = owner.GetDefinition <MethodDef>(location.Module, location.Token);

            if (method == null)
            {
                if (printedToken)
                {
                    output.Write(BoxedTextColor.Error, "???");
                }
                else
                {
                    WriteToken(output, location.Token);
                }
            }
            else
            {
                owner.MethodDecompiler.Write(output, method, GetFormatterOptions(options));
            }

            switch (location.ILOffsetMapping)
            {
            case DbgILOffsetMapping.Exact:
            case DbgILOffsetMapping.Approximate:
                output.WriteSpace();
                output.Write(BoxedTextColor.Operator, "+");
                output.WriteSpace();
                if (location.ILOffsetMapping == DbgILOffsetMapping.Approximate)
                {
                    output.Write(BoxedTextColor.Operator, "~");
                }
                WriteILOffset(output, location.Offset);
                break;

            case DbgILOffsetMapping.Prolog:
                WriteText(output, "prolog");
                break;

            case DbgILOffsetMapping.Epilog:
                WriteText(output, "epilog");
                break;

            case DbgILOffsetMapping.Unknown:
            case DbgILOffsetMapping.NoInfo:
            case DbgILOffsetMapping.UnmappedAddress:
                WriteText(output, "???");
                break;

            default: throw new InvalidOperationException();
            }

            output.WriteSpace();
            output.Write(BoxedTextColor.Punctuation, "(");
            output.Write(BoxedTextColor.Number, GetHexPrefix() + location.NativeMethodAddress.ToString("X8"));
            output.Write(BoxedTextColor.Operator, "+");
            output.Write(BoxedTextColor.Number,
                         (options & DbgBreakpointLocationFormatterOptions.Decimal) != 0 ?
                         location.NativeMethodOffset.ToString() :
                         GetHexPrefix() + location.NativeMethodOffset.ToString("X"));
            output.Write(BoxedTextColor.Punctuation, ")");
        }