Exemple #1
0
        private static void ToggleBreakpoint(string file, int line)
        {
            RefreshBreakPointsFromContent();

            string key = BuildBreakpointKey(file, line);

            if (breakpoints.ContainsKey(key))
            {
                Npp.DeleteMarker(breakpoints[key]);
                breakpoints.Remove(key);
                if (IsRunning)
                {
                    string actualKey = TranslateSourceBreakpoint(key);
                    DebuggerServer.RemoveBreakpoint(key);
                }
            }
            else
            {
                var handle = Npp.PlaceMarker(MARK_BREAKPOINT, line);
                breakpoints.Add(key, handle);
                if (IsRunning)
                {
                    string actualKey = TranslateSourceBreakpoint(key);
                    DebuggerServer.AddBreakpoint(actualKey);
                }
            }

            SaveBreakPointsFor(file);
        }
Exemple #2
0
        private static void ToggleBreakpoint(string file, int line)
        {
            RefreshBreakPointsFromContent();

            var document = Npp.GetCurrentDocument();

            string key = BuildBreakpointKey(file, line);

            if (breakpoints.ContainsKey(key))
            {
                document.DeleteMarker(breakpoints[key]);
                breakpoints.Remove(key);
                if (IsRunning)
                {
                    string actualKey = TranslateSourceBreakpoint(key);
                    DebuggerServer.RemoveBreakpoint(key);
                }
            }
            else
            {
                var validLine = document.ClosestNonEmptyLineTo(line);

                if (validLine != -1 && validLine != line)
                {
                    key  = BuildBreakpointKey(file, validLine);
                    line = validLine;
                }

                // after valid line was fount it is possible that it aleady has a brealpoint
                if (breakpoints.ContainsKey(key))
                {
                    document.DeleteMarker(breakpoints[key]);
                    breakpoints.Remove(key);
                    if (IsRunning)
                    {
                        string actualKey = TranslateSourceBreakpoint(key);
                        DebuggerServer.RemoveBreakpoint(key);
                    }
                }
                else
                {
                    var handle = document.PlaceMarker(MARK_BREAKPOINT, validLine);
                    breakpoints.Add(key, handle);
                    if (IsRunning)
                    {
                        string actualKey = TranslateSourceBreakpoint(key);
                        DebuggerServer.AddBreakpoint(actualKey);
                    }
                }
            }

            SaveBreakPointsFor(file);
        }
Exemple #3
0
 static public void RunToCursor()
 {
     if (IsRunning && IsInBreak)
     {
         string file             = Npp.GetCurrentFile();
         int    line             = Npp.GetCaretLineNumber();
         string key              = BuildBreakpointKey(file, line);
         string actualBreakpoint = TranslateSourceBreakpoint(key);
         DebuggerServer.AddBreakpoint(actualBreakpoint);
         DebuggerServer.Go();
         DebuggerServer.OnBreak = () =>
         {
             DebuggerServer.RemoveBreakpoint(actualBreakpoint);
         };
     }
 }
