Ejemplo n.º 1
0
        static void MarkResult(List <ITextEditor> textAreas, SearchResultMatch result)
        {
            ITextEditor textArea = OpenTextArea(result.FileName);

            if (textArea != null)
            {
                if (!textAreas.Contains(textArea))
                {
                    textAreas.Add(textArea);
                }
                textArea.Caret.Offset = result.Offset;
                IDocumentLine segment = textArea.Document.GetLineForOffset(result.Offset);

                int lineNr = segment.LineNumber;

                foreach (var bookmark in BookmarkManager.GetBookmarks(result.FileName))
                {
                    if (bookmark.CanToggle && bookmark.LineNumber == lineNr)
                    {
                        // bookmark or breakpoint already exists at that line
                        return;
                    }
                }
                BookmarkManager.AddMark(new Bookmark(result.FileName, textArea.Document.OffsetToPosition(result.Offset)));
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        public static void SetPosition(FileName fileName, IDocument document, int makerStartLine, int makerStartColumn, int makerEndLine, int makerEndColumn)
        {
            Remove();

            startLine   = makerStartLine;
            startColumn = makerStartColumn;
            endLine     = makerEndLine;
            endColumn   = makerEndColumn;

            if (startLine < 1 || startLine > document.TotalNumberOfLines)
            {
                return;
            }
            if (endLine < 1 || endLine > document.TotalNumberOfLines)
            {
                endLine   = startLine;
                endColumn = int.MaxValue;
            }
            if (startColumn < 1)
            {
                startColumn = 1;
            }

            IDocumentLine line = document.GetLine(startLine);

            if (endColumn < 1 || endColumn > line.Length)
            {
                endColumn = line.Length;
            }
            instance = new CurrentLineBookmark(fileName, new Location(startColumn, startLine));
            BookmarkManager.AddMark(instance);
        }
Ejemplo n.º 4
0
        void IconBarMargin_MouseDown(AbstractMargin sender, Point mousepos, MouseButtons mouseButtons)
        {
            if (mouseButtons != MouseButtons.Left)
            {
                return;
            }

            IconBarMargin marginObj = (IconBarMargin)sender;

            Rectangle    viewRect = marginObj.TextArea.TextView.DrawingPosition;
            TextLocation logicPos = marginObj.TextArea.TextView.GetLogicalPosition(0, mousepos.Y - viewRect.Top);

            if (logicPos.Y >= 0 && logicPos.Y < marginObj.TextArea.Document.TotalNumberOfLines)
            {
                LineSegment l = marginObj.Document.GetLineSegment(logicPos.Y);

                string s = marginObj.Document.GetText(l);

                if (s.Trim().Length == 0)
                {
                    return;
                }

                int             lineNr = logicPos.Y + 1;
                BookmarkManager bm     = this.currentFile.Editor.Document.BookmarkManager;

                Bookmark mark = new BreakMark(marginObj.Document, logicPos);
                bm.AddMark(mark);
                Breakpoint bp = new Breakpoint(this.currentFile, lineNr, mark);
                this.debugEngine.SetBreakpoint(bp);
                this.currentFile.Breakpoints.Add(lineNr, bp);
                marginObj.TextArea.Refresh();
            }
        }
 void AddClassMemberBookmarks(BookmarkManager bm, IClass c)
 {
     if (c.IsSynthetic)
     {
         return;
     }
     if (!c.Region.IsEmpty)
     {
         bm.AddMark(new Bookmarks.ClassBookmark(textEditorControl.Document, c));
     }
     foreach (IClass innerClass in c.InnerClasses)
     {
         AddClassMemberBookmarks(bm, innerClass);
     }
     foreach (IMethod m in c.Methods)
     {
         if (m.Region.IsEmpty || m.IsSynthetic)
         {
             continue;
         }
         bm.AddMark(new Bookmarks.MethodBookmark(textEditorControl.Document, m));
     }
     foreach (IProperty m in c.Properties)
     {
         if (m.Region.IsEmpty || m.IsSynthetic)
         {
             continue;
         }
         bm.AddMark(new Bookmarks.PropertyBookmark(textEditorControl.Document, m));
     }
     foreach (IField f in c.Fields)
     {
         if (f.Region.IsEmpty || f.IsSynthetic)
         {
             continue;
         }
         bm.AddMark(new Bookmarks.FieldBookmark(textEditorControl.Document, f));
     }
     foreach (IEvent e in c.Events)
     {
         if (e.Region.IsEmpty || e.IsSynthetic)
         {
             continue;
         }
         bm.AddMark(new Bookmarks.EventBookmark(textEditorControl.Document, e));
     }
 }
Ejemplo n.º 6
0
        public static void SetPosition(IMemberRef memberReference, int makerStartLine, int makerStartColumn, int makerEndLine, int makerEndColumn, uint ilOffset)
        {
            Remove();

            startLine   = makerStartLine;
            startColumn = makerStartColumn;
            endLine     = makerEndLine;
            endColumn   = makerEndColumn;

            instance = new CurrentLineBookmark(memberReference, new TextLocation(startLine, startColumn), ilOffset);
            BookmarkManager.AddMark(instance);
        }
        void ToggleSelectedFrameBookmark(Location location)
        {
            // remove all
            BookmarkManager.RemoveAll(b => b is SelectedFrameBookmark);

            ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveContent as ITextEditorProvider;

            if (provider != null)
            {
                ITextEditor editor = provider.TextEditor;
                BookmarkManager.AddMark(new SelectedFrameBookmark(editor.FileName, location));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Should be called each time the IL offset has been updated
        /// </summary>
        static bool UpdateReturnStatementBookmarks(DecompilerTextView decompilerTextView, bool moveCaret = false)
        {
            Remove(decompilerTextView);
            bool movedCaret             = false;
            var  cm                     = decompilerTextView == null ? null : decompilerTextView.CodeMappings;
            bool updateReturnStatements =
                cm != null &&
                DebuggerService.CurrentDebugger != null &&
                DebuggerService.CurrentDebugger.IsDebugging &&
                !DebuggerService.CurrentDebugger.IsProcessRunning;

            if (updateReturnStatements)
            {
                int frameNo = -1;
                foreach (var frame in DebuggerService.CurrentDebugger.GetStackFrames(100))
                {
                    frameNo++;
                    StackFrameStatementType type;
                    if (frameNo == 0)
                    {
                        type = StackFrameStatementType.CurrentStatement;
                    }
                    else
                    {
                        type = selectedFrame == frameNo ? StackFrameStatementType.SelectedReturnStatement : StackFrameStatementType.ReturnStatement;
                    }
                    if (frame.ILOffset == null)
                    {
                        continue;
                    }
                    var       key    = frame.MethodKey;
                    int       offset = frame.ILOffset.Value;
                    MethodDef methodDef;
                    ICSharpCode.NRefactory.TextLocation location, endLocation;
                    if (cm != null && cm.ContainsKey(key) &&
                        cm[key].GetInstructionByTokenAndOffset((uint)offset, out methodDef, out location, out endLocation))
                    {
                        var rs = new StackFrameStatementBookmark(decompilerTextView, methodDef, location, endLocation, type, (uint)offset);
                        returnStatementBookmarks.Add(rs);
                        BookmarkManager.AddMark(rs);

                        if (moveCaret && frameNo == selectedFrame)
                        {
                            decompilerTextView.ScrollAndMoveCaretTo(location.Line, location.Column);
                            movedCaret = true;
                        }
                    }
                }
            }
            return(movedCaret);
        }
Ejemplo n.º 9
0
        void PinButton_Checked(object sender, RoutedEventArgs e)
        {
            ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;
            var editor = provider.TextEditor;

            if (editor == null)
            {
                return;
            }
            var node = (ITreeNode)(((ToggleButton)(e.OriginalSource)).DataContext);

            if (!string.IsNullOrEmpty(editor.FileName))
            {
                // verify if at the line of the root there's a pin bookmark
                var pin = BookmarkManager.Bookmarks.Find(
                    b => b is PinBookmark &&
                    b.LineNumber == logicalPosition.Line &&
                    b.FileName == editor.FileName) as PinBookmark;

                if (pin == null)
                {
                    pin = new PinBookmark(editor.FileName, logicalPosition);
                    // show pinned DebuggerPopup
                    if (pin.Popup == null)
                    {
                        pin.Popup      = new PinDebuggerControl();
                        pin.Popup.Mark = pin;
                        Rect rect  = new Rect(this.DesiredSize);
                        var  point = this.PointToScreen(rect.TopRight);
                        pin.Popup.Location = new Point {
                            X = 500, Y = point.Y - 150
                        };
                        pin.Nodes.Add(node);
                        pin.Popup.ItemsSource = pin.Nodes;
                    }

                    // do actions
                    pin.Popup.Open();
                    BookmarkManager.AddMark(pin);
                }
                else
                {
                    if (!pin.ContainsNode(node))
                    {
                        pin.Nodes.Add(node);
                        pin.Popup.ItemsSource = pin.Nodes;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void SyncBookmarks()
        {
            var storage = DebugInformation.CodeMappings;

            if (storage == null || storage.Count == 0)
            {
                return;
            }

            // TODO: handle other types of bookmarks
            // remove existing bookmarks and create new ones
            // update of existing bookmarks for new position does not update TextMarker
            // this is only done in TextMarkerService handlers for BookmarkManager.Added/Removed
            List <BreakpointBookmark> newBookmarks = new List <BreakpointBookmark>();

            for (int i = BookmarkManager.Bookmarks.Count - 1; i >= 0; --i)
            {
                var breakpoint = BookmarkManager.Bookmarks[i] as BreakpointBookmark;
                if (breakpoint == null)
                {
                    continue;
                }

                var key = breakpoint.FunctionToken;
                if (!storage.ContainsKey(key))
                {
                    continue;
                }

                bool isMatch;
                SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset(breakpoint.ILRange.From, out isMatch);

                if (map != null)
                {
                    BreakpointBookmark newBookmark = new BreakpointBookmark(breakpoint.MemberReference,
                                                                            new TextLocation(map.StartLocation.Line, 0),
                                                                            breakpoint.FunctionToken,
                                                                            map.ILInstructionOffset,
                                                                            BreakpointAction.Break);
                    newBookmark.IsEnabled = breakpoint.IsEnabled;

                    newBookmarks.Add(newBookmark);

                    BookmarkManager.RemoveMark(breakpoint);
                }
            }
            newBookmarks.ForEach(m => BookmarkManager.AddMark(m));
            SyncCurrentLineBookmark();
        }
        void PinCloseControl_PinningChanged(object sender, EventArgs e)
        {
            if (this.PinCloseControl.IsChecked)
            {
                BookmarkManager.RemoveMark(Mark);
            }
            else
            {
                if (BookmarkManager.Bookmarks.Contains(Mark))
                {
                    BookmarkManager.RemoveMark(Mark);
                }

                BookmarkManager.AddMark(Mark);
            }
        }
Ejemplo n.º 12
0
        public void SyncBookmarks()
        {
            var storage = DebugInformation.CodeMappings;

            if (storage == null || storage.Count == 0)
            {
                return;
            }

            //remove existing bookmarks and create new ones
            List <BreakpointBookmark> newBookmarks = new List <BreakpointBookmark>();

            for (int i = BookmarkManager.Bookmarks.Count - 1; i >= 0; --i)
            {
                var breakpoint = BookmarkManager.Bookmarks[i] as BreakpointBookmark;
                if (breakpoint == null)
                {
                    continue;
                }

                var key = breakpoint.MemberReference.MetadataToken.ToInt32();
                if (!storage.ContainsKey(key))
                {
                    continue;
                }

                var member = DebugInformation.DecompiledMemberReferences[key];

                bool isMatch;
                SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset(
                    member.MetadataToken.ToInt32(), breakpoint.ILRange.From, out isMatch);

                if (map != null)
                {
                    newBookmarks.Add(new BreakpointBookmark(
                                         member, new AstLocation(map.SourceCodeLine, 0),
                                         map.ILInstructionOffset, BreakpointAction.Break, DebugInformation.Language));

                    BookmarkManager.RemoveMark(breakpoint);
                }
            }

            newBookmarks.ForEach(m => BookmarkManager.AddMark(m));

            SyncCurrentLineBookmark();
        }
Ejemplo n.º 13
0
        static void MarkResult(SearchResultMatch result, bool switchToOpenedView = true)
        {
            ITextEditor textArea = OpenTextArea(result.FileName, switchToOpenedView);

            if (textArea != null)
            {
                if (switchToOpenedView)
                {
                    textArea.Caret.Position = result.StartLocation;
                }

                foreach (var bookmark in BookmarkManager.GetBookmarks(result.FileName))
                {
                    if (bookmark.CanToggle && bookmark.LineNumber == result.StartLocation.Line)
                    {
                        // bookmark or breakpoint already exists at that line
                        return;
                    }
                }
                BookmarkManager.AddMark(new Bookmark(result.FileName, result.StartLocation));
            }
        }
Ejemplo n.º 14
0
        public void LoadInternal()
        {
            ILSpySettings settings = ILSpySettings.Load();
            var           bpsx     = settings["Breakpoints"];

            BookmarkManager.RemoveMarks <BreakpointBookmark>();
            foreach (var bpx in bpsx.Elements("Breakpoint"))
            {
                int?   token            = (int?)bpx.Attribute("Token");
                string moduleFullPath   = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath"));
                string assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath"));
                uint?  from             = (uint?)bpx.Attribute("From");
                uint?  to                = (uint?)bpx.Attribute("To");
                bool?  isEnabled         = (bool?)bpx.Attribute("IsEnabled");
                int?   locationLine      = (int?)bpx.Attribute("LocationLine");
                int?   locationColumn    = (int?)bpx.Attribute("LocationColumn");
                int?   endLocationLine   = (int?)bpx.Attribute("EndLocationLine");
                int?   endLocationColumn = (int?)bpx.Attribute("EndLocationColumn");
                string methodFullName    = SessionSettings.Unescape((string)bpx.Attribute("MethodFullName"));

                if (token == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(moduleFullPath))
                {
                    continue;
                }
                if (assemblyFullPath == null)
                {
                    continue;
                }
                if (from == null || to == null || from.Value >= to.Value)
                {
                    continue;
                }
                if (isEnabled == null)
                {
                    continue;
                }
                if (locationLine == null || locationLine.Value < 1)
                {
                    continue;
                }
                if (locationColumn == null || locationColumn.Value < 1)
                {
                    continue;
                }
                if (endLocationLine == null || endLocationLine.Value < 1)
                {
                    continue;
                }
                if (endLocationColumn == null || endLocationColumn.Value < 1)
                {
                    continue;
                }
                var location    = new TextLocation(locationLine.Value, locationColumn.Value);
                var endLocation = new TextLocation(endLocationLine.Value, endLocationColumn.Value);
                if (location >= endLocation)
                {
                    continue;
                }

                ModuleDefMD loadedMod;
                try {
                    loadedMod = MainWindow.Instance.LoadAssembly(assemblyFullPath, moduleFullPath).ModuleDefinition as ModuleDefMD;
                }
                catch {
                    continue;
                }
                if (loadedMod == null)
                {
                    continue;
                }

                var method = loadedMod.ResolveToken(token.Value) as MethodDef;
                if (method == null)
                {
                    continue;
                }

                // Add an extra check to make sure that the file hasn't been re-created. This check
                // isn't perfect but should work most of the time unless the file was re-compiled
                // with the same tools and no methods were added or removed.
                if (method.FullName != methodFullName)
                {
                    continue;
                }

                if (MethodKey.Create(method) == null)
                {
                    continue;
                }
                var bpm = new BreakpointBookmark(method, location, endLocation, new ILRange(from.Value, to.Value), isEnabled.Value);
                BookmarkManager.AddMark(bpm);
            }
        }