Example #1
0
            public static void Toggle(DecompilerTextView textView, int line, int column)
            {
                var bps   = SourceCodeMappingUtils.Find(textView, line, column);
                var ilbps = GetILCodeBreakpoints(textView, bps);

                if (ilbps.Count > 0)
                {
                    if (IsEnabled(ilbps))
                    {
                        foreach (var ilbp in ilbps)
                        {
                            BreakpointManager.Instance.Remove(ilbp);
                        }
                    }
                    else
                    {
                        foreach (var bpm in ilbps)
                        {
                            bpm.IsEnabled = true;
                        }
                    }
                }
                else if (bps.Count > 0)
                {
                    foreach (var bp in bps)
                    {
                        var md     = bp.MemberMapping.MethodDef;
                        var serMod = md.Module.ToSerializedDnSpyModule();
                        var key    = new SerializedDnSpyToken(serMod, md.MDToken);
                        BreakpointManager.Instance.Add(new ILCodeBreakpoint(key, bp.ILInstructionOffset.From));
                    }
                    textView.ScrollAndMoveCaretTo(bps[0].StartLocation.Line, bps[0].StartLocation.Column);
                }
            }
Example #2
0
        public static void Toggle(DecompilerTextView textView, int line, int column)
        {
            var bps  = SourceCodeMappingUtils.Find(textView, line, column);
            var bpms = GetBreakpointBookmarks(textView, bps);

            if (bpms.Count > 0)
            {
                if (bpms.IsEnabled())
                {
                    foreach (var bpm in bpms)
                    {
                        BookmarkManager.RemoveMark(bpm);
                    }
                }
                else
                {
                    foreach (var bpm in bpms)
                    {
                        bpm.IsEnabled = true;
                    }
                }
            }
            else if (bps.Count > 0)
            {
                foreach (var bp in bps)
                {
                    if (MethodKey.Create(bp.MemberMapping.MethodDefinition) == null)
                    {
                        continue;
                    }
                    BookmarkManager.AddMark(new BreakpointBookmark(bp.MemberMapping.MethodDefinition, bp.StartLocation, bp.EndLocation, bp.ILInstructionOffset));
                }
                textView.ScrollAndMoveCaretTo(bps[0].StartLocation.Line, bps[0].StartLocation.Column);
            }
        }
Example #3
0
        static IList <SourceCodeMapping> GetMappings(TextViewContext context)
        {
            if (context.TextView == null || context.Position == null)
            {
                return(null);
            }
            var list = SourceCodeMappingUtils.Find(context.TextView, context.Position.Value.Line, context.Position.Value.Column);

            return(list.Count == 0 ? null : list);
        }
Example #4
0
        bool CanToggleBP()
        {
            var textView = MainWindow.Instance.ActiveTextView;

            if (textView == null)
            {
                return(false);
            }
            var location = textView.TextEditor.TextArea.Caret.Location;

            return(SourceCodeMappingUtils.Find(textView, location.Line, location.Column).Count != 0);
        }
Example #5
0
        internal static IList <SourceCodeMapping> GetMappings(ContextMenuEntryContext context)
        {
            if (!(context.Element is DecompilerTextView) || context.Position == null)
            {
                return(null);
            }
            var list = SourceCodeMappingUtils.Find((DecompilerTextView)context.Element, context.Position.Value.Line, context.Position.Value.Column);

            if (list.Count == 0)
            {
                return(null);
            }
            if (!(list[0].StartLocation.Line <= context.Position.Value.Line && context.Position.Value.Line <= list[0].EndLocation.Line))
            {
                return(null);
            }
            return(list);
        }
Example #6
0
        static IList <SourceCodeMapping> GetMappings(TextViewContext context)
        {
            if (context.TextView == null || context.Position == null)
            {
                return(null);
            }
            var list = SourceCodeMappingUtils.Find(context.TextView, context.Position.Value.Line, context.Position.Value.Column);

            if (list.Count == 0)
            {
                return(null);
            }
            if (!(list[0].StartLocation.Line <= context.Position.Value.Line && context.Position.Value.Line <= list[0].EndLocation.Line))
            {
                return(null);
            }
            return(list);
        }