Exemple #4
0
        private static void HandleNotification(string notification)
        {
            //process=>7924:STARTED
            //source=>c:\Users\osh\Documents\Visual Studio 2012\Projects\ConsoleApplication12\ConsoleApplication12\Program.cs|12:9|12:10

            string message = notification;

            Debug.WriteLine("Received: " + message);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    if (OnNotification != null)
                    {
                        OnNotification(message);
                    }
                }
                catch { }
            });

            HandleErrors(() =>
            {
                if (message.StartsWith(NppCategory.Process))
                {
                    ClearDebuggingMarkers();

                    if (message.EndsWith(":STARTED"))
                    {
                        stepsCount     = 0;
                        DecorationInfo = CSScriptHelper.GetDecorationInfo(Debugger.ScriptFile);

                        foreach (string info in breakpoints.Keys)
                        {
                            DebuggerServer.AddBreakpoint(TranslateSourceBreakpoint(info));
                        }

                        if (Debugger.EntryBreakpointFile != null)
                        {
                            //line num is 0; debugger is smart enough to move the breakpoint to the very next appropriate line
                            string key = BuildBreakpointKey(Debugger.EntryBreakpointFile, 0);

                            if (DecorationInfo != null && DecorationInfo.AutoGenFile == Debugger.EntryBreakpointFile)
                            {
                                key = BuildBreakpointKey(DecorationInfo.AutoGenFile, DecorationInfo.InjectedLineNumber + 1);
                            }

                            DebuggerServer.AddBreakpoint(key);
                        }

                        //By default Mdbg always enters break mode at start/attach completed
                        //however we should only resume after mdbg finished the initialization (first break is reported).
                        resumeOnNextBreakPoint = true;
                    }
                    else if (message.EndsWith(":ENDED"))
                    {
                        NotifyOnDebugStepChanges();
                    }
                }
                else if (message.StartsWith(NppCategory.BreakEntered))
                {
                    if (resumeOnNextBreakPoint)
                    {
                        resumeOnNextBreakPoint = false;
                        Go();
                    }
                }
                else if (message.StartsWith(NppCategory.Exception))
                {
                    OnException(message.Substring(NppCategory.Exception.Length));
                }
                else if (message.StartsWith(NppCategory.DbgCommandError))
                {
                    OnDebuggerFailure(message.Substring(NppCategory.DbgCommandError.Length));
                }
                else if (message.StartsWith(NppCategory.Invoke))
                {
                    OnInvokeComplete(message.Substring(NppCategory.Invoke.Length));
                }
                else if (message.StartsWith(NppCategory.Watch))
                {
                    OnWatchData(message.Substring(NppCategory.Watch.Length));
                }
                else if (message.StartsWith(NppCategory.Trace))
                {
                    Plugin.OutputPanel.DebugOutput.Write(message.Substring(NppCategory.Trace.Length));
                }
                else if (message.StartsWith(NppCategory.State))
                {
                    if (message.Substring(NppCategory.State.Length) == "NOSOURCEBREAK")
                    {
                        Task.Factory.StartNew(() =>
                        {
                            //The break can be caused by 'Debugger.Break();'
                            //Trigger user break to force source code entry if available as a small usability improvement.
                            if ((Environment.TickCount - lastNOSOURCEBREAK) > 1500) //Just in case, prevent infinite loop.
                            {
                                lastNOSOURCEBREAK = Environment.TickCount;
                                Thread.Sleep(200); //even 80 is enough
                                Debugger.Break();
                            }
                        });
                    }
                }
                else if (message.StartsWith(NppCategory.CallStack))
                {
                    Plugin.GetDebugPanel().UpdateCallstack(message.Substring(NppCategory.CallStack.Length));
                }
                else if (message.StartsWith(NppCategory.Threads))
                {
                    Plugin.GetDebugPanel().UpdateThreads(message.Substring(NppCategory.Threads.Length));
                }
                else if (message.StartsWith(NppCategory.Modules))
                {
                    Plugin.GetDebugPanel().UpdateModules(message.Substring(NppCategory.Modules.Length));
                }
                else if (message.StartsWith(NppCategory.Locals))
                {
                    Plugin.GetDebugPanel().UpdateLocals(message.Substring(NppCategory.Locals.Length));
                    NotifyOnDebugStepChanges(); // !!! remove
                }
                else if (message.StartsWith(NppCategory.SourceCode))
                {
                    stepsCount++;

                    var sourceLocation = message.Substring(NppCategory.SourceCode.Length);

                    if (stepsCount == 1 && sourceLocation.Contains("css_dbg.cs|"))
                    {
                        //ignore the first source code break as it is inside of the CSScript.Npp debug launcher
                    }
                    else
                    {
                        NavigateToFileLocation(sourceLocation);
                    }
                }
            });
        }