public static void InitDebugger()
            {
                #region Attach event handlers
                Engine.Output += delegate(OutputFlags type, string msg)
                {
                    if (!GlobalProperties.Instance.VerboseDebugOutput && (type == OutputFlags.Verbose || type == OutputFlags.Normal)) return;

                    var ErrType=ErrorType.Message;
                    if (type == OutputFlags.Warning)
                        return;
                    if (type == OutputFlags.Error)
                        ErrType = ErrorType.Error;
                    Log(msg.Replace("\n",string.Empty),ErrType);
                };

                Engine.OnLoadModule += delegate(ulong BaseOffset, uint ModuleSize, string ModuleName, uint Checksum, uint Timestamp)
                {
                    if (EngineStarting)
                        return DebugStatus.Break;
                    return DebugStatus.NoChange;
                };

                /*dbg.OnUnloadModule += delegate(ulong BaseOffset, string ModuleName)
                {
                    LoadedModules.Remove(ModuleName);
                    return DebugStatus.NoChange;
                };*/

                Engine.OnBreakPoint += delegate(uint Id, string cmd, ulong off, string exp)
                {
                    StopWaitingForEvents = true;
                    var bp = Engine.GetBreakPointById(Id);
                    Log("Breakpoint #" + Id.ToString() + " at " + off.ToString() + ": " + exp,ErrorType.Information);
                    string fn;
                    uint ln;

                    if (!Engine.Symbols.GetLineByOffset(off, out fn, out ln))
                    {
                        Log("No source associated with " + off.ToString(),ErrorType.Warning);
                        return DebugStatus.Break;
                    }

                    if(GlobalProperties.Instance.VerboseDebugOutput)
                        Log(fn + ":" + ln.ToString(),ErrorType.Information);

                    var ed = IDEManager.Instance.OpenFile(fn) as EditorDocument;
                    if (ed == null)
                    {
                        Log("Unable to move to "+fn+":"+ln,ErrorType.Warning);
                        return DebugStatus.Break;
                    }

                    var text_off=ed.Editor.Document.GetOffset((int)ln-1,0);
                    ed.Editor.TextArea.Selection.StartSelectionOrSetEndpoint(text_off, text_off);

                    UpdateDebuggingPanels();

                    return DebugStatus.Break;
                };

                Engine.OnException += delegate(CodeException ex)
                {
                    StopWaitingForEvents = true;

                    string extype = "";
                    try
                    {
                        extype = ((ExceptionType)ex.Type).ToString();
                    }
                    catch
                    {
                        extype = "Unknown type (" + ex.Type.ToString() + ")";
                    }

                    string msg = "";
                    if ((ExceptionType)ex.Type == ExceptionType.DException)
                    {
                        msg = ex.Message;
                        if (ex.TypeInfo != null)
                            msg = ex.TypeInfo + ": " + msg;

                        Log(msg,ErrorType.Error);

                    }
                    else
                    {
                        Log(msg=extype + "-Exception",ErrorType.Error);
                    }

                    var ed = IDEManager.Instance.OpenFile(ex.SourceFile) as EditorDocument;
                    if (ed != null)
                    {
                        var m = new DebugErrorMarker(ed.MarkerStrategy, ex);
                        m.Redraw();

                        var off = ed.Editor.Document.GetOffset((int)ex.SourceLine - 1, 0);
                        ed.Editor.TextArea.Selection.StartSelectionOrSetEndpoint(off,off);
                    }

                    UpdateDebuggingPanels();

                    return DebugStatus.Break;
                };

                Engine.OnExitProcess += delegate(uint code)
                {
                    Log("Debugger Process exited with code " + code.ToString(),
                        code<1?ErrorType.Information:ErrorType.Error);
                    StopExecution();
                    return DebugStatus.NoChange;
                };

                /*Engine.OnSessionStatusChanged += delegate(SessionStatus ss)
                {
                    Log("Session status changed to " + ss.ToString());
                    //if (ss == SessionStatus.Active)	return DebugStatus.Break;
                    return DebugStatus.NoChange;
                };*/
                #endregion

                Engine.Execute("n 10"); // Set decimal numbers
                Engine.Execute(".lines -e"); // Enable source code locating

                dbgEngineInited = true;
            }