Example #7
0
            public static void Toggle(DecompilerTextView textView, int line, int column)
            {
                var bps   = SourceCodeMappingUtils.Find(textView, line, column);
                var ilbps = GetILCodeBreakpoints(textView, bps);

                if (ilbps.Count > 0)
                {
                    if (IsEnabled(ilbps))
                    {
                        foreach (var ilbp in ilbps)
                        {
                            BreakpointManager.Instance.Remove(ilbp);
                        }
                    }
                    else
                    {
                        foreach (var bpm in ilbps)
                        {
                            bpm.IsEnabled = true;
                        }
                    }
                }
                else if (bps.Count > 0)
                {
                    foreach (var bp in bps)
                    {
                        var md  = bp.MemberMapping.MethodDefinition;
                        var key = MethodKey.Create(md);
                        if (key == null)
                        {
                            continue;
                        }
                        var asm     = md.Module == null ? null : md.Module.Assembly;
                        var asmName = asm == null ? null : asm.ManifestModule.Location;
                        BreakpointManager.Instance.Add(new ILCodeBreakpoint(asmName, key.Value, bp.ILInstructionOffset.From));
                    }
                    textView.ScrollAndMoveCaretTo(bps[0].StartLocation.Line, bps[0].StartLocation.Column);
                }
            }
Example #8
0
 public static List <ILCodeBreakpoint> GetILCodeBreakpoints(DecompilerTextView textView, int line, int column)
 {
     return(GetILCodeBreakpoints(textView, SourceCodeMappingUtils.Find(textView, line, column)));
 }
Example #9
0
        public static bool DebugGetSourceCodeMappingForSetNextStatement(out string errMsg, out SourceCodeMapping mapping)
        {
            errMsg  = string.Empty;
            mapping = null;

            if (DebuggerService.CurrentDebugger == null)
            {
                errMsg = "No debugger exists";
                return(false);
            }
            if (!DebuggerService.CurrentDebugger.IsDebugging)
            {
                errMsg = "We're not debugging";
                return(false);
            }
            if (DebuggerService.CurrentDebugger.IsProcessRunning)
            {
                errMsg = "Can't set next statement when the process is running";
                return(false);
            }

            var textView = MainWindow.Instance.ActiveTextView;

            if (textView == null)
            {
                errMsg = "No tab is available. Decompile the current method!";
                return(false);
            }

            Tuple <MethodKey, int, IMemberRef> info;
            MethodKey currentKey;
            Dictionary <MethodKey, MemberMapping> cm;

            if (!DebugUtils.VerifyAndGetCurrentDebuggedMethod(textView, out info, out currentKey, out cm))
            {
                errMsg = "No debug information found. Make sure that only the debugged method is selected in the treeview (press 'Alt+Num *' to go to current statement)";
                return(false);
            }

            var location = textView.TextEditor.TextArea.Caret.Location;
            var bps      = SourceCodeMappingUtils.Find(cm, location.Line, location.Column);

            if (bps.Count == 0)
            {
                errMsg = "It's not possible to set the next statement here";
                return(false);
            }

            // The method def could be different now if the debugged assembly was reloaded from disk
            // so use SigComparer and not object references to compare the methods.
            var flags = SigComparerOptions.CompareDeclaringTypes |
                        SigComparerOptions.CompareAssemblyPublicKeyToken |
                        SigComparerOptions.CompareAssemblyVersion |
                        SigComparerOptions.CompareAssemblyLocale |
                        SigComparerOptions.PrivateScopeIsComparable;

            foreach (var bp in bps)
            {
                if (new SigComparer(flags).Equals(bp.MemberMapping.MethodDefinition, info.Item3))
                {
                    mapping = bp;
                    break;
                }
            }
            if (mapping == null)
            {
                errMsg = "The next statement cannot be set to another method";
                return(false);
            }

            return(true);
        }
Example #10
0
 public static List <BreakpointBookmark> GetBreakpointBookmarks(DecompilerTextView textView, int line, int column)
 {
     return(GetBreakpointBookmarks(textView, SourceCodeMappingUtils.Find(textView, line, column)));
 }