Esempio n. 1
0
        static void SetSourceCodeFrame()
        {
            var bt = DebuggingService.CurrentCallStack;

            if (bt != null)
            {
                for (int n = 0; n < bt.FrameCount; n++)
                {
                    var sf = bt.GetFrame(n);

                    if (!sf.IsExternalCode &&
                        sf.SourceLocation.Line != -1 &&
                        !string.IsNullOrEmpty(sf.SourceLocation.FileName) &&
                        //Uncomment condition below once logic for ProjectOnlyCode in runtime is fixed
                        (                    /*DebuggingService.CurrentSessionSupportsFeature (DebuggerFeatures.Disassembly) ||*/

                            sf.SourceLocation.SourceLink != null ||
                            File.Exists(sf.SourceLocation.FileName) ||
                            SourceCodeLookup.FindSourceFile(sf.SourceLocation.FileName, sf.SourceLocation.FileHash).IsNotNull))
                    {
                        if (n != DebuggingService.CurrentFrameIndex)
                        {
                            DebuggingService.CurrentFrameIndex = n;
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        void OnFrameChanged(object s, EventArgs a)
        {
            if (disassemblyDoc != null && DebuggingService.IsFeatureSupported(DebuggerFeatures.Disassembly))
            {
                disassemblyView.Update();
            }

            var frame = DebuggingService.CurrentFrame;

            if (frame == null)
            {
                return;
            }

            FilePath file = frame.SourceLocation.FileName;
            int      line = frame.SourceLocation.Line;

            if (line != -1)
            {
                if (!file.IsNullOrEmpty && System.IO.File.Exists(file))
                {
                    if (IdeApp.Workbench.OpenDocument(file, null, line, 1, OpenDocumentOptions.Debugger) != null)
                    {
                        return;
                    }
                }
                if (frame.SourceLocation.FileHash != null)
                {
                    var newFilePath = SourceCodeLookup.FindSourceFile(file, frame.SourceLocation.FileHash);
                    if (newFilePath != null)
                    {
                        frame.UpdateSourceFile(newFilePath);
                        if (IdeApp.Workbench.OpenDocument(newFilePath, null, line, 1, OpenDocumentOptions.Debugger) != null)
                        {
                            return;
                        }
                    }
                }
            }

            // If we don't have an address space, we can't disassemble
            if (string.IsNullOrEmpty(frame.AddressSpace))
            {
                return;
            }

            if (!DebuggingService.CurrentSessionSupportsFeature(DebuggerFeatures.Disassembly))
            {
                return;
            }

            if (disassemblyDoc == null)
            {
                OnShowDisassembly(null, null);
            }
            else
            {
                disassemblyDoc.Select();
            }
        }
Esempio n. 3
0
        public override bool Evaluate(NodeElement conditionNode)
        {
            var solution = IdeApp.ProjectOperations.CurrentSelectedSolution;

            if (solution == null)
            {
                return(false);
            }
            return(SourceCodeLookup.GetDebugSourceFolders(solution).Any());
        }
        public DebugSourceFilesOptionsPanelWidget(Solution solution)
        {
            this.solution = solution;

            label        = new Label(BrandingService.BrandApplicationName(GettextCatalog.GetString("Folders where MonoDevelop should look for debug source files:")));
            label.Xalign = 0;
            PackStart(label, false, false, 0);
            selector.Directories = new List <string> (SourceCodeLookup.GetDebugSourceFolders(solution));
            PackStart(selector, true, true, 0);
            ShowAll();
            SetupAccessibility();
        }
Esempio n. 5
0
        private async void OpenFindSourceFileDialog(object sender, EventArgs e)
        {
            var sf = DebuggingService.CurrentFrame;

            if (sf == null)
            {
                LoggingService.LogWarning($"CurrentFrame was null in {nameof (OpenFindSourceFileDialog)}");
                return;
            }
            var dlg = new Ide.Gui.Dialogs.OpenFileDialog(GettextCatalog.GetString("File to Open") + " " + sf.SourceLocation.FileName, FileChooserAction.Open)
            {
                TransientFor         = IdeApp.Workbench.RootWindow,
                ShowEncodingSelector = true,
                ShowViewerSelector   = true
            };

            dlg.DirectoryChangedHandler = (s, path) => {
                return(SourceCodeLookup.TryDebugSourceFolders(sf.SourceLocation.FileName, sf.SourceLocation.FileHash, new string [] { path }));
            };
            if (!dlg.Run())
            {
                return;
            }
            var newFilePath = dlg.SelectedFile;

            try {
                if (File.Exists(newFilePath))
                {
                    var ignoreButton = new AlertButton(GettextCatalog.GetString("Ignore"));
                    if (SourceCodeLookup.CheckFileHash(newFilePath, sf.SourceLocation.FileHash) ||
                        MessageService.AskQuestion(GettextCatalog.GetString("File checksum doesn't match."), 1, ignoreButton, new AlertButton(GettextCatalog.GetString("Cancel"))) == ignoreButton)
                    {
                        SourceCodeLookup.AddLoadedFile(newFilePath, sf.SourceLocation.FileName);
                        sf.UpdateSourceFile(newFilePath);

                        var doc = await IdeApp.Workbench.OpenDocument(newFilePath, null, sf.SourceLocation.Line, 1, OpenDocumentOptions.Debugger);

                        if (doc != null)
                        {
                            await Document.Close(false);
                        }
                    }
                }
                else
                {
                    MessageService.ShowWarning(GettextCatalog.GetString("File not found."));
                }
            } catch (Exception) {
                MessageService.ShowWarning(GettextCatalog.GetString("Error opening file."));
            }
        }
Esempio n. 6
0
        void ShowLoadSourceFile(StackFrame sf)
        {
            if (messageOverlayContent != null)
            {
                editor.RemoveOverlay(messageOverlayContent);
                messageOverlayContent = null;
            }
            messageOverlayContent = new HBox();

            var hbox = new HBox();

            hbox.Spacing = 8;
            var label = new Label(GettextCatalog.GetString("{0} not found. Find source file at alternative location.", Path.GetFileName(sf.SourceLocation.FileName)));

            hbox.TooltipText = sf.SourceLocation.FileName;

            var color = SyntaxHighlightingService.GetColor(editor.Options.GetEditorTheme(), EditorThemeColors.NotificationText);

            label.ModifyFg(StateType.Normal, color);

            int w, h;

            label.Layout.GetPixelSize(out w, out h);

            hbox.PackStart(label, true, true, 0);
            var openButton = new Button(Gtk.Stock.Open);

            openButton.WidthRequest = 60;
            hbox.PackEnd(openButton, false, false, 0);

            const int containerPadding = 8;

            messageOverlayContent.PackStart(hbox, true, true, containerPadding);
            editor.AddOverlay(messageOverlayContent, () => openButton.SizeRequest().Width + w + hbox.Spacing * 5 + containerPadding * 2);

            openButton.Clicked += delegate {
                var dlg = new OpenFileDialog(GettextCatalog.GetString("File to Open"), MonoDevelop.Components.FileChooserAction.Open)
                {
                    TransientFor         = IdeApp.Workbench.RootWindow,
                    ShowEncodingSelector = true,
                    ShowViewerSelector   = true
                };
                if (!dlg.Run())
                {
                    return;
                }
                var newFilePath = dlg.SelectedFile;
                try {
                    if (File.Exists(newFilePath))
                    {
                        if (SourceCodeLookup.CheckFileMd5(newFilePath, sf.SourceLocation.FileHash))
                        {
                            SourceCodeLookup.AddLoadedFile(newFilePath, sf.SourceLocation.FileName);
                            sf.UpdateSourceFile(newFilePath);
                            if (IdeApp.Workbench.OpenDocument(newFilePath, null, sf.SourceLocation.Line, 1, OpenDocumentOptions.Debugger) != null)
                            {
                                this.WorkbenchWindow.CloseWindow(false);
                            }
                        }
                        else
                        {
                            MessageService.ShowWarning(GettextCatalog.GetString("File checksum doesn't match."));
                        }
                    }
                    else
                    {
                        MessageService.ShowWarning(GettextCatalog.GetString("File not found."));
                    }
                } catch (Exception) {
                    MessageService.ShowWarning(GettextCatalog.GetString("Error opening file."));
                }
            };
        }
Esempio n. 7
0
        async void OnFrameChanged(object s, EventArgs a)
        {
            if (changingFrame)
            {
                return;
            }

            changingFrame = true;

            try {
                if (disassemblyDoc != null && DebuggingService.IsFeatureSupported(DebuggerFeatures.Disassembly))
                {
                    disassemblyView.Update();
                }

                var frame = DebuggingService.CurrentFrame;
                if (frame == null)
                {
                    return;
                }

                var      debuggerOptions = DebuggingService.GetUserOptions();
                FilePath file            = frame.SourceLocation.FileName;
                int      line            = frame.SourceLocation.Line;

                if (line != -1)
                {
                    if (!file.IsNullOrEmpty && File.Exists(file))
                    {
                        var doc = await IdeApp.Workbench.OpenDocument(file, null, line, 1, OpenDocumentOptions.Debugger);

                        if (doc != null)
                        {
                            return;
                        }
                    }

                    if (frame.SourceLocation.FileHash != null)
                    {
                        var newFilePath = SourceCodeLookup.FindSourceFile(file, frame.SourceLocation.FileHash);
                        if (newFilePath != null && File.Exists(newFilePath))
                        {
                            frame.UpdateSourceFile(newFilePath);
                            var doc = await IdeApp.Workbench.OpenDocument(newFilePath, null, line, 1, OpenDocumentOptions.Debugger);

                            if (doc != null)
                            {
                                return;
                            }
                        }
                    }

                    var automaticSourceDownload = debuggerOptions.AutomaticSourceLinkDownload;

                    var sourceLink = frame.SourceLocation.SourceLink;
                    if (sourceLink != null && automaticSourceDownload != AutomaticSourceDownload.Never)
                    {
                        var      downloadLocation = sourceLink.GetDownloadLocation(symbolCachePath);
                        Document doc = null;
                        // ~/Library/Caches/VisualStudio/8.0/Symbols/org/projectname/git-sha/path/to/file.cs
                        if (!File.Exists(downloadLocation))
                        {
                            if (automaticSourceDownload == AutomaticSourceDownload.Always)
                            {
                                doc = await NoSourceView.DownloadAndOpenAsync(frame);
                            }
                        }
                        else
                        {
                            // The file has previously been downloaded for a different solution.
                            // We need to map the cached location
                            frame.UpdateSourceFile(downloadLocation);
                            doc = await IdeApp.Workbench.OpenDocument(downloadLocation, null, line, 1, OpenDocumentOptions.Debugger);
                        }
                        if (doc != null)
                        {
                            return;
                        }
                    }
                }

                bool disassemblySupported = !string.IsNullOrEmpty(frame.AddressSpace) &&
                                            DebuggingService.CurrentSessionSupportsFeature(DebuggerFeatures.Disassembly);

                if (!disassemblySupported && disassemblyDoc != null)
                {
                    disassemblyDoc.Close().Ignore();
                    disassemblyDoc  = null;
                    disassemblyView = null;
                }

                // If disassembly is open don't show NoSourceView
                if (disassemblyDoc == null)
                {
                    if (noSourceDoc == null)
                    {
                        noSourceView = new NoSourceView();
                        noSourceView.Update(debuggerOptions, frame, disassemblySupported);
                        noSourceDoc = await IdeApp.Workbench.OpenDocument(noSourceView, true);

                        noSourceDoc.Closed += delegate {
                            noSourceDoc  = null;
                            noSourceView = null;
                        };
                    }
                    else
                    {
                        noSourceView.Update(debuggerOptions, frame, disassemblySupported);
                        noSourceDoc.Select();
                    }
                }
                else
                {
                    disassemblyDoc.Select();
                }
            } finally {
                changingFrame = false;
            }
        }
Esempio n. 8
0
        async void OnFrameChanged(object s, EventArgs a)
        {
            if (changingFrame)
            {
                return;
            }
            try {
                changingFrame = true;
                if (disassemblyDoc != null && DebuggingService.IsFeatureSupported(DebuggerFeatures.Disassembly))
                {
                    disassemblyView.Update();
                }

                var frame = DebuggingService.CurrentFrame;
                if (frame == null)
                {
                    return;
                }

                FilePath file = frame.SourceLocation.FileName;

                int line = frame.SourceLocation.Line;
                if (line != -1)
                {
                    if (!file.IsNullOrEmpty && File.Exists(file))
                    {
                        var doc = await IdeApp.Workbench.OpenDocument(file, null, line, 1, OpenDocumentOptions.Debugger);

                        if (doc != null)
                        {
                            return;
                        }
                    }
                    bool alternateLocationExists = false;
                    if (frame.SourceLocation.FileHash != null)
                    {
                        var newFilePath = SourceCodeLookup.FindSourceFile(file, frame.SourceLocation.FileHash);
                        if (newFilePath != null && File.Exists(newFilePath))
                        {
                            frame.UpdateSourceFile(newFilePath);
                            var doc = await IdeApp.Workbench.OpenDocument(newFilePath, null, line, 1, OpenDocumentOptions.Debugger);

                            if (doc != null)
                            {
                                return;
                            }
                        }
                    }
                    var debuggerOptions         = DebuggingService.GetUserOptions();
                    var automaticSourceDownload = debuggerOptions.AutomaticSourceLinkDownload;

                    var sourceLink = frame.SourceLocation.SourceLink;
                    if (sourceLink != null && automaticSourceDownload != AutomaticSourceDownload.Never)
                    {
                        var      downloadLocation = sourceLink.GetDownloadLocation(symbolCachePath);
                        Document doc = null;
                        // ~/Library/Caches/VisualStudio/8.0/Symbols/org/projectname/git-sha/path/to/file.cs
                        if (!File.Exists(downloadLocation))
                        {
                            if (automaticSourceDownload == AutomaticSourceDownload.Always)
                            {
                                doc = await DownloadAndOpenFileAsync(frame, line, sourceLink);
                            }
                            else
                            {
                                var hyperlink      = $"<a href='{ sourceLink.Uri }'>{  Path.GetFileName (sourceLink.RelativeFilePath) }</a>";
                                var stackframeText = $"<b>{frame.FullStackframeText}</b>";

                                var text = GettextCatalog.GetString
                                               ("{0} is a call to external source code. Would you like to get '{1}' and view it?", stackframeText, hyperlink);
                                var message = new Ide.GenericMessage {
                                    Text          = GettextCatalog.GetString("External source code available"),
                                    SecondaryText = text
                                };
                                message.AddOption(nameof(automaticSourceDownload), GettextCatalog.GetString("Always get source code automatically"), false);
                                message.Buttons.Add(AlertButton.Cancel);
                                message.Buttons.Add(new AlertButton(GettextCatalog.GetString("Get and Open")));
                                message.DefaultButton = 1;

                                var didNotCancel = MessageService.GenericAlert(message) != AlertButton.Cancel;
                                if (didNotCancel)
                                {
                                    if (message.GetOptionValue(nameof(automaticSourceDownload)))
                                    {
                                        debuggerOptions.AutomaticSourceLinkDownload = AutomaticSourceDownload.Always;
                                        DebuggingService.SetUserOptions(debuggerOptions);
                                    }
                                    doc = await DownloadAndOpenFileAsync(frame, line, sourceLink);
                                }
                            }
                        }
                        else
                        {
                            // The file has previously been downloaded for a different solution.
                            // We need to map the cached location
                            frame.UpdateSourceFile(downloadLocation);
                            doc = await IdeApp.Workbench.OpenDocument(downloadLocation, null, line, 1, OpenDocumentOptions.Debugger);
                        }
                        if (doc != null)
                        {
                            return;
                        }
                    }
                }

                bool disassemblyNotSupported = false;
                // If we don't have an address space, we can't disassemble
                if (string.IsNullOrEmpty(frame.AddressSpace))
                {
                    disassemblyNotSupported = true;
                }

                if (!DebuggingService.CurrentSessionSupportsFeature(DebuggerFeatures.Disassembly))
                {
                    disassemblyNotSupported = true;
                }

                if (disassemblyNotSupported && disassemblyDoc != null)
                {
                    disassemblyDoc.Close().Ignore();
                    disassemblyDoc  = null;
                    disassemblyView = null;
                }

                // If disassembly is open don't show NoSourceView
                if (disassemblyDoc == null)
                {
                    if (noSourceDoc == null)
                    {
                        noSourceView = new NoSourceView();
                        noSourceView.Update(disassemblyNotSupported);
                        noSourceDoc = await IdeApp.Workbench.OpenDocument(noSourceView, true);

                        noSourceDoc.Closed += delegate {
                            noSourceDoc  = null;
                            noSourceView = null;
                        };
                    }
                    else
                    {
                        noSourceView.Update(disassemblyNotSupported);
                        noSourceDoc.Select();
                    }
                }
                else
                {
                    disassemblyDoc.Select();
                }
            } finally {
                changingFrame = false;
            }
        }
Esempio n. 9
0
        async void OnFrameChanged(object s, EventArgs a)
        {
            if (disassemblyDoc != null && DebuggingService.IsFeatureSupported(DebuggerFeatures.Disassembly))
            {
                disassemblyView.Update();
            }

            var frame = DebuggingService.CurrentFrame;

            if (frame == null)
            {
                return;
            }

            FilePath file = frame.SourceLocation.FileName;
            int      line = frame.SourceLocation.Line;

            if (line != -1)
            {
                if (!file.IsNullOrEmpty && System.IO.File.Exists(file))
                {
                    var doc = await IdeApp.Workbench.OpenDocument(file, null, line, 1, OpenDocumentOptions.Debugger);

                    if (doc != null)
                    {
                        return;
                    }
                }
                if (frame.SourceLocation.FileHash != null)
                {
                    var newFilePath = SourceCodeLookup.FindSourceFile(file, frame.SourceLocation.FileHash);
                    if (newFilePath != null)
                    {
                        frame.UpdateSourceFile(newFilePath);
                        var doc = await IdeApp.Workbench.OpenDocument(newFilePath, null, line, 1, OpenDocumentOptions.Debugger);

                        if (doc != null)
                        {
                            return;
                        }
                    }
                }
            }

            bool disassemblyNotSupported = false;

            // If we don't have an address space, we can't disassemble
            if (string.IsNullOrEmpty(frame.AddressSpace))
            {
                disassemblyNotSupported = true;
            }

            if (!DebuggingService.CurrentSessionSupportsFeature(DebuggerFeatures.Disassembly))
            {
                disassemblyNotSupported = true;
            }

            if (disassemblyNotSupported && disassemblyDoc != null)
            {
                disassemblyDoc.Close().Ignore();
                disassemblyDoc  = null;
                disassemblyView = null;
            }

            // If disassembly is open don't show NoSourceView
            if (disassemblyDoc == null)
            {
                if (noSourceDoc == null)
                {
                    noSourceView = new NoSourceView();
                    noSourceView.Update(disassemblyNotSupported);
                    noSourceDoc = await IdeApp.Workbench.OpenDocument(noSourceView, true);

                    noSourceDoc.Closed += delegate {
                        noSourceDoc  = null;
                        noSourceView = null;
                    };
                }
                else
                {
                    noSourceView.Update(disassemblyNotSupported);
                    noSourceDoc.Select();
                }
            }
            else
            {
                disassemblyDoc.Select();
            }
        }
 public void Store()
 {
     SourceCodeLookup.SetDebugSourceFolders(solution, selector.Directories.ToArray());
 }