示例#2
0
            public static void InitDebugger()
            {
                #region Attach event handlers
                Engine.Output += delegate(OutputFlags type, string msg)
                {
                    if (!GlobalProperties.Instance.VerboseDebugOutput && (type == OutputFlags.Verbose || type == OutputFlags.Normal))
                    {
                        return;
                    }

                    var ErrType = ErrorType.Message;
                    if (type == OutputFlags.Warning)
                    {
                        return;
                    }
                    if (type == OutputFlags.Error)
                    {
                        ErrType = ErrorType.Error;
                    }
                    Log(msg.Replace("\n", string.Empty), ErrType);
                };

                Engine.OnLoadModule += delegate(ulong BaseOffset, uint ModuleSize, string ModuleName, uint Checksum, uint Timestamp)
                {
                    if (EngineStarting)
                    {
                        return(DebugStatus.Break);
                    }
                    return(DebugStatus.NoChange);
                };

                /*dbg.OnUnloadModule += delegate(ulong BaseOffset, string ModuleName)
                 * {
                 *      LoadedModules.Remove(ModuleName);
                 *      return DebugStatus.NoChange;
                 * };*/

                Engine.OnBreakPoint += delegate(uint Id, string cmd, ulong off, string exp)
                {
                    StopWaitingForEvents = true;
                    var bp = Engine.GetBreakPointById(Id);
                    Log("Breakpoint #" + Id.ToString() + " at " + off.ToString() + ": " + exp, ErrorType.Information);
                    string fn;
                    uint   ln;

                    if (!Engine.Symbols.GetLineByOffset(off, out fn, out ln))
                    {
                        Log("No source associated with " + off.ToString(), ErrorType.Warning);
                        return(DebugStatus.Break);
                    }

                    if (GlobalProperties.Instance.VerboseDebugOutput)
                    {
                        Log(fn + ":" + ln.ToString(), ErrorType.Information);
                    }

                    var ed = IDEManager.Instance.OpenFile(fn) as EditorDocument;
                    if (ed == null)
                    {
                        Log("Unable to move to " + fn + ":" + ln, ErrorType.Warning);
                        return(DebugStatus.Break);
                    }

                    var text_off = ed.Editor.Document.GetOffset((int)ln - 1, 0);
                    ed.Editor.TextArea.Selection.StartSelectionOrSetEndpoint(text_off, text_off);

                    UpdateDebuggingPanels();

                    return(DebugStatus.Break);
                };

                Engine.OnException += delegate(CodeException ex)
                {
                    StopWaitingForEvents = true;

                    string extype = "";
                    try
                    {
                        extype = ((ExceptionType)ex.Type).ToString();
                    }
                    catch
                    {
                        extype = "Unknown type (" + ex.Type.ToString() + ")";
                    }

                    string msg = "";
                    if ((ExceptionType)ex.Type == ExceptionType.DException)
                    {
                        msg = ex.Message;
                        if (ex.TypeInfo != null)
                        {
                            msg = ex.TypeInfo + ": " + msg;
                        }

                        Log(msg, ErrorType.Error);
                    }
                    else
                    {
                        Log(msg = extype + "-Exception", ErrorType.Error);
                    }

                    var ed = IDEManager.Instance.OpenFile(ex.SourceFile) as EditorDocument;
                    if (ed != null)
                    {
                        var m = new DebugErrorMarker(ed.MarkerStrategy, ex);
                        m.Redraw();

                        var off = ed.Editor.Document.GetOffset((int)ex.SourceLine - 1, 0);
                        ed.Editor.TextArea.Selection.StartSelectionOrSetEndpoint(off, off);
                    }

                    UpdateDebuggingPanels();

                    return(DebugStatus.Break);
                };

                Engine.OnExitProcess += delegate(uint code)
                {
                    Log("Debugger Process exited with code " + code.ToString(),
                        code < 1?ErrorType.Information:ErrorType.Error);
                    StopExecution();
                    return(DebugStatus.NoChange);
                };

                /*Engine.OnSessionStatusChanged += delegate(SessionStatus ss)
                 * {
                 *      Log("Session status changed to " + ss.ToString());
                 *      //if (ss == SessionStatus.Active)	return DebugStatus.Break;
                 *      return DebugStatus.NoChange;
                 * };*/
                #endregion

                Engine.Execute("n 10");                 // Set decimal numbers
                Engine.Execute(".lines -e");            // Enable source code locating

                dbgEngineInited = true;
            }