Exemple #1
0
        static public void RemoveAllBreakpoints()
        {
            var document = Npp.GetCurrentDocument();

            foreach (var key in breakpoints.Keys)
            {
                document.DeleteMarker(breakpoints[key]);
                if (IsRunning)
                {
                    DebuggerServer.RemoveBreakpoint(key);
                }
            }
            breakpoints.Clear();

            foreach (string file in Npp.Editor.GetOpenFilesSafe())
            {
                string dbgInfo = CSScriptHelper.GetDbgInfoFile(file, false);
                if (File.Exists(dbgInfo))
                {
                    File.Delete(dbgInfo);
                }
            }

            if (OnBreakpointChanged != null)
            {
                OnBreakpointChanged();
            }
        }
Exemple #2
0
 static new public void GoToThread(string threadId)
 {
     if (IsRunning && IsInBreak)
     {
         DebuggerServer.GoToThread(threadId);
     }
 }
Exemple #3
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 #4
0
 static new public void GoToFrame(string frameId)
 {
     if (IsRunning && IsInBreak)
     {
         DebuggerServer.GoToFrame(frameId);
     }
 }
Exemple #5
0
 static new public void StepOut()
 {
     if (IsRunning && IsInBreak)
     {
         ClearDebuggingMarkers();
         DebuggerServer.StepOut();
     }
 }
Exemple #6
0
 static public void RemoveWatch(string expression)
 {
     if (watchExtressions.Contains(expression))
     {
         watchExtressions.Remove(expression);
         if (IsRunning)
         {
             DebuggerServer.RemoveWatchExpression(expression);
         }
     }
 }
Exemple #7
0
 static public void Attach(int process, CpuType cpu)
 {
     if (!IsRunning)
     {
         Start(cpu);
         SendSettings(BreakOnException);
         watchExtressions.ForEach(x => DebuggerServer.AddWatchExpression(x));
         Attach(process);
         EntryBreakpointFile = null;
     }
 }
Exemple #8
0
 static public void AddWatch(string expression)
 {
     if (!watchExtressions.Contains(expression))
     {
         watchExtressions.Add(expression);
     }
     if (IsRunning)
     {
         DebuggerServer.AddWatchExpression(expression);
     }
 }
Exemple #9
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 #10
0
 static public void Start(string app, string args, CpuType cpu)
 {
     if (!IsRunning)
     {
         lastLocation = null;
         Start(cpu);
         SendSettings(BreakOnException);
         watchExtressions.ForEach(x => DebuggerServer.AddWatchExpression(x));
         Run(app, args ?? "");
         EntryBreakpointFile = null;
     }
 }
Exemple #11
0
        static public void SetInstructionPointer()
        {
            if (IsRunning && IsInBreak)
            {
                ClearDebuggingMarkers();

                int line = TranslateSourceLineLocation(Npp.GetCurrentFile(), Npp.GetCaretLineNumber());

                DebuggerServer.SetInstructionPointer(line + 1); //debugger is 1-based
                DebuggerServer.Break();                         //need to break to trigger reporting the current step
            }
        }
Exemple #12
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 #13
0
 static public void RemoveAllWatch()
 {
     watchExtressions.ForEach(x => DebuggerServer.RemoveWatchExpression(x));
     watchExtressions.Clear();
 }
Exemple #14
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);
                    }
                }
            });
        }
Exemple #15
0
 static new public void Go()
 {
     ClearDebuggingMarkers();
     DebuggerServer.Go();
 